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:
Patrick
2022-11-16 10:34:18 -05:00
committed by GitHub
parent 03fc9e18e9
commit 022a84691e
17 changed files with 765 additions and 1048 deletions
@@ -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 () => {