release: next (#315)
Co-authored-by: Sebastian Mateos Nicolajsen <sebastian.m.nicolajsen@gmail.com> Co-authored-by: Abraham Ugbeshe <abrahamugbeshe@gmail.com> Co-authored-by: olivermrbl <oliver@mrbltech.com>
This commit is contained in:
co-authored by
Sebastian Mateos Nicolajsen
Abraham Ugbeshe
olivermrbl
parent
44d31b4d83
commit
2585e958de
@@ -104,6 +104,82 @@ describe("/admin/discounts", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("testing for soft-deletion + uniqueness on discount codes", () => {
|
||||
const manager = dbConnection.manager;
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
await manager.insert(DiscountRule, {
|
||||
id: "test-discount-rule",
|
||||
description: "Test discount rule",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
});
|
||||
await manager.insert(Discount, {
|
||||
id: "test-discount",
|
||||
code: "TESTING",
|
||||
rule_id: "test-discount-rule",
|
||||
});
|
||||
} catch (err) {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "discount_rule"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("successfully creates discount with soft-deleted discount code", async () => {
|
||||
const api = useApi();
|
||||
|
||||
// First we soft-delete the discount
|
||||
await api
|
||||
.delete("/admin/discounts/test-discount", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
// Lets try to create a discount with same code as deleted one
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/discounts",
|
||||
{
|
||||
code: "TESTING",
|
||||
rule: {
|
||||
description: "test",
|
||||
type: "percentage",
|
||||
value: 10,
|
||||
allocation: "total",
|
||||
},
|
||||
usage_limit: 10,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.discount).toEqual(
|
||||
expect.objectContaining({
|
||||
code: "HELLOWORLD",
|
||||
usage_limit: 10,
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("POST /admin/discounts/:discount_id/dynamic-codes", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
|
||||
Reference in New Issue
Block a user