Merge branch 'develop' into feat/draft-orders
This commit is contained in:
79
integration-tests/api/__tests__/admin/gift-cards.js
Normal file
79
integration-tests/api/__tests__/admin/gift-cards.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const { dropDatabase } = require("pg-god");
|
||||
const path = require("path");
|
||||
const { Region } = require("@medusajs/medusa");
|
||||
|
||||
const setupServer = require("../../../helpers/setup-server");
|
||||
const { useApi } = require("../../../helpers/use-api");
|
||||
const { initDb } = require("../../../helpers/use-db");
|
||||
const adminSeeder = require("../../helpers/admin-seeder");
|
||||
|
||||
jest.setTimeout(30000);
|
||||
|
||||
describe("/admin/gift-cards", () => {
|
||||
let medusaProcess;
|
||||
let dbConnection;
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."));
|
||||
dbConnection = await initDb({ cwd });
|
||||
medusaProcess = await setupServer({ cwd });
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await dbConnection.close();
|
||||
await dropDatabase({ databaseName: "medusa-integration" });
|
||||
|
||||
medusaProcess.kill();
|
||||
});
|
||||
|
||||
describe("POST /admin/gift-cards", () => {
|
||||
beforeEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
await manager.insert(Region, {
|
||||
id: "region",
|
||||
name: "Test Region",
|
||||
currency_code: "usd",
|
||||
tax_rate: 0,
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "gift_card"`);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("creates a gift card", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/gift-cards",
|
||||
{
|
||||
value: 1000,
|
||||
region_id: "region",
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err);
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.gift_card.value).toEqual(1000);
|
||||
expect(response.data.gift_card.balance).toEqual(1000);
|
||||
expect(response.data.gift_card.region_id).toEqual("region");
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -151,30 +151,29 @@ describe("/admin/orders", () => {
|
||||
);
|
||||
expect(response.status).toEqual(200);
|
||||
|
||||
expect(response.data.order.claims[0].claim_items).toEqual([
|
||||
expect.objectContaining({
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason: "production_failure",
|
||||
images: [
|
||||
expect.objectContaining({
|
||||
url: "https://test.image.com",
|
||||
}),
|
||||
],
|
||||
tags: [
|
||||
expect.objectContaining({
|
||||
value: "fluff",
|
||||
}),
|
||||
],
|
||||
}),
|
||||
]);
|
||||
expect(response.data.order.claims[0].claim_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
item_id: "test-item",
|
||||
quantity: 1,
|
||||
reason: "production_failure",
|
||||
images: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
url: "https://test.image.com",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
);
|
||||
|
||||
expect(response.data.order.claims[0].additional_items).toEqual([
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
}),
|
||||
]);
|
||||
expect(response.data.order.claims[0].additional_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant",
|
||||
quantity: 1,
|
||||
}),
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it("updates a claim", async () => {
|
||||
@@ -296,26 +295,28 @@ describe("/admin/orders", () => {
|
||||
claim = updateData.order.claims[0];
|
||||
|
||||
expect(claim.claim_items.length).toEqual(1);
|
||||
expect(claim.claim_items).toEqual([
|
||||
expect.objectContaining({
|
||||
id: claim.claim_items[0].id,
|
||||
reason: "production_failure",
|
||||
note: "Something new",
|
||||
images: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
url: "https://test.image.com",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
url: "https://new.com/image",
|
||||
}),
|
||||
]),
|
||||
tags: expect.arrayContaining([
|
||||
expect.objectContaining({ value: "completely" }),
|
||||
expect.objectContaining({ value: "new" }),
|
||||
expect.objectContaining({ value: "tags" }),
|
||||
]),
|
||||
}),
|
||||
]);
|
||||
expect(claim.claim_items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: claim.claim_items[0].id,
|
||||
reason: "production_failure",
|
||||
note: "Something new",
|
||||
images: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
url: "https://test.image.com",
|
||||
}),
|
||||
expect.objectContaining({
|
||||
url: "https://new.com/image",
|
||||
}),
|
||||
]),
|
||||
// tags: expect.arrayContaining([
|
||||
// expect.objectContaining({ value: "completely" }),
|
||||
// expect.objectContaining({ value: "new" }),
|
||||
// expect.objectContaining({ value: "tags" }),
|
||||
// ]),
|
||||
}),
|
||||
])
|
||||
);
|
||||
});
|
||||
|
||||
it("updates claim items - removes image", async () => {
|
||||
@@ -384,11 +385,11 @@ describe("/admin/orders", () => {
|
||||
reason: "production_failure",
|
||||
note: "Something new",
|
||||
images: [],
|
||||
tags: expect.arrayContaining([
|
||||
expect.objectContaining({ value: "completely" }),
|
||||
expect.objectContaining({ value: "new" }),
|
||||
expect.objectContaining({ value: "tags" }),
|
||||
]),
|
||||
// tags: expect.arrayContaining([
|
||||
// expect.objectContaining({ value: "completely" }),
|
||||
// expect.objectContaining({ value: "new" }),
|
||||
// expect.objectContaining({ value: "tags" }),
|
||||
// ]),
|
||||
}),
|
||||
]);
|
||||
});
|
||||
@@ -466,4 +467,157 @@ describe("/admin/orders", () => {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("GET /admin/orders", () => {
|
||||
beforeEach(async () => {
|
||||
try {
|
||||
await adminSeeder(dbConnection);
|
||||
// Manually insert date for filtering
|
||||
const createdAt = new Date("26 January 1997 12:00 UTC");
|
||||
await orderSeeder(dbConnection, {
|
||||
created_at: createdAt.toISOString(),
|
||||
});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
|
||||
afterEach(async () => {
|
||||
const manager = dbConnection.manager;
|
||||
await manager.query(`DELETE FROM "cart"`);
|
||||
await manager.query(`DELETE FROM "fulfillment_item"`);
|
||||
await manager.query(`DELETE FROM "fulfillment"`);
|
||||
await manager.query(`DELETE FROM "swap"`);
|
||||
await manager.query(`DELETE FROM "return"`);
|
||||
await manager.query(`DELETE FROM "claim_image"`);
|
||||
await manager.query(`DELETE FROM "claim_tag"`);
|
||||
await manager.query(`DELETE FROM "claim_item"`);
|
||||
await manager.query(`DELETE FROM "shipping_method"`);
|
||||
await manager.query(`DELETE FROM "line_item"`);
|
||||
await manager.query(`DELETE FROM "claim_order"`);
|
||||
await manager.query(`DELETE FROM "money_amount"`);
|
||||
await manager.query(`DELETE FROM "product_variant"`);
|
||||
await manager.query(`DELETE FROM "product"`);
|
||||
await manager.query(`DELETE FROM "shipping_option"`);
|
||||
await manager.query(`DELETE FROM "discount"`);
|
||||
await manager.query(`DELETE FROM "payment"`);
|
||||
await manager.query(`DELETE FROM "order"`);
|
||||
await manager.query(`DELETE FROM "customer"`);
|
||||
await manager.query(
|
||||
`UPDATE "country" SET region_id=NULL WHERE iso_2 = 'us'`
|
||||
);
|
||||
await manager.query(`DELETE FROM "region"`);
|
||||
await manager.query(`DELETE FROM "user"`);
|
||||
});
|
||||
|
||||
it("lists all orders", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.get("/admin/orders?fields=id", {
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
});
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("successfully lists orders with greater than", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.get(
|
||||
"/admin/orders?fields=id&created_at[gt]=01-26-1990",
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("successfully lists no orders with greater than", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.get(
|
||||
"/admin/orders?fields=id&created_at[gt]=01-26-2000",
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.orders).toEqual([]);
|
||||
});
|
||||
|
||||
it("successfully lists orders with less than", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.get(
|
||||
"/admin/orders?fields=id&created_at[lt]=01-26-2000",
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it("successfully lists no orders with less than", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.get(
|
||||
"/admin/orders?fields=id&created_at[lt]=01-26-1990",
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.orders).toEqual([]);
|
||||
});
|
||||
|
||||
it("successfully lists orders using unix (greater than)", async () => {
|
||||
const api = useApi();
|
||||
|
||||
const response = await api.get(
|
||||
"/admin/orders?fields=id&created_at[gt]=633351600",
|
||||
{
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
expect(response.status).toEqual(200);
|
||||
expect(response.data.orders).toEqual([
|
||||
expect.objectContaining({
|
||||
id: "test-order",
|
||||
}),
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user