feat: Allow backorder on swaps (#404)

This commit is contained in:
Oliver Windall Juhl
2021-09-19 15:33:43 +02:00
committed by GitHub
parent 75b608330b
commit 00ab03f3a2
20 changed files with 1038 additions and 393 deletions

View File

@@ -0,0 +1,382 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/admin/products GET /admin/products returns a list of products with child entities 1`] = `
Array [
Object {
"collection": Object {
"created_at": Any<String>,
"deleted_at": null,
"handle": "test-collection",
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"title": "Test collection",
"updated_at": Any<String>,
},
"collection_id": "test-collection",
"created_at": Any<String>,
"deleted_at": null,
"description": "test-product-description",
"discountable": true,
"handle": "test-product",
"height": null,
"hs_code": null,
"id": StringMatching /\\^test-\\*/,
"images": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"url": "test-image.png",
},
],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"product_id": StringMatching /\\^test-\\*/,
"title": "test-option",
"updated_at": Any<String>,
},
],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"subtitle": null,
"tags": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^tag\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "123",
},
],
"thumbnail": null,
"title": "Test product",
"type": Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "test-type",
},
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Array [
Object {
"allow_backorder": false,
"barcode": "test-barcode",
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean",
"height": null,
"hs_code": null,
"id": "test-variant",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku",
"title": "Test variant",
"upc": "test-upc",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean2",
"height": null,
"hs_code": null,
"id": "test-variant_2",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 2",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku2",
"title": "Test variant rank (2)",
"upc": "test-upc2",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": "test-barcode 1",
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean1",
"height": null,
"hs_code": null,
"id": "test-variant_1",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 1",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku1",
"title": "Test variant rank (1)",
"upc": "test-upc1",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
],
"weight": null,
"width": null,
},
Object {
"collection": Object {
"created_at": Any<String>,
"deleted_at": null,
"handle": "test-collection",
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"title": "Test collection",
"updated_at": Any<String>,
},
"collection_id": "test-collection",
"created_at": Any<String>,
"deleted_at": null,
"description": "test-product-description1",
"discountable": true,
"handle": "test-product1",
"height": null,
"hs_code": null,
"id": StringMatching /\\^test-\\*/,
"images": Array [],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"subtitle": null,
"tags": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^tag\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "123",
},
],
"thumbnail": null,
"title": "Test product1",
"type": Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "test-type",
},
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Array [
Object {
"allow_backorder": false,
"barcode": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean4",
"height": null,
"hs_code": null,
"id": "test-variant_4",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 4",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku4",
"title": "Test variant rank (2)",
"upc": "test-upc4",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean3",
"height": null,
"hs_code": null,
"id": "test-variant_3",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 3",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": StringMatching /\\^test-price\\*/,
"region_id": null,
"sale_amount": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku3",
"title": "Test variant rank (2)",
"upc": "test-upc3",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
],
"weight": null,
"width": null,
},
]
`;

View File

@@ -1,49 +1,49 @@
const path = require("path");
const path = require("path")
const setupServer = require("../../../helpers/setup-server");
const { useApi } = require("../../../helpers/use-api");
const { initDb, useDb } = require("../../../helpers/use-db");
const setupServer = require("../../../helpers/setup-server")
const { useApi } = require("../../../helpers/use-api")
const { initDb, useDb } = require("../../../helpers/use-db")
const orderSeeder = require("../../helpers/order-seeder");
const swapSeeder = require("../../helpers/swap-seeder");
const adminSeeder = require("../../helpers/admin-seeder");
const orderSeeder = require("../../helpers/order-seeder")
const swapSeeder = require("../../helpers/swap-seeder")
const adminSeeder = require("../../helpers/admin-seeder")
jest.setTimeout(30000);
jest.setTimeout(30000)
describe("/admin/swaps", () => {
let medusaProcess;
let dbConnection;
let medusaProcess
let dbConnection
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."));
dbConnection = await initDb({ cwd });
medusaProcess = await setupServer({ cwd });
});
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
medusaProcess = await setupServer({ cwd })
})
afterAll(async () => {
const db = useDb();
await db.shutdown();
medusaProcess.kill();
});
const db = useDb()
await db.shutdown()
medusaProcess.kill()
})
describe("GET /admin/swaps/:id", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection);
await orderSeeder(dbConnection);
await swapSeeder(dbConnection);
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
} catch (err) {
throw err;
throw err
}
});
})
afterEach(async () => {
const db = useDb();
await db.teardown();
});
const db = useDb()
await db.teardown()
})
it("gets a swap with cart and totals", async () => {
const api = useApi();
const api = useApi()
const response = await api
.get("/admin/swaps/test-swap", {
@@ -52,46 +52,46 @@ describe("/admin/swaps", () => {
},
})
.catch((err) => {
console.log(err);
});
expect(response.status).toEqual(200);
console.log(err)
})
expect(response.status).toEqual(200)
expect(response.data.swap).toEqual(
expect.objectContaining({
id: "test-swap",
})
);
)
expect(response.data.swap.cart).toEqual(
expect.objectContaining({
id: "test-cart",
id: "test-cart-w-swap",
shipping_total: 1000,
subtotal: 1000,
total: 2000,
})
);
expect(response.data.swap.cart).toHaveProperty("discount_total");
expect(response.data.swap.cart).toHaveProperty("gift_card_total");
});
});
)
expect(response.data.swap.cart).toHaveProperty("discount_total")
expect(response.data.swap.cart).toHaveProperty("gift_card_total")
})
})
describe("GET /admin/swaps/", () => {
beforeEach(async () => {
try {
await adminSeeder(dbConnection);
await orderSeeder(dbConnection);
await swapSeeder(dbConnection);
await adminSeeder(dbConnection)
await orderSeeder(dbConnection)
await swapSeeder(dbConnection)
} catch (err) {
throw err;
throw err
}
});
})
afterEach(async () => {
const db = useDb();
await db.teardown();
});
const db = useDb()
await db.teardown()
})
it("lists all swaps", async () => {
const api = useApi();
const api = useApi()
const response = await api
.get("/admin/swaps/", {
@@ -100,18 +100,18 @@ describe("/admin/swaps", () => {
},
})
.catch((err) => {
console.log(err);
});
console.log(err)
})
expect(response.status).toEqual(200);
expect(response.data).toHaveProperty("count");
expect(response.data.offset).toBe(0);
expect(response.data.limit).toBe(50);
expect(response.status).toEqual(200)
expect(response.data).toHaveProperty("count")
expect(response.data.offset).toBe(0)
expect(response.data.limit).toBe(50)
expect(response.data.swaps).toContainEqual(
expect.objectContaining({
id: "test-swap",
})
);
});
});
});
)
})
})
})