add integration tests
This commit is contained in:
1 parent
d9cd52a177
commit
38521169c0
3 files changed
+88
-7
No files matched your search
@@ -26,6 +26,84 @@ describe("/admin/discounts", () => {
|
|||||||
medusaProcess.kill();
|
medusaProcess.kill();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("POST /admin/discounts", () => {
|
||||||
|
beforeEach(async () => {
|
||||||
|
const manager = dbConnection.manager;
|
||||||
|
try {
|
||||||
|
await adminSeeder(dbConnection);
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
throw err;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
const manager = dbConnection.manager;
|
||||||
|
await manager.query(`DELETE FROM "discount"`);
|
||||||
|
await manager.query(`DELETE FROM "discount_rule"`);
|
||||||
|
await manager.query(`DELETE FROM "user"`);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("creates a discount and updates it", async () => {
|
||||||
|
const api = useApi();
|
||||||
|
|
||||||
|
const response = await api
|
||||||
|
.post(
|
||||||
|
"/admin/discounts",
|
||||||
|
{
|
||||||
|
code: "HELLOWORLD",
|
||||||
|
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,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const updated = await api
|
||||||
|
.post(
|
||||||
|
`/admin/discounts/${response.data.discount.id}`,
|
||||||
|
{
|
||||||
|
usage_limit: 20,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
Authorization: "Bearer test_token",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch((err) => {
|
||||||
|
console.log(err);
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(updated.status).toEqual(200);
|
||||||
|
expect(updated.data.discount).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
code: "HELLOWORLD",
|
||||||
|
usage_limit: 20,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("POST /admin/discounts/:discount_id/dynamic-codes", () => {
|
describe("POST /admin/discounts/:discount_id/dynamic-codes", () => {
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
const manager = dbConnection.manager;
|
const manager = dbConnection.manager;
|
||||||
|
|||||||
@@ -36,6 +36,9 @@ import { MedusaError, Validator } from "medusa-core-utils"
|
|||||||
* type: array
|
* type: array
|
||||||
* items:
|
* items:
|
||||||
* type: string
|
* type: string
|
||||||
|
* usage_limit:
|
||||||
|
* type: number
|
||||||
|
* description: Maximum times the discount can be used
|
||||||
* metadata:
|
* metadata:
|
||||||
* description: An optional set of key-value pairs to hold additional information.
|
* description: An optional set of key-value pairs to hold additional information.
|
||||||
* type: object
|
* type: object
|
||||||
@@ -57,21 +60,21 @@ export default async (req, res) => {
|
|||||||
is_dynamic: Validator.boolean().default(false),
|
is_dynamic: Validator.boolean().default(false),
|
||||||
rule: Validator.object()
|
rule: Validator.object()
|
||||||
.keys({
|
.keys({
|
||||||
description: Validator.string().optional(),
|
description: Validator.string().required(),
|
||||||
type: Validator.string().required(),
|
type: Validator.string().required(),
|
||||||
value: Validator.number()
|
value: Validator.number()
|
||||||
.positive()
|
.positive()
|
||||||
.required(),
|
.required(),
|
||||||
allocation: Validator.string().required(),
|
allocation: Validator.string().required(),
|
||||||
valid_for: Validator.array().items(Validator.string()),
|
valid_for: Validator.array().items(Validator.string()),
|
||||||
usage_limit: Validator.number()
|
|
||||||
.positive()
|
|
||||||
.optional(),
|
|
||||||
})
|
})
|
||||||
.required(),
|
.required(),
|
||||||
is_disabled: Validator.boolean().default(false),
|
is_disabled: Validator.boolean().default(false),
|
||||||
starts_at: Validator.date().optional(),
|
starts_at: Validator.date().optional(),
|
||||||
ends_at: Validator.date().optional(),
|
ends_at: Validator.date().optional(),
|
||||||
|
usage_limit: Validator.number()
|
||||||
|
.positive()
|
||||||
|
.optional(),
|
||||||
regions: Validator.array()
|
regions: Validator.array()
|
||||||
.items(Validator.string())
|
.items(Validator.string())
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|||||||
@@ -64,14 +64,14 @@ export default async (req, res) => {
|
|||||||
value: Validator.number().required(),
|
value: Validator.number().required(),
|
||||||
allocation: Validator.string().required(),
|
allocation: Validator.string().required(),
|
||||||
valid_for: Validator.array().items(Validator.string()),
|
valid_for: Validator.array().items(Validator.string()),
|
||||||
usage_limit: Validator.number()
|
|
||||||
.positive()
|
|
||||||
.optional(),
|
|
||||||
})
|
})
|
||||||
.optional(),
|
.optional(),
|
||||||
is_disabled: Validator.boolean().optional(),
|
is_disabled: Validator.boolean().optional(),
|
||||||
starts_at: Validator.date().optional(),
|
starts_at: Validator.date().optional(),
|
||||||
ends_at: Validator.date().optional(),
|
ends_at: Validator.date().optional(),
|
||||||
|
usage_limit: Validator.number()
|
||||||
|
.positive()
|
||||||
|
.optional(),
|
||||||
regions: Validator.array()
|
regions: Validator.array()
|
||||||
.items(Validator.string())
|
.items(Validator.string())
|
||||||
.optional(),
|
.optional(),
|
||||||
|
|||||||
Reference in new issue
Block a user