Feat:discount expiration date (#403)
* discount expiration validation and testing * integration testing * double quotes * add iso8601 package * api testing * add joi validation of start and end dates as well as valid_duration * valid_duration column * service testing * discount validation in services * integration test with invalid date interval * include valid_duration when fetching a discount * rename variable for clarity * add test for dynamic discount with expiration date * remove debug code * adjust tests to reflect valid_duration being included in default fields * additional discount update validation * fixed failing test * set ends_at on dynamic discount creation * discount integration tests * removed unused console.log * removed validation of dynamic discounts by duration and added ends_at to dynamic discount creation * integration tests for dynamic discount with and without duration * optional valid duration for dynamic discounts * allow nullable dynamic discount durations * expect assertions * fix unit test after change to dynamic discounts without duration * change to date instead of string * add assertions * error handling * addressed feedback
This commit is contained in:
1 parent
ae0ab03fac
commit
9b64828ec3
22 files changed
+1009
-21
No files matched your search
@@ -55,6 +55,74 @@ describe("DiscountService", () => {
|
||||
|
||||
expect(discountRepository.save).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it("successfully creates discount with start and end dates", async () => {
|
||||
await discountService.create({
|
||||
code: "test",
|
||||
rule: {
|
||||
type: "percentage",
|
||||
allocation: "total",
|
||||
value: 20,
|
||||
},
|
||||
starts_at: new Date("03/14/2021"),
|
||||
ends_at: new Date("03/15/2021"),
|
||||
regions: [IdMap.getId("france")],
|
||||
})
|
||||
|
||||
expect(discountRuleRepository.create).toHaveBeenCalledTimes(1)
|
||||
expect(discountRuleRepository.create).toHaveBeenCalledWith({
|
||||
type: "percentage",
|
||||
allocation: "total",
|
||||
value: 20,
|
||||
})
|
||||
|
||||
expect(discountRuleRepository.save).toHaveBeenCalledTimes(1)
|
||||
|
||||
expect(discountRepository.create).toHaveBeenCalledTimes(1)
|
||||
expect(discountRepository.create).toHaveBeenCalledWith({
|
||||
code: "TEST",
|
||||
rule: expect.anything(),
|
||||
regions: [{ id: IdMap.getId("france") }],
|
||||
starts_at: new Date("03/14/2021"),
|
||||
ends_at: new Date("03/15/2021"),
|
||||
})
|
||||
|
||||
expect(discountRepository.save).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
|
||||
it("successfully creates discount with start date and a valid duration", async () => {
|
||||
await discountService.create({
|
||||
code: "test",
|
||||
rule: {
|
||||
type: "percentage",
|
||||
allocation: "total",
|
||||
value: 20,
|
||||
},
|
||||
starts_at: new Date("03/14/2021"),
|
||||
valid_duration: "P0Y0M1D",
|
||||
regions: [IdMap.getId("france")],
|
||||
})
|
||||
|
||||
expect(discountRuleRepository.create).toHaveBeenCalledTimes(1)
|
||||
expect(discountRuleRepository.create).toHaveBeenCalledWith({
|
||||
type: "percentage",
|
||||
allocation: "total",
|
||||
value: 20,
|
||||
})
|
||||
|
||||
expect(discountRuleRepository.save).toHaveBeenCalledTimes(1)
|
||||
|
||||
expect(discountRepository.create).toHaveBeenCalledTimes(1)
|
||||
expect(discountRepository.create).toHaveBeenCalledWith({
|
||||
code: "TEST",
|
||||
rule: expect.anything(),
|
||||
regions: [{ id: IdMap.getId("france") }],
|
||||
starts_at: new Date("03/14/2021"),
|
||||
valid_duration: "P0Y0M1D",
|
||||
})
|
||||
|
||||
expect(discountRepository.save).toHaveBeenCalledTimes(1)
|
||||
})
|
||||
})
|
||||
|
||||
describe("retrieve", () => {
|
||||
@@ -376,6 +444,7 @@ describe("DiscountService", () => {
|
||||
id: "parent",
|
||||
is_dynamic: true,
|
||||
rule_id: "parent_rule",
|
||||
valid_duration: "P1Y",
|
||||
}),
|
||||
})
|
||||
|
||||
@@ -412,6 +481,8 @@ describe("DiscountService", () => {
|
||||
rule_id: "parent_rule",
|
||||
parent_discount_id: "parent",
|
||||
code: "HI",
|
||||
usage_limit: undefined,
|
||||
ends_at: expect.any(Date),
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user