fix(draft-order): create tax-inclusive with discount (#2579)
**What** Fix system error (500) with DraftOrder create operation when payload includes discount in a tax-inclusive context. **How** * Ensure newly created cart contains all required relation in order to calculate line item tax-inclusive pricing with discounts. * Add resilience to TotalsService.getLineDiscounts() * Ensure newly generate line items have variant relation loaded. * fix TotalsService.getLineItemTotals to use the passed lineItem instead of relying on cartOrOrder.items. **Test** * Unit: * TotalsService.getLineDiscounts - coverage * Integration: * Admin API draft-order - coverage * Admin API draft-order create w/ discount in tax-inclusive Resolves: CORE-771 Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com> Co-authored-by: Adrien de Peretti <25098370+adrien2p@users.noreply.github.com>
This commit is contained in:
@@ -1,451 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/collections /admin/collections adds products to collection 1`] = `
|
||||
Object {
|
||||
"collection": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"handle": "test-collection",
|
||||
"id": "test-collection",
|
||||
"metadata": null,
|
||||
"products": Array [
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description1",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product1",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product1",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product1",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product_filtering_1",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product_filtering_1",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "proposed",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product filtering 1",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
"title": "Test collection",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/collections /admin/collections creates a collection 1`] = `
|
||||
Object {
|
||||
"collection": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"handle": "test-handle-creation",
|
||||
"id": StringMatching /\\^pcol_\\*/,
|
||||
"metadata": null,
|
||||
"title": "test collection creation",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/collections /admin/collections filters collections by title 1`] = `
|
||||
Object {
|
||||
"collections": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"handle": "test-collection",
|
||||
"id": "test-collection",
|
||||
"products": Array [
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description1",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product1",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product1",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product1",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
"title": "Test collection",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
"count": 1,
|
||||
"limit": 10,
|
||||
"offset": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/collections /admin/collections lists collections 1`] = `
|
||||
Object {
|
||||
"collections": Array [
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"handle": "test-collection2",
|
||||
"id": "test-collection2",
|
||||
"products": Array [
|
||||
Object {
|
||||
"collection_id": "test-collection2",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product_filtering_2",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product_filtering_2",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "published",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product filtering 2",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
"title": "Test collection 2",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"handle": "test-collection1",
|
||||
"id": "test-collection1",
|
||||
"products": Array [
|
||||
Object {
|
||||
"collection_id": "test-collection1",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product_filtering_1",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product_filtering_1",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "proposed",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product filtering 1",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection_id": "test-collection1",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product_filtering_3",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product_filtering_3",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product filtering 3",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
"title": "Test collection 1",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
Object {
|
||||
"created_at": Any<String>,
|
||||
"handle": "test-collection",
|
||||
"id": "test-collection",
|
||||
"products": Array [
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description1",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product1",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product1",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product1",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
"title": "Test collection",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
],
|
||||
"count": 3,
|
||||
"limit": 10,
|
||||
"offset": 0,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/collections /admin/collections removes products from collection 1`] = `
|
||||
Object {
|
||||
"id": "test-collection",
|
||||
"object": "product-collection",
|
||||
"removed_products": Array [
|
||||
"test-product",
|
||||
],
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/collections /admin/collections/:id gets collection 1`] = `
|
||||
Object {
|
||||
"collection": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"handle": "test-collection",
|
||||
"id": "test-collection",
|
||||
"metadata": null,
|
||||
"products": Array [
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
Object {
|
||||
"collection_id": "test-collection",
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"description": "test-product-description1",
|
||||
"discountable": true,
|
||||
"external_id": null,
|
||||
"handle": "test-product1",
|
||||
"height": null,
|
||||
"hs_code": null,
|
||||
"id": "test-product1",
|
||||
"is_giftcard": false,
|
||||
"length": null,
|
||||
"material": null,
|
||||
"metadata": null,
|
||||
"mid_code": null,
|
||||
"origin_country": null,
|
||||
"profile_id": StringMatching /\\^sp_\\*/,
|
||||
"status": "draft",
|
||||
"subtitle": null,
|
||||
"thumbnail": null,
|
||||
"title": "Test product1",
|
||||
"type_id": "test-type",
|
||||
"updated_at": Any<String>,
|
||||
"weight": null,
|
||||
"width": null,
|
||||
},
|
||||
],
|
||||
"title": "Test collection",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/collections /admin/collections/:id updates a collection 1`] = `
|
||||
Object {
|
||||
"collection": Object {
|
||||
"created_at": Any<String>,
|
||||
"deleted_at": null,
|
||||
"handle": "test-handle-creation",
|
||||
"id": StringMatching /\\^pcol_\\*/,
|
||||
"metadata": null,
|
||||
"title": "test collection creation",
|
||||
"updated_at": Any<String>,
|
||||
},
|
||||
}
|
||||
`;
|
||||
@@ -1,85 +0,0 @@
|
||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||
|
||||
exports[`/admin/draft-orders POST /admin/draft-orders creates a draft order with a billing address that is an AddressPayload and a shipping address that is an ID 1`] = `
|
||||
Object {
|
||||
"address_1": null,
|
||||
"address_2": null,
|
||||
"city": null,
|
||||
"company": null,
|
||||
"country_code": "us",
|
||||
"created_at": Any<String>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "oli",
|
||||
"id": "oli-shipping",
|
||||
"last_name": "test",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": null,
|
||||
"province": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/draft-orders POST /admin/draft-orders creates a draft order with a billing address that is an AddressPayload and a shipping address that is an ID 2`] = `
|
||||
Object {
|
||||
"address_1": null,
|
||||
"address_2": null,
|
||||
"city": null,
|
||||
"company": null,
|
||||
"country_code": "us",
|
||||
"created_at": Any<String>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "kap",
|
||||
"id": Any<String>,
|
||||
"last_name": "test",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": null,
|
||||
"province": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/draft-orders POST /admin/draft-orders creates a draft order with a shipping address that is an AddressPayload and a billing adress that is an ID 1`] = `
|
||||
Object {
|
||||
"address_1": null,
|
||||
"address_2": null,
|
||||
"city": null,
|
||||
"company": null,
|
||||
"country_code": "us",
|
||||
"created_at": Any<String>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "oli",
|
||||
"id": "oli-shipping",
|
||||
"last_name": "test",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": null,
|
||||
"province": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
|
||||
exports[`/admin/draft-orders POST /admin/draft-orders creates a draft order with a shipping address that is an AddressPayload and a billing adress that is an ID 2`] = `
|
||||
Object {
|
||||
"address_1": null,
|
||||
"address_2": null,
|
||||
"city": null,
|
||||
"company": null,
|
||||
"country_code": "us",
|
||||
"created_at": Any<String>,
|
||||
"customer_id": null,
|
||||
"deleted_at": null,
|
||||
"first_name": "kap",
|
||||
"id": Any<String>,
|
||||
"last_name": "test",
|
||||
"metadata": null,
|
||||
"phone": null,
|
||||
"postal_code": null,
|
||||
"province": null,
|
||||
"updated_at": Any<String>,
|
||||
}
|
||||
`;
|
||||
@@ -70,15 +70,17 @@ describe("/admin/collections", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collection: {
|
||||
id: expect.stringMatching(/^pcol_*/),
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: expect.stringMatching(/^pcol_*/),
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("deletes a collection", async () => {
|
||||
@@ -112,27 +114,29 @@ describe("/admin/collections", () => {
|
||||
headers: { Authorization: "Bearer test_token" },
|
||||
})
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collection: {
|
||||
id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -160,15 +164,17 @@ describe("/admin/collections", () => {
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collection: {
|
||||
id: expect.stringMatching(/^pcol_*/),
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
},
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: expect.stringMatching(/^pcol_*/),
|
||||
title: "test collection creation",
|
||||
handle: "test-handle-creation",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("lists collections", async () => {
|
||||
@@ -178,68 +184,70 @@ describe("/admin/collections", () => {
|
||||
headers: { Authorization: "Bearer test_token" },
|
||||
})
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collections: [
|
||||
{
|
||||
id: "test-collection2",
|
||||
handle: "test-collection2",
|
||||
title: "Test collection 2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "test-collection1",
|
||||
handle: "test-collection1",
|
||||
title: "Test collection 1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
{
|
||||
collection_id: "test-collection1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
count: 3,
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
count: 3,
|
||||
collections: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-collection2",
|
||||
handle: "test-collection2",
|
||||
title: "Test collection 2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection2",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-collection1",
|
||||
handle: "test-collection1",
|
||||
title: "Test collection 1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("adds products to collection", async () => {
|
||||
@@ -258,36 +266,38 @@ describe("/admin/collections", () => {
|
||||
)
|
||||
.catch((err) => console.warn(err))
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collection: {
|
||||
id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
id: "test-product",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
id: "test-product1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
id: "test-product_filtering_1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
collection: expect.objectContaining({
|
||||
id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
id: "test-product",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
id: "test-product_filtering_1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
id: "test-product1",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
})
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
@@ -302,11 +312,13 @@ describe("/admin/collections", () => {
|
||||
})
|
||||
.catch((err) => console.warn(err))
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
id: "test-collection",
|
||||
object: "product-collection",
|
||||
removed_products: ["test-product"],
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "test-collection",
|
||||
object: "product-collection",
|
||||
removed_products: ["test-product"],
|
||||
})
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
@@ -320,34 +332,36 @@ describe("/admin/collections", () => {
|
||||
})
|
||||
.catch((err) => console.log(err))
|
||||
|
||||
expect(response.data).toMatchSnapshot({
|
||||
collections: [
|
||||
{
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: [
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
{
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
count: 1,
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
})
|
||||
expect(response.data).toEqual(
|
||||
expect.objectContaining({
|
||||
count: 1,
|
||||
limit: 10,
|
||||
offset: 0,
|
||||
collections: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
id: "test-collection",
|
||||
handle: "test-collection",
|
||||
title: "Test collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
products: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
expect.objectContaining({
|
||||
collection_id: "test-collection",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
profile_id: expect.stringMatching(/^sp_*/),
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
]),
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
it("returns a list of collections filtered by discount condition id", async () => {
|
||||
|
||||
@@ -1,22 +1,32 @@
|
||||
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 draftOrderSeeder = require("../../helpers/draft-order-seeder")
|
||||
const adminSeeder = require("../../helpers/admin-seeder")
|
||||
const draftOrderSeeder = require("../../../helpers/draft-order-seeder")
|
||||
const adminSeeder = require("../../../helpers/admin-seeder")
|
||||
const {
|
||||
simpleRegionFactory,
|
||||
simpleDiscountFactory,
|
||||
} = require("../../../factories")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
const adminReqConfig = {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
|
||||
describe("/admin/draft-orders", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", ".."))
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
dbConnection = await initDb({ cwd })
|
||||
medusaProcess = await setupServer({ cwd })
|
||||
medusaProcess = await setupServer({ cwd, verbose: true })
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
@@ -40,9 +50,15 @@ describe("/admin/draft-orders", () => {
|
||||
it("creates a draft order cart", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await simpleDiscountFactory(dbConnection, {
|
||||
code: "testytest",
|
||||
regions: ["test-region"],
|
||||
})
|
||||
|
||||
const payload = {
|
||||
email: "oli@test.dk",
|
||||
shipping_address: "oli-shipping",
|
||||
discounts: [{ code: "testytest" }],
|
||||
items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
@@ -59,15 +75,11 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
@@ -94,22 +106,18 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const draftOrderId = response.data.draft_order.id
|
||||
|
||||
const draftOrderResponse = await api.get(
|
||||
`/admin/draft-orders/${draftOrderId}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
expect(draftOrderResponse.status).toEqual(200)
|
||||
expect(draftOrderResponse.data.draft_order.cart.shipping_total).toEqual(
|
||||
@@ -147,15 +155,7 @@ describe("/admin/draft-orders", () => {
|
||||
const {
|
||||
status,
|
||||
data: { draft_order },
|
||||
} = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
} = await api.post("/admin/draft-orders", payload, adminReqConfig)
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(draft_order.cart.billing_address_id).not.toBeNull()
|
||||
@@ -163,29 +163,25 @@ describe("/admin/draft-orders", () => {
|
||||
|
||||
const afterCreate = await api.get(
|
||||
`/admin/draft-orders/${draft_order.id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(
|
||||
afterCreate.data.draft_order.cart.shipping_address
|
||||
).toMatchSnapshot({
|
||||
id: "oli-shipping",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
expect(afterCreate.data.draft_order.cart.billing_address).toMatchSnapshot(
|
||||
{
|
||||
expect(afterCreate.data.draft_order.cart.shipping_address).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "oli-shipping",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
})
|
||||
)
|
||||
expect(afterCreate.data.draft_order.cart.billing_address).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
first_name: "kap",
|
||||
last_name: "test",
|
||||
country_code: "us",
|
||||
}
|
||||
})
|
||||
)
|
||||
})
|
||||
|
||||
@@ -219,15 +215,7 @@ describe("/admin/draft-orders", () => {
|
||||
const {
|
||||
status,
|
||||
data: { draft_order },
|
||||
} = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
} = await api.post("/admin/draft-orders", payload, adminReqConfig)
|
||||
|
||||
expect(status).toEqual(200)
|
||||
expect(draft_order.cart.billing_address_id).not.toBeNull()
|
||||
@@ -235,30 +223,26 @@ describe("/admin/draft-orders", () => {
|
||||
|
||||
const afterCreate = await api.get(
|
||||
`/admin/draft-orders/${draft_order.id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(afterCreate.data.draft_order.cart.billing_address).toMatchSnapshot(
|
||||
{
|
||||
expect(afterCreate.data.draft_order.cart.billing_address).toEqual(
|
||||
expect.objectContaining({
|
||||
id: "oli-shipping",
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
}
|
||||
})
|
||||
)
|
||||
expect(afterCreate.data.draft_order.cart.shipping_address).toEqual(
|
||||
expect.objectContaining({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
first_name: "kap",
|
||||
last_name: "test",
|
||||
country_code: "us",
|
||||
})
|
||||
)
|
||||
expect(
|
||||
afterCreate.data.draft_order.cart.shipping_address
|
||||
).toMatchSnapshot({
|
||||
id: expect.any(String),
|
||||
created_at: expect.any(String),
|
||||
updated_at: expect.any(String),
|
||||
first_name: "kap",
|
||||
last_name: "test",
|
||||
country_code: "us",
|
||||
})
|
||||
})
|
||||
|
||||
it("creates a draft order cart and creates new user", async () => {
|
||||
@@ -283,15 +267,11 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -324,11 +304,7 @@ describe("/admin/draft-orders", () => {
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.post("/admin/draft-orders", payload, adminReqConfig)
|
||||
.catch((err) => {
|
||||
return err.response
|
||||
})
|
||||
@@ -362,15 +338,11 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
@@ -401,15 +373,11 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
@@ -442,25 +410,16 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const created = await api
|
||||
.get(`/admin/draft-orders/${response.data.draft_order.id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const created = await api.get(
|
||||
`/admin/draft-orders/${response.data.draft_order.id}`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(created.data.draft_order.cart.items).toEqual(
|
||||
@@ -505,15 +464,11 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const draftOrder = response.data.draft_order
|
||||
const lineItemId = draftOrder.cart.items[0].id
|
||||
@@ -561,25 +516,16 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const created = await api
|
||||
.get(`/admin/draft-orders/${response.data.draft_order.id}`, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const created = await api.get(
|
||||
`/admin/draft-orders/${response.data.draft_order.id}`,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const draftOrder = created.data.draft_order
|
||||
const lineItemId = draftOrder.cart.items[0].id
|
||||
@@ -650,15 +596,11 @@ describe("/admin/draft-orders", () => {
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.post("/admin/draft-orders", payload, {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
@@ -669,29 +611,17 @@ describe("/admin/draft-orders", () => {
|
||||
const orderResponse = await api.post(
|
||||
`/admin/draft-orders/test-draft-order/pay`,
|
||||
{},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const createdOrder = await api.get(
|
||||
`/admin/orders/${orderResponse.data.order.id}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const updatedDraftOrder = await api.get(
|
||||
`/admin/draft-orders/test-draft-order`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(orderResponse.status).toEqual(200)
|
||||
@@ -722,15 +652,7 @@ describe("/admin/draft-orders", () => {
|
||||
it("lists draft orders", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/draft-orders", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.get("/admin/draft-orders", adminReqConfig)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -744,15 +666,10 @@ describe("/admin/draft-orders", () => {
|
||||
it("lists draft orders with query", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/draft-orders?q=oli@test", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.get(
|
||||
"/admin/draft-orders?q=oli@test",
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -768,15 +685,10 @@ describe("/admin/draft-orders", () => {
|
||||
it("lists no draft orders on query for non-existing email", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.get("/admin/draft-orders?q=heyo@heyo.dk", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.get(
|
||||
"/admin/draft-orders?q=heyo@heyo.dk",
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -799,11 +711,10 @@ describe("/admin/draft-orders", () => {
|
||||
it("retrieves a draft-order should include the items totals", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const order = await api.get("/admin/draft-orders/test-draft-order", {
|
||||
headers: {
|
||||
authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
const order = await api.get(
|
||||
"/admin/draft-orders/test-draft-order",
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(order.status).toEqual(200)
|
||||
expect(order.data.draft_order).toEqual(
|
||||
@@ -833,15 +744,10 @@ describe("/admin/draft-orders", () => {
|
||||
it("deletes a draft order", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.delete("/admin/draft-orders/test-draft-order", {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
})
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.delete(
|
||||
"/admin/draft-orders/test-draft-order",
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
@@ -867,32 +773,20 @@ describe("/admin/draft-orders", () => {
|
||||
it("updates a line item on the draft order", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/draft-orders/test-draft-order/line-items/test-item",
|
||||
{
|
||||
title: "Update title",
|
||||
unit_price: 1000,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders/test-draft-order/line-items/test-item",
|
||||
{
|
||||
title: "Update title",
|
||||
unit_price: 1000,
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const updatedDraftOrder = await api.get(
|
||||
`/admin/draft-orders/test-draft-order`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const item = updatedDraftOrder.data.draft_order.cart.items[0]
|
||||
@@ -904,32 +798,20 @@ describe("/admin/draft-orders", () => {
|
||||
it("removes the line item, if quantity is 0", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/draft-orders/test-draft-order/line-items/test-item",
|
||||
{
|
||||
title: "Update title",
|
||||
quantity: 0,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders/test-draft-order/line-items/test-item",
|
||||
{
|
||||
title: "Update title",
|
||||
quantity: 0,
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const updatedDraftOrder = await api.get(
|
||||
`/admin/draft-orders/test-draft-order`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const items = updatedDraftOrder.data.draft_order.cart.items
|
||||
@@ -952,48 +834,36 @@ describe("/admin/draft-orders", () => {
|
||||
it("updates a line item on the draft order", async () => {
|
||||
const api = useApi()
|
||||
|
||||
const response = await api
|
||||
.post(
|
||||
"/admin/draft-orders/test-draft-order",
|
||||
{
|
||||
email: "lebron@james.com",
|
||||
billing_address: {
|
||||
first_name: "lebron",
|
||||
last_name: "james",
|
||||
address_1: "hollywood boulevard 1",
|
||||
city: "hollywood",
|
||||
country_code: "us",
|
||||
postal_code: "2100",
|
||||
},
|
||||
shipping_address: {
|
||||
first_name: "lebron",
|
||||
last_name: "james",
|
||||
address_1: "hollywood boulevard 1",
|
||||
city: "hollywood",
|
||||
country_code: "us",
|
||||
postal_code: "2100",
|
||||
},
|
||||
discounts: [{ code: "TEST" }],
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders/test-draft-order",
|
||||
{
|
||||
email: "lebron@james.com",
|
||||
billing_address: {
|
||||
first_name: "lebron",
|
||||
last_name: "james",
|
||||
address_1: "hollywood boulevard 1",
|
||||
city: "hollywood",
|
||||
country_code: "us",
|
||||
postal_code: "2100",
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
)
|
||||
.catch((err) => {
|
||||
console.log(err)
|
||||
})
|
||||
shipping_address: {
|
||||
first_name: "lebron",
|
||||
last_name: "james",
|
||||
address_1: "hollywood boulevard 1",
|
||||
city: "hollywood",
|
||||
country_code: "us",
|
||||
postal_code: "2100",
|
||||
},
|
||||
discounts: [{ code: "TEST" }],
|
||||
},
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
|
||||
const updatedDraftOrder = await api.get(
|
||||
`/admin/draft-orders/test-draft-order`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const dorder = updatedDraftOrder.data.draft_order
|
||||
@@ -0,0 +1,185 @@
|
||||
const path = require("path")
|
||||
|
||||
const draftOrderSeeder = require("../../../helpers/draft-order-seeder")
|
||||
const adminSeeder = require("../../../helpers/admin-seeder")
|
||||
const {
|
||||
simpleDiscountFactory,
|
||||
simpleRegionFactory,
|
||||
simpleShippingOptionFactory,
|
||||
} = require("../../../factories")
|
||||
const startServerWithEnvironment =
|
||||
require("../../../../helpers/start-server-with-environment").default
|
||||
const { useDb } = require("../../../../helpers/use-db")
|
||||
const { useApi } = require("../../../../helpers/use-api")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
const adminReqConfig = {
|
||||
headers: {
|
||||
Authorization: "Bearer test_token",
|
||||
},
|
||||
}
|
||||
|
||||
describe("[MEDUSA_FF_TAX_INCLUSIVE_PRICING] /admin/draft-orders", () => {
|
||||
let medusaProcess
|
||||
let dbConnection
|
||||
|
||||
beforeAll(async () => {
|
||||
const cwd = path.resolve(path.join(__dirname, "..", "..", ".."))
|
||||
const [process, connection] = await startServerWithEnvironment({
|
||||
cwd,
|
||||
env: { MEDUSA_FF_TAX_INCLUSIVE_PRICING: true },
|
||||
verbose: false,
|
||||
})
|
||||
|
||||
dbConnection = connection
|
||||
medusaProcess = process
|
||||
})
|
||||
|
||||
afterAll(async () => {
|
||||
const db = useDb()
|
||||
await db.shutdown()
|
||||
|
||||
medusaProcess.kill()
|
||||
})
|
||||
|
||||
describe("POST /admin/draft-orders", () => {
|
||||
beforeEach(async () => {
|
||||
await adminSeeder(dbConnection)
|
||||
await draftOrderSeeder(dbConnection)
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
const db = useDb()
|
||||
await db.teardown()
|
||||
})
|
||||
|
||||
it("creates a draft order cart", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
id: "taxincl-region",
|
||||
includes_tax: true,
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
await dbConnection.manager.query(
|
||||
`update currency
|
||||
set includes_tax = true
|
||||
where code = 'usd'`
|
||||
)
|
||||
|
||||
await simpleDiscountFactory(dbConnection, {
|
||||
code: "testytest",
|
||||
regions: ["taxincl-region"],
|
||||
})
|
||||
await simpleShippingOptionFactory(dbConnection, {
|
||||
id: "taxincl-option",
|
||||
price: 100,
|
||||
region_id: "taxincl-region",
|
||||
})
|
||||
|
||||
const payload = {
|
||||
email: "oli@test.dk",
|
||||
shipping_address: "oli-shipping",
|
||||
discounts: [{ code: "testytest" }],
|
||||
items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
quantity: 2,
|
||||
metadata: {},
|
||||
},
|
||||
],
|
||||
region_id: "taxincl-region",
|
||||
customer_id: "oli-test",
|
||||
shipping_methods: [
|
||||
{
|
||||
option_id: "taxincl-option",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
expect(response.status).toEqual(200)
|
||||
})
|
||||
|
||||
it("creates a draft order with discount and line item", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await simpleRegionFactory(dbConnection, {
|
||||
id: "taxincl-region",
|
||||
includes_tax: true,
|
||||
currency_code: "usd",
|
||||
})
|
||||
|
||||
await dbConnection.manager.query(
|
||||
`update currency
|
||||
set includes_tax = true
|
||||
where code = 'usd'`
|
||||
)
|
||||
|
||||
await simpleDiscountFactory(dbConnection, {
|
||||
id: "disc_testytest",
|
||||
code: "testytest",
|
||||
regions: ["taxincl-region"],
|
||||
})
|
||||
await simpleShippingOptionFactory(dbConnection, {
|
||||
id: "taxincl-option",
|
||||
price: 100,
|
||||
region_id: "taxincl-region",
|
||||
})
|
||||
|
||||
const payload = {
|
||||
email: "oli@test.dk",
|
||||
shipping_address: "oli-shipping",
|
||||
discounts: [{ code: "testytest" }],
|
||||
items: [
|
||||
{
|
||||
variant_id: "test-variant",
|
||||
quantity: 2,
|
||||
metadata: {},
|
||||
},
|
||||
],
|
||||
region_id: "taxincl-region",
|
||||
customer_id: "oli-test",
|
||||
shipping_methods: [
|
||||
{
|
||||
option_id: "taxincl-option",
|
||||
},
|
||||
],
|
||||
}
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/draft-orders",
|
||||
payload,
|
||||
adminReqConfig
|
||||
)
|
||||
|
||||
const draftOrder = response.data.draft_order
|
||||
const lineItemId = draftOrder.cart.items[0].id
|
||||
|
||||
expect(response.status).toEqual(200)
|
||||
expect(draftOrder.cart.items).toEqual(
|
||||
expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
variant_id: "test-variant",
|
||||
unit_price: 8000,
|
||||
quantity: 2,
|
||||
adjustments: expect.arrayContaining([
|
||||
expect.objectContaining({
|
||||
item_id: lineItemId,
|
||||
amount: 1600,
|
||||
description: "discount",
|
||||
discount_id: "disc_testytest",
|
||||
}),
|
||||
]),
|
||||
}),
|
||||
])
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -22,6 +22,7 @@ const {
|
||||
callGet,
|
||||
partial,
|
||||
} = require("../../../helpers/call-helpers")
|
||||
const { simpleShippingOptionFactory } = require("../../../factories")
|
||||
|
||||
jest.setTimeout(30000)
|
||||
|
||||
@@ -1760,6 +1761,12 @@ describe("/admin/orders", () => {
|
||||
it("creates a swap", async () => {
|
||||
const api = useApi()
|
||||
|
||||
await simpleShippingOptionFactory(dbConnection, {
|
||||
id: "testytest",
|
||||
is_return: true,
|
||||
region_id: "test-region",
|
||||
})
|
||||
|
||||
const response = await api.post(
|
||||
"/admin/orders/test-order/swaps",
|
||||
{
|
||||
@@ -1770,6 +1777,10 @@ describe("/admin/orders", () => {
|
||||
},
|
||||
],
|
||||
additional_items: [{ variant_id: "test-variant-2", quantity: 1 }],
|
||||
return_shipping: {
|
||||
option_id: "testytest",
|
||||
price: 400,
|
||||
},
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
|
||||
Reference in New Issue
Block a user