test: fix existing integration tests and add a new test that validates regions inclusion and validity
This commit is contained in:
committed by
Adrien de Peretti
parent
d4e565b0b9
commit
f22e063ed8
@@ -408,6 +408,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -471,6 +472,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -538,6 +540,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -576,6 +579,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
)
|
)
|
||||||
@@ -630,6 +634,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -654,6 +659,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -690,6 +696,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -729,6 +736,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -755,6 +763,7 @@ describe("/admin/discounts", () => {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: {
|
headers: {
|
||||||
@@ -779,6 +788,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -822,6 +832,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -844,6 +855,7 @@ describe("/admin/discounts", () => {
|
|||||||
id: response.data.discount.rule.id,
|
id: response.data.discount.rule.id,
|
||||||
type: "free_shipping",
|
type: "free_shipping",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
)
|
)
|
||||||
@@ -869,6 +881,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -913,6 +926,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -958,6 +972,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -1033,6 +1048,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -1103,6 +1119,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
starts_at: new Date("09/15/2021 11:50"),
|
starts_at: new Date("09/15/2021 11:50"),
|
||||||
ends_at: new Date("09/15/2021 17:50"),
|
ends_at: new Date("09/15/2021 17:50"),
|
||||||
@@ -1172,6 +1189,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
starts_at: new Date("09/15/2021 11:50"),
|
starts_at: new Date("09/15/2021 11:50"),
|
||||||
ends_at: new Date("09/15/2021 17:50"),
|
ends_at: new Date("09/15/2021 17:50"),
|
||||||
@@ -1229,6 +1247,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
starts_at: new Date("09/15/2021 11:50"),
|
starts_at: new Date("09/15/2021 11:50"),
|
||||||
ends_at: new Date("09/14/2021 17:50"),
|
ends_at: new Date("09/14/2021 17:50"),
|
||||||
@@ -1244,6 +1263,55 @@ describe("/admin/discounts", () => {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("fails to create a discount if regions array contains an invalid regionID ", async () => {
|
||||||
|
expect.assertions(2)
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
"/admin/discounts",
|
||||||
|
{
|
||||||
|
code: "HELLOWORLD",
|
||||||
|
rule: {
|
||||||
|
description: "test",
|
||||||
|
type: "percentage",
|
||||||
|
value: 10,
|
||||||
|
allocation: "total",
|
||||||
|
},
|
||||||
|
regions: ["test-region", "not-a-valid-region"],
|
||||||
|
},
|
||||||
|
adminReqConfig
|
||||||
|
).catch((err) => {
|
||||||
|
expect(err.response.status).toEqual(404)
|
||||||
|
expect(err.response.data.message).toEqual(
|
||||||
|
`Region with not-a-valid-region was not found`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("fails to create a discount if regions array is not present ", async () => {
|
||||||
|
expect.assertions(2)
|
||||||
|
const api = useApi()
|
||||||
|
|
||||||
|
const response = await api.post(
|
||||||
|
"/admin/discounts",
|
||||||
|
{
|
||||||
|
code: "HELLOWORLD",
|
||||||
|
rule: {
|
||||||
|
description: "test",
|
||||||
|
type: "percentage",
|
||||||
|
value: 10,
|
||||||
|
allocation: "total",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
adminReqConfig
|
||||||
|
).catch((err) => {
|
||||||
|
expect(err.response.status).toEqual(400)
|
||||||
|
expect(err.response.data.message).toEqual(
|
||||||
|
`each value in regions must be a string, regions must be an array`
|
||||||
|
)
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("POST /admin/discounts/:id", () => {
|
describe("POST /admin/discounts/:id", () => {
|
||||||
@@ -1306,7 +1374,10 @@ describe("/admin/discounts", () => {
|
|||||||
let manager
|
let manager
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
manager = dbConnection.manager
|
manager = dbConnection.manager
|
||||||
|
|
||||||
await adminSeeder(dbConnection)
|
await adminSeeder(dbConnection)
|
||||||
|
await discountSeeder(dbConnection)
|
||||||
|
|
||||||
await manager.insert(DiscountRule, {
|
await manager.insert(DiscountRule, {
|
||||||
id: "test-discount-rule",
|
id: "test-discount-rule",
|
||||||
description: "Test discount rule",
|
description: "Test discount rule",
|
||||||
@@ -1345,6 +1416,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -1374,6 +1446,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
@@ -2033,7 +2106,9 @@ describe("/admin/discounts", () => {
|
|||||||
describe("GET /admin/discounts/code/:code", () => {
|
describe("GET /admin/discounts/code/:code", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const manager = dbConnection.manager
|
const manager = dbConnection.manager
|
||||||
|
|
||||||
await adminSeeder(dbConnection)
|
await adminSeeder(dbConnection)
|
||||||
|
await discountSeeder(dbConnection)
|
||||||
|
|
||||||
await manager.insert(DiscountRule, {
|
await manager.insert(DiscountRule, {
|
||||||
id: "test-discount-rule-fixed",
|
id: "test-discount-rule-fixed",
|
||||||
@@ -2139,6 +2214,7 @@ describe("/admin/discounts", () => {
|
|||||||
value: 10,
|
value: 10,
|
||||||
allocation: "total",
|
allocation: "total",
|
||||||
},
|
},
|
||||||
|
regions: ["test-region"],
|
||||||
usage_limit: 10,
|
usage_limit: 10,
|
||||||
},
|
},
|
||||||
adminReqConfig
|
adminReqConfig
|
||||||
|
|||||||
Reference in New Issue
Block a user