fix(integration-tests): Use asymmetric matcher for arrays in tests (#1992)

This commit is contained in:
Adrien de Peretti
2022-08-07 11:50:12 +02:00
committed by GitHub
parent 73383cc466
commit b3b69d7117
16 changed files with 935 additions and 730 deletions
+5
View File
@@ -0,0 +1,5 @@
---
---
Use asymetric matcher for arrays
@@ -331,12 +331,15 @@ describe("/admin/discounts", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1) expect(response.data.count).toEqual(1)
expect(response.data.discounts).toEqual([ expect(response.data.discounts).toHaveLength(1)
expect(response.data.discounts).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "fixed-discount", id: "fixed-discount",
code: "fixed100", code: "fixed100",
}), }),
]) ])
)
}) })
it("fails when listing invalid discount types", async () => { it("fails when listing invalid discount types", async () => {
@@ -394,12 +397,15 @@ describe("/admin/discounts", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1) expect(response.data.count).toEqual(1)
expect(response.data.discounts).toEqual([ expect(response.data.discounts).toHaveLength(1)
expect(response.data.discounts).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "dynamic-discount", id: "dynamic-discount",
code: "Dyn100", code: "Dyn100",
}), })
]) ])
)
}) })
it("lists disabled discounts ", async () => { it("lists disabled discounts ", async () => {
@@ -416,12 +422,15 @@ describe("/admin/discounts", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1) expect(response.data.count).toEqual(1)
expect(response.data.discounts).toEqual([ expect(response.data.discounts).toHaveLength(1)
expect(response.data.discounts).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "disabled-discount", id: "disabled-discount",
code: "Dis100", code: "Dis100",
}), }),
]) ])
)
}) })
}) })
@@ -614,7 +623,9 @@ describe("/admin/discounts", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.discount.rule.conditions).toEqual([ expect(response.data.discount.rule.conditions).toHaveLength(2)
expect(response.data.discount.rule.conditions).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
type: "products", type: "products",
operator: "in", operator: "in",
@@ -624,6 +635,7 @@ describe("/admin/discounts", () => {
operator: "not_in", operator: "not_in",
}), }),
]) ])
)
const createdRule = response.data.discount.rule const createdRule = response.data.discount.rule
const condsToUpdate = createdRule.conditions[0] const condsToUpdate = createdRule.conditions[0]
+48 -12
View File
@@ -673,11 +673,14 @@ describe("/admin/orders", () => {
) )
expect(status).toEqual(200) expect(status).toEqual(200)
expect(updateData.order.claims[0].shipping_methods).toEqual([ expect(updateData.order.claims[0].shipping_methods).toHaveLength(1)
expect(updateData.order.claims[0].shipping_methods).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-method", id: "test-method",
}), }),
]) ])
)
}) })
it("updates claim items", async () => { it("updates claim items", async () => {
@@ -827,7 +830,8 @@ describe("/admin/orders", () => {
claim = updateData.order.claims[0] claim = updateData.order.claims[0]
expect(claim.claim_items.length).toEqual(1) expect(claim.claim_items.length).toEqual(1)
expect(claim.claim_items).toEqual([ expect(claim.claim_items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: claim.claim_items[0].id, id: claim.claim_items[0].id,
reason: "production_failure", reason: "production_failure",
@@ -840,6 +844,7 @@ describe("/admin/orders", () => {
// ]), // ]),
}), }),
]) ])
)
}) })
it("fulfills a claim", async () => { it("fulfills a claim", async () => {
@@ -892,17 +897,23 @@ describe("/admin/orders", () => {
} }
) )
expect(fulRes.status).toEqual(200) expect(fulRes.status).toEqual(200)
expect(fulRes.data.order.claims).toEqual([ expect(fulRes.data.order.claims).toHaveLength(1)
expect(fulRes.data.order.claims).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: cid, id: cid,
order_id: "test-order", order_id: "test-order",
fulfillment_status: "fulfilled", fulfillment_status: "fulfilled",
}), }),
]) ])
)
const fid = fulRes.data.order.claims[0].fulfillments[0].id const fid = fulRes.data.order.claims[0].fulfillments[0].id
const iid = fulRes.data.order.claims[0].additional_items[0].id const iid = fulRes.data.order.claims[0].additional_items[0].id
expect(fulRes.data.order.claims[0].fulfillments).toEqual([
expect(fulRes.data.order.claims[0].fulfillments).toHaveLength(1)
expect(fulRes.data.order.claims[0].fulfillments).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
items: [ items: [
{ {
@@ -913,6 +924,7 @@ describe("/admin/orders", () => {
], ],
}), }),
]) ])
)
}) })
it("creates a claim on a claim additional item", async () => { it("creates a claim on a claim additional item", async () => {
@@ -1318,7 +1330,9 @@ describe("/admin/orders", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.order.returns[0].refund_amount).toEqual(7200) expect(response.data.order.returns[0].refund_amount).toEqual(7200)
expect(response.data.order.returns[0].items).toEqual([ expect(response.data.order.returns[0].items).toHaveLength(1)
expect(response.data.order.returns[0].items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
item_id: "test-item", item_id: "test-item",
quantity: 1, quantity: 1,
@@ -1326,6 +1340,7 @@ describe("/admin/orders", () => {
note: "TOO SMALL", note: "TOO SMALL",
}), }),
]) ])
)
}) })
it("increases inventory_quantity when return is received", async () => { it("increases inventory_quantity when return is received", async () => {
@@ -1420,7 +1435,9 @@ describe("/admin/orders", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.orders).toEqual([ expect(response.data.orders).toHaveLength(6)
expect(response.data.orders).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-order", id: "test-order",
}), }),
@@ -1442,6 +1459,7 @@ describe("/admin/orders", () => {
id: "discount-order", id: "discount-order",
}), }),
]) ])
)
}) })
it("lists all orders with a fulfillment status = fulfilled and payment status = captured", async () => { it("lists all orders with a fulfillment status = fulfilled and payment status = captured", async () => {
@@ -1459,7 +1477,9 @@ describe("/admin/orders", () => {
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.orders).toEqual([ expect(response.data.orders).toHaveLength(2)
expect(response.data.orders).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-order", id: "test-order",
}), }),
@@ -1467,6 +1487,7 @@ describe("/admin/orders", () => {
id: "discount-order", id: "discount-order",
}), }),
]) ])
)
}) })
it("fails to lists all orders with an invalid status", async () => { it("fails to lists all orders with an invalid status", async () => {
@@ -1502,12 +1523,15 @@ describe("/admin/orders", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1) expect(response.data.count).toEqual(1)
expect(response.data.orders).toEqual([ expect(response.data.orders).toHaveLength(1)
expect(response.data.orders).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-order", id: "test-order",
email: "test@email.com", email: "test@email.com",
}), }),
]) ])
)
}) })
it("list all orders with matching shipping_address first name", async () => { it("list all orders with matching shipping_address first name", async () => {
@@ -1546,7 +1570,9 @@ describe("/admin/orders", () => {
) )
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.orders).toEqual([ expect(response.data.orders).toHaveLength(6)
expect(response.data.orders).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-order", id: "test-order",
}), }),
@@ -1567,6 +1593,7 @@ describe("/admin/orders", () => {
id: "discount-order", id: "discount-order",
}), }),
]) ])
)
}) })
it("successfully lists no orders with greater than", async () => { it("successfully lists no orders with greater than", async () => {
@@ -1598,7 +1625,9 @@ describe("/admin/orders", () => {
) )
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.orders).toEqual([ expect(response.data.orders).toHaveLength(6)
expect(response.data.orders).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-order", id: "test-order",
}), }),
@@ -1619,6 +1648,7 @@ describe("/admin/orders", () => {
id: "discount-order", id: "discount-order",
}), }),
]) ])
)
}) })
it("successfully lists no orders with less than", async () => { it("successfully lists no orders with less than", async () => {
@@ -1650,7 +1680,9 @@ describe("/admin/orders", () => {
) )
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.orders).toEqual([ expect(response.data.orders).toHaveLength(6)
expect(response.data.orders).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-order", id: "test-order",
}), }),
@@ -1671,6 +1703,7 @@ describe("/admin/orders", () => {
id: "discount-order", id: "discount-order",
}), }),
]) ])
)
}) })
it.each([ it.each([
@@ -1864,11 +1897,14 @@ describe("/admin/orders", () => {
const cart = response.data.cart const cart = response.data.cart
const items = cart.items const items = cart.items
const [returnItem] = items.filter((i) => i.is_return) const [returnItem] = items.filter((i) => i.is_return)
expect(returnItem.adjustments).toEqual([ expect(returnItem.adjustments).toHaveLength(1)
expect(returnItem.adjustments).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
amount: -800, amount: -800,
}), }),
]) ])
)
expect(cart.total).toBe(7200) expect(cart.total).toBe(7200)
}) })
}) })
@@ -363,10 +363,13 @@ describe("/admin/price-lists", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.price_lists.length).toEqual(2) expect(response.data.price_lists.length).toEqual(2)
expect(response.data.price_lists).toEqual([ expect(response.data.price_lists).toHaveLength(2)
expect(response.data.price_lists).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: "test-list-cgroup-1" }), expect.objectContaining({ id: "test-list-cgroup-1" }),
expect.objectContaining({ id: "test-list-cgroup-2" }), expect.objectContaining({ id: "test-list-cgroup-2" }),
]) ])
)
}) })
}) })
@@ -1177,7 +1180,9 @@ describe("/admin/price-lists", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.count).toEqual(2) expect(response.data.count).toEqual(2)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(2)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-prod-1", id: "test-prod-1",
variants: [ variants: [
@@ -1223,6 +1228,7 @@ describe("/admin/price-lists", () => {
], ],
}), }),
]) ])
)
}) })
it("lists only product 2", async () => { it("lists only product 2", async () => {
@@ -1240,9 +1246,12 @@ describe("/admin/price-lists", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1) expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ id: "test-prod-2" }), expect.objectContaining({ id: "test-prod-2" }),
]) ])
)
}) })
it("lists products using free text search", async () => { it("lists products using free text search", async () => {
@@ -1260,12 +1269,15 @@ describe("/admin/price-lists", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1) expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-prod-1", id: "test-prod-1",
title: "MedusaHeadphones", title: "MedusaHeadphones",
}), }),
]) ])
)
}) })
}) })
@@ -165,7 +165,9 @@ describe("/admin/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(2)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_1", id: "test-product_filtering_1",
status: "proposed", status: "proposed",
@@ -175,6 +177,7 @@ describe("/admin/products", () => {
status: "published", status: "published",
}), }),
]) ])
)
for (const notExpect of notExpected) { for (const notExpect of notExpected) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -204,7 +207,9 @@ describe("/admin/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(2)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_1", id: "test-product_filtering_1",
status: "proposed", status: "proposed",
@@ -214,6 +219,7 @@ describe("/admin/products", () => {
status: "published", status: "published",
}), }),
]) ])
)
for (const notExpect of notExpected) { for (const notExpect of notExpected) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -237,11 +243,14 @@ describe("/admin/products", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.count).toEqual(1) expect(response.data.count).toEqual(1)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_4", id: "test-product_filtering_4",
}), }),
]) ])
)
}) })
it("returns a list of products with free text query and limit", async () => { it("returns a list of products with free text query and limit", async () => {
@@ -322,11 +331,14 @@ describe("/admin/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_4", id: "test-product_filtering_4",
}), }),
]) ])
)
}) })
it("returns a list of products in collection", async () => { it("returns a list of products in collection", async () => {
@@ -348,7 +360,9 @@ describe("/admin/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(2)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_1", id: "test-product_filtering_1",
collection_id: "test-collection1", collection_id: "test-collection1",
@@ -358,6 +372,7 @@ describe("/admin/products", () => {
collection_id: "test-collection1", collection_id: "test-collection1",
}), }),
]) ])
)
for (const notExpect of notExpected) { for (const notExpect of notExpected) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -431,13 +446,16 @@ describe("/admin/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_3", id: "test-product_filtering_3",
collection_id: "test-collection1", collection_id: "test-collection1",
tags: [expect.objectContaining({ id: "tag4" })], tags: [expect.objectContaining({ id: "tag4" })],
}), }),
]) ])
)
for (const notExpect of notExpectedCollections) { for (const notExpect of notExpectedCollections) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -162,7 +162,9 @@ describe("/admin/regions", () => {
console.log(err) console.log(err)
}) })
expect(response.data.regions).toEqual([ expect(response.data.regions).toHaveLength(3)
expect(response.data.regions).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-region-updated-1", id: "test-region-updated-1",
}), }),
@@ -173,6 +175,7 @@ describe("/admin/regions", () => {
id: "test-region-updated", id: "test-region-updated",
}), }),
]) ])
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
}) })
@@ -189,7 +192,9 @@ describe("/admin/regions", () => {
console.log(err) console.log(err)
}) })
expect(response.data.regions).toEqual([ expect(response.data.regions).toHaveLength(2)
expect(response.data.regions).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-region", id: "test-region",
}), }),
@@ -197,6 +202,7 @@ describe("/admin/regions", () => {
id: "test-region-updated", id: "test-region-updated",
}), }),
]) ])
)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
}) })
}) })
@@ -355,7 +355,9 @@ describe("/admin/return-reasons", () => {
expect(nested_response.status).toEqual(200) expect(nested_response.status).toEqual(200)
expect(nested_response.data.return_reasons).toEqual([ expect(nested_response.data.return_reasons).toHaveLength(1)
expect(nested_response.data.return_reasons).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
label: "Wrong size", label: "Wrong size",
description: "Use this if the size was too big", description: "Use this if the size was too big",
@@ -369,6 +371,7 @@ describe("/admin/return-reasons", () => {
]), ]),
}), }),
]) ])
)
}) })
it("list return reasons", async () => { it("list return reasons", async () => {
@@ -401,11 +404,14 @@ describe("/admin/return-reasons", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.return_reasons).toEqual([ expect(response.data.return_reasons).toHaveLength(1)
expect(response.data.return_reasons).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
value: "too_big", value: "too_big",
}), }),
]) ])
)
}) })
}) })
@@ -832,11 +832,13 @@ describe("sales channels", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.orders.length).toEqual(1) expect(response.data.orders.length).toEqual(1)
expect(response.data.orders).toEqual([ expect(response.data.orders).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: order.id, id: order.id,
}), }),
]) ])
)
}) })
}) })
}) })
@@ -72,13 +72,16 @@ describe("/admin/orders", () => {
* 1000 * 1.125 = 1125 * 1000 * 1.125 = 1125
*/ */
expect(response.data.order.returns[0].refund_amount).toEqual(1125) expect(response.data.order.returns[0].refund_amount).toEqual(1125)
expect(response.data.order.returns[0].items).toEqual([ expect(response.data.order.returns[0].items).toHaveLength(1)
expect(response.data.order.returns[0].items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
item_id: "test-item", item_id: "test-item",
quantity: 1, quantity: 1,
note: "TOO SMALL", note: "TOO SMALL",
}), }),
]) ])
)
}) })
test("creates a return w. new tax system", async () => { test("creates a return w. new tax system", async () => {
@@ -113,13 +116,16 @@ describe("/admin/orders", () => {
*/ */
expect(response.data.order.returns[0].refund_amount).toEqual(1200) expect(response.data.order.returns[0].refund_amount).toEqual(1200)
expect(response.data.order.returns[0].items).toEqual([ expect(response.data.order.returns[0].items).toHaveLength(1)
expect(response.data.order.returns[0].items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
item_id: "test-item", item_id: "test-item",
quantity: 1, quantity: 1,
note: "TOO SMALL", note: "TOO SMALL",
}), }),
]) ])
)
}) })
test("creates a return w. new tax system + shipping", async () => { test("creates a return w. new tax system + shipping", async () => {
@@ -163,20 +169,26 @@ describe("/admin/orders", () => {
* shipping method will have 12.5 rate 1000 * 1.125 = 1125 * shipping method will have 12.5 rate 1000 * 1.125 = 1125
*/ */
expect(response.data.order.returns[0].refund_amount).toEqual(75) expect(response.data.order.returns[0].refund_amount).toEqual(75)
expect(response.data.order.returns[0].shipping_method.tax_lines).toEqual([ expect(response.data.order.returns[0].shipping_method.tax_lines).toHaveLength(1)
expect(response.data.order.returns[0].shipping_method.tax_lines).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
rate: 12.5, rate: 12.5,
name: "default", name: "default",
code: "default", code: "default",
}), }),
]) ])
expect(response.data.order.returns[0].items).toEqual([ )
expect(response.data.order.returns[0].items).toHaveLength(1)
expect(response.data.order.returns[0].items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
item_id: "test-item", item_id: "test-item",
quantity: 1, quantity: 1,
note: "TOO SMALL", note: "TOO SMALL",
}), }),
]) ])
)
}) })
test("creates a return w. discount", async () => { test("creates a return w. discount", async () => {
@@ -214,13 +226,16 @@ describe("/admin/orders", () => {
*/ */
expect(response.data.order.returns[0].refund_amount).toEqual(1080) expect(response.data.order.returns[0].refund_amount).toEqual(1080)
expect(response.data.order.returns[0].items).toEqual([ expect(response.data.order.returns[0].items).toHaveLength(1)
expect(response.data.order.returns[0].items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
item_id: "test-item", item_id: "test-item",
quantity: 1, quantity: 1,
note: "TOO SMALL", note: "TOO SMALL",
}), }),
]) ])
)
}) })
test("receives a return with a claimed line item", async () => { test("receives a return with a claimed line item", async () => {
+59 -15
View File
@@ -155,7 +155,9 @@ describe("/store/carts", () => {
response.data.cart.items.sort((a, b) => a.quantity - b.quantity) response.data.cart.items.sort((a, b) => a.quantity - b.quantity)
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(2)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
variant_id: "test-variant_1", variant_id: "test-variant_1",
quantity: 1, quantity: 1,
@@ -166,6 +168,7 @@ describe("/store/carts", () => {
unit_price: 800, unit_price: 800,
}), }),
]) ])
)
const getRes = await api.post(`/store/carts/${response.data.cart.id}`) const getRes = await api.post(`/store/carts/${response.data.cart.id}`)
expect(getRes.status).toEqual(200) expect(getRes.status).toEqual(200)
@@ -235,7 +238,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart", cart_id: "test-cart",
unit_price: 1000, unit_price: 1000,
@@ -244,6 +249,7 @@ describe("/store/carts", () => {
adjustments: [], adjustments: [],
}), }),
]) ])
)
}) })
it("adds line item to cart containing a total fixed discount", async () => { it("adds line item to cart containing a total fixed discount", async () => {
@@ -260,7 +266,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart-w-total-fixed-discount", cart_id: "test-cart-w-total-fixed-discount",
unit_price: 1000, unit_price: 1000,
@@ -275,6 +283,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
it("adds line item to cart containing a total percentage discount", async () => { it("adds line item to cart containing a total percentage discount", async () => {
@@ -291,7 +300,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart-w-total-percentage-discount", cart_id: "test-cart-w-total-percentage-discount",
unit_price: 1000, unit_price: 1000,
@@ -306,6 +317,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
it("adds line item to cart containing an item fixed discount", async () => { it("adds line item to cart containing an item fixed discount", async () => {
@@ -322,7 +334,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart-w-item-fixed-discount", cart_id: "test-cart-w-item-fixed-discount",
unit_price: 1000, unit_price: 1000,
@@ -337,6 +351,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
it("adds line item to cart containing an item percentage discount", async () => { it("adds line item to cart containing an item percentage discount", async () => {
@@ -353,7 +368,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart-w-item-percentage-discount", cart_id: "test-cart-w-item-percentage-discount",
unit_price: 1000, unit_price: 1000,
@@ -368,6 +385,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
it("adds line item to cart time limited sale", async () => { it("adds line item to cart time limited sale", async () => {
@@ -384,7 +402,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart", cart_id: "test-cart",
unit_price: 800, unit_price: 800,
@@ -392,6 +412,7 @@ describe("/store/carts", () => {
quantity: 1, quantity: 1,
}), }),
]) ])
)
}) })
it("adds line item to cart time customer pricing", async () => { it("adds line item to cart time customer pricing", async () => {
@@ -422,7 +443,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart", cart_id: "test-cart",
unit_price: 700, unit_price: 700,
@@ -430,6 +453,7 @@ describe("/store/carts", () => {
quantity: 1, quantity: 1,
}), }),
]) ])
)
}) })
it("adds line item with quantity to cart with quantity discount", async () => { it("adds line item with quantity to cart with quantity discount", async () => {
@@ -446,7 +470,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart", cart_id: "test-cart",
unit_price: 800, unit_price: 800,
@@ -454,6 +480,7 @@ describe("/store/carts", () => {
quantity: 90, quantity: 90,
}), }),
]) ])
)
}) })
it("adds line item with quantity to cart with quantity discount no ceiling", async () => { it("adds line item with quantity to cart with quantity discount no ceiling", async () => {
@@ -470,7 +497,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart", cart_id: "test-cart",
unit_price: 700, unit_price: 700,
@@ -478,6 +507,7 @@ describe("/store/carts", () => {
quantity: 900, quantity: 900,
}), }),
]) ])
)
}) })
describe("ensures correct line item adjustment generation", () => { describe("ensures correct line item adjustment generation", () => {
@@ -682,7 +712,8 @@ describe("/store/carts", () => {
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items.length).toEqual(1) expect(response.data.cart.items.length).toEqual(1)
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
adjustments: [ adjustments: [
expect.objectContaining({ expect.objectContaining({
@@ -693,6 +724,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
}) })
}) })
@@ -761,7 +793,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart-w-total-fixed-discount", cart_id: "test-cart-w-total-fixed-discount",
unit_price: 1000, unit_price: 1000,
@@ -776,6 +810,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
it("updates line item of a cart containing a total percentage discount", async () => { it("updates line item of a cart containing a total percentage discount", async () => {
@@ -801,7 +836,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart-w-total-percentage-discount", cart_id: "test-cart-w-total-percentage-discount",
unit_price: 1000, unit_price: 1000,
@@ -816,6 +853,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
it("updates line item of a cart containing an item fixed discount", async () => { it("updates line item of a cart containing an item fixed discount", async () => {
@@ -841,7 +879,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart-w-item-fixed-discount", cart_id: "test-cart-w-item-fixed-discount",
unit_price: 1000, unit_price: 1000,
@@ -856,6 +896,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
it("updates line item of a cart containing an item percentage discount", async () => { it("updates line item of a cart containing an item percentage discount", async () => {
@@ -881,7 +922,9 @@ describe("/store/carts", () => {
) )
.catch((err) => console.log(err)) .catch((err) => console.log(err))
expect(response.data.cart.items).toEqual([ expect(response.data.cart.items).toHaveLength(1)
expect(response.data.cart.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
cart_id: "test-cart-w-item-percentage-discount", cart_id: "test-cart-w-item-percentage-discount",
unit_price: 1000, unit_price: 1000,
@@ -896,6 +939,7 @@ describe("/store/carts", () => {
], ],
}), }),
]) ])
)
}) })
}) })
@@ -55,12 +55,15 @@ describe("/store/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_2", id: "test-product_filtering_2",
collection_id: "test-collection2", collection_id: "test-collection2",
}), }),
]) ])
)
for (const notExpect of notExpected) { for (const notExpect of notExpected) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -81,12 +84,15 @@ describe("/store/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_1", id: "test-product_filtering_1",
collection_id: "test-collection1", collection_id: "test-collection1",
}), }),
]) ])
)
for (const notExpect of notExpected) { for (const notExpect of notExpected) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -106,12 +112,14 @@ describe("/store/products", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products.length).toEqual(1) expect(response.data.products.length).toEqual(1)
expect(response.data.products).toEqual([ expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "giftcard", id: "giftcard",
is_giftcard: true, is_giftcard: true,
}), }),
]) ])
)
}) })
it("returns non gift card products", async () => { it("returns non gift card products", async () => {
@@ -144,12 +152,15 @@ describe("/store/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_1", id: "test-product_filtering_1",
collection_id: "test-collection1", collection_id: "test-collection1",
}), }),
]) ])
)
for (const notExpect of notExpected) { for (const notExpect of notExpected) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -172,12 +183,15 @@ describe("/store/products", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(1)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product_filtering_2", id: "test-product_filtering_2",
handle: "test-product_filtering_2", handle: "test-product_filtering_2",
}), }),
]) ])
)
for (const notExpect of notExpected) { for (const notExpect of notExpected) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -201,7 +215,8 @@ describe("/store/products", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.products.length).toEqual(5) expect(response.data.products.length).toEqual(5)
expect(response.data.products).toEqual([ expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product1", id: "test-product1",
collection_id: "test-collection", collection_id: "test-collection",
@@ -222,6 +237,7 @@ describe("/store/products", () => {
id: "giftcard", id: "giftcard",
}), }),
]) ])
)
for (const notExpect of notExpected) { for (const notExpect of notExpected) {
expect(response.data.products).toEqual( expect(response.data.products).toEqual(
@@ -256,7 +272,9 @@ describe("/store/products", () => {
console.log(err) console.log(err)
}) })
expect(response.data.products).toEqual([ expect(response.data.products).toHaveLength(5)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: "test-product1", id: "test-product1",
collection_id: "test-collection", collection_id: "test-collection",
@@ -327,6 +345,7 @@ describe("/store/products", () => {
id: "giftcard", id: "giftcard",
}), }),
]) ])
)
}) })
}) })
@@ -118,7 +118,9 @@ describe("/store/return-reasons", () => {
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.return_reasons).toEqual([ expect(response.data.return_reasons).toHaveLength(2)
expect(response.data.return_reasons).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: rrId, id: rrId,
value: "wrong_size", value: "wrong_size",
@@ -134,6 +136,7 @@ describe("/store/return-reasons", () => {
value: "too_big_1", value: "too_big_1",
}), }),
]) ])
)
}) })
}) })
}) })
@@ -241,12 +241,15 @@ describe("/store/carts", () => {
}) })
expect(response.status).toEqual(200) expect(response.status).toEqual(200)
expect(response.data.return.items).toEqual([ expect(response.data.return.items).toHaveLength(1)
expect(response.data.return.items).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
reason_id: rrId_child, reason_id: rrId_child,
note: "TOO small", note: "TOO small",
}), }),
]) ])
)
}) })
it("failes to create a return with an invalid quantity (less than 1)", async () => { it("failes to create a return with an invalid quantity (less than 1)", async () => {
@@ -290,16 +290,22 @@ describe("Order Taxes", () => {
response.data.data.items.flatMap((li) => li.tax_lines).length response.data.data.items.flatMap((li) => li.tax_lines).length
).toEqual(2) ).toEqual(2)
expect(response.data.data.items[0].tax_lines).toEqual([ expect(response.data.data.items[0].tax_lines).toHaveLength(1)
expect(response.data.data.items[0].tax_lines).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
rate: 25, rate: 25,
}), }),
]) ])
expect(response.data.data.items[1].tax_lines).toEqual([ )
expect(response.data.data.items[1].tax_lines).toHaveLength(1)
expect(response.data.data.items[1].tax_lines).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
rate: 20, rate: 20,
}), }),
]) ])
)
}) })
test("completing cart creates tax lines", async () => { test("completing cart creates tax lines", async () => {
@@ -381,15 +387,21 @@ describe("Order Taxes", () => {
expect(response.data.data.tax_total).toEqual(35) expect(response.data.data.tax_total).toEqual(35)
expect(response.data.data.total).toEqual(185) expect(response.data.data.total).toEqual(185)
expect(response.data.data.items[0].tax_lines).toEqual([ expect(response.data.data.items[0].tax_lines).toHaveLength(1)
expect(response.data.data.items[0].tax_lines).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
rate: 25, rate: 25,
}), }),
]) ])
expect(response.data.data.items[1].tax_lines).toEqual([ )
expect(response.data.data.items[1].tax_lines).toHaveLength(1)
expect(response.data.data.items[1].tax_lines).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
rate: 20, rate: 20,
}), }),
]) ])
)
}) })
}) })
@@ -69,13 +69,16 @@ describe("Shipping Options Totals Calculations", () => {
}, },
}) })
expect(res.data.shipping_options).toEqual([ expect(res.data.shipping_options).toHaveLength(1)
expect(res.data.shipping_options).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: so.id, id: so.id,
amount: 100, amount: 100,
price_incl_tax: 110, price_incl_tax: 110,
}), }),
]) ])
)
}) })
it("gets correct shipping prices", async () => { it("gets correct shipping prices", async () => {
@@ -98,12 +101,15 @@ describe("Shipping Options Totals Calculations", () => {
const res = await api.get(`/store/shipping-options?region_id=${region.id}`) const res = await api.get(`/store/shipping-options?region_id=${region.id}`)
expect(res.data.shipping_options).toEqual([ expect(res.data.shipping_options).toHaveLength(1)
expect(res.data.shipping_options).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
id: so.id, id: so.id,
amount: 100, amount: 100,
price_incl_tax: 110, price_incl_tax: 110,
}), }),
]) ])
)
}) })
}) })
@@ -93,13 +93,16 @@ describe("Order Totals", () => {
headers: { Authorization: `Bearer test_token` }, headers: { Authorization: `Bearer test_token` },
}) })
expect(data.order.gift_card_transactions).toEqual([ expect(data.order.gift_card_transactions).toHaveLength(1)
expect(data.order.gift_card_transactions).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
amount: 160000, amount: 160000,
is_taxable: false, is_taxable: false,
tax_rate: null, tax_rate: null,
}), }),
]) ])
)
expect(data.order.gift_card_total).toEqual(160000) expect(data.order.gift_card_total).toEqual(160000)
expect(data.order.gift_card_tax_total).toEqual(0) expect(data.order.gift_card_tax_total).toEqual(0)
expect(data.order.total).toEqual(59000) expect(data.order.total).toEqual(59000)
@@ -155,13 +158,16 @@ describe("Order Totals", () => {
headers: { Authorization: `Bearer test_token` }, headers: { Authorization: `Bearer test_token` },
}) })
expect(data.order.gift_card_transactions).toEqual([ expect(data.order.gift_card_transactions).toHaveLength(1)
expect(data.order.gift_card_transactions).toEqual(
expect.arrayContaining([
expect.objectContaining({ expect.objectContaining({
amount: 160000, amount: 160000,
is_taxable: true, is_taxable: true,
tax_rate: 25, tax_rate: 25,
}), }),
]) ])
)
expect(data.order.gift_card_total).toEqual(160000) expect(data.order.gift_card_total).toEqual(160000)
expect(data.order.gift_card_tax_total).toEqual(40000) expect(data.order.gift_card_tax_total).toEqual(40000)
expect(data.order.tax_total).toEqual(3800) expect(data.order.tax_total).toEqual(3800)