feat(medusa): Ordering products on retrieval (#2815)

**What**

Move to transformQuery which adds a default ordering and also allows to order the product list from the store API

**How**
Among other things, fix the product repo to allow ordering by either a key from the product or a key from a relation

FIXES CORE-911
FIXES CORE-901
This commit is contained in:
Adrien de Peretti
2022-12-22 11:33:53 +01:00
committed by GitHub
parent 5ae319004f
commit 463f83ffdd
17 changed files with 1080 additions and 1927 deletions

View File

@@ -1,450 +0,0 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/store/products /store/products/:id includes default relations 1`] = `
Object {
"product": Object {
"collection": Object {
"created_at": Any<String>,
"deleted_at": null,
"handle": "test-collection",
"id": "test-collection",
"metadata": null,
"title": "Test collection",
"updated_at": Any<String>,
},
"collection_id": "test-collection",
"created_at": Any<String>,
"deleted_at": null,
"description": "test-product-description",
"discountable": true,
"external_id": null,
"handle": "test-product",
"height": null,
"hs_code": null,
"id": "test-product",
"images": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-image",
"metadata": null,
"updated_at": Any<String>,
"url": "test-image.png",
},
],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-option",
"metadata": null,
"product_id": "test-product",
"title": "test-option",
"updated_at": Any<String>,
"values": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-variant-option",
"metadata": null,
"option_id": "test-option",
"updated_at": Any<String>,
"value": "Default variant",
"variant_id": "test-variant",
},
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-variant-option-1",
"metadata": null,
"option_id": "test-option",
"updated_at": Any<String>,
"value": "Default variant 1",
"variant_id": "test-variant_1",
},
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-variant-option-2",
"metadata": null,
"option_id": "test-option",
"updated_at": Any<String>,
"value": "Default variant 2",
"variant_id": "test-variant_2",
},
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-variant-option-3",
"metadata": null,
"option_id": "test-option",
"updated_at": Any<String>,
"value": "Default variant 3",
"variant_id": "test-variant_3",
},
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-variant-option-4",
"metadata": null,
"option_id": "test-option",
"updated_at": Any<String>,
"value": "Default variant 4",
"variant_id": "test-variant_4",
},
],
},
],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "published",
"subtitle": null,
"tags": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "tag1",
"metadata": null,
"updated_at": Any<String>,
"value": "123",
},
],
"thumbnail": null,
"title": "Test product",
"type": Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-type",
"metadata": null,
"updated_at": Any<String>,
"value": "test-type",
},
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Array [
Object {
"allow_backorder": false,
"barcode": "test-barcode",
"calculated_price": null,
"calculated_price_incl_tax": null,
"calculated_tax": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean",
"height": null,
"hs_code": null,
"id": "test-variant",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-variant-option",
"metadata": null,
"option_id": "test-option",
"updated_at": Any<String>,
"value": "Default variant",
"variant_id": "test-variant",
},
],
"origin_country": null,
"original_price": null,
"original_price_incl_tax": null,
"original_tax": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "test-price",
"max_quantity": null,
"min_quantity": null,
"price_list": null,
"price_list_id": null,
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant",
},
Object {
"amount": 80,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "test-price-discount",
"max_quantity": null,
"min_quantity": null,
"price_list": Object {
"created_at": Any<String>,
"deleted_at": null,
"description": "Winter sale for VIP customers.",
"ends_at": null,
"id": "pl",
"name": "VIP winter sale",
"starts_at": null,
"status": "active",
"type": "sale",
"updated_at": Any<String>,
},
"price_list_id": "pl",
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant",
},
],
"product_id": "test-product",
"sku": "test-sku",
"tax_rates": null,
"title": "Test variant",
"upc": "test-upc",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": null,
"calculated_price": null,
"calculated_price_incl_tax": null,
"calculated_tax": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean2",
"height": null,
"hs_code": null,
"id": "test-variant_2",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-variant-option-2",
"metadata": null,
"option_id": "test-option",
"updated_at": Any<String>,
"value": "Default variant 2",
"variant_id": "test-variant_2",
},
],
"origin_country": null,
"original_price": null,
"original_price_incl_tax": null,
"original_tax": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "test-price2",
"max_quantity": null,
"min_quantity": null,
"price_list": null,
"price_list_id": null,
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant_2",
},
Object {
"amount": 80,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "test-price2-discount",
"max_quantity": null,
"min_quantity": null,
"price_list": Object {
"created_at": Any<String>,
"deleted_at": null,
"description": "Winter sale for VIP customers.",
"ends_at": null,
"id": "pl",
"name": "VIP winter sale",
"starts_at": null,
"status": "active",
"type": "sale",
"updated_at": Any<String>,
},
"price_list_id": "pl",
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant_2",
},
],
"product_id": "test-product",
"sku": "test-sku2",
"tax_rates": null,
"title": "Test variant rank (2)",
"upc": "test-upc2",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": "test-barcode 1",
"calculated_price": null,
"calculated_price_incl_tax": null,
"calculated_tax": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean1",
"height": null,
"hs_code": null,
"id": "test-variant_1",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": "test-variant-option-1",
"metadata": null,
"option_id": "test-option",
"updated_at": Any<String>,
"value": "Default variant 1",
"variant_id": "test-variant_1",
},
],
"origin_country": null,
"original_price": null,
"original_price_incl_tax": null,
"original_tax": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "test-price1",
"max_quantity": null,
"min_quantity": null,
"price_list": null,
"price_list_id": null,
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant_1",
},
Object {
"amount": 80,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "test-price1-discount",
"max_quantity": null,
"min_quantity": null,
"price_list": Object {
"created_at": Any<String>,
"deleted_at": null,
"description": "Winter sale for VIP customers.",
"ends_at": null,
"id": "pl",
"name": "VIP winter sale",
"starts_at": null,
"status": "active",
"type": "sale",
"updated_at": Any<String>,
},
"price_list_id": "pl",
"region_id": null,
"updated_at": Any<String>,
"variant_id": "test-variant_1",
},
],
"product_id": "test-product",
"sku": "test-sku1",
"tax_rates": null,
"title": "Test variant rank (1)",
"upc": "test-upc1",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
],
"weight": null,
"width": null,
},
}
`;
exports[`/store/products list params works with expand and fields 1`] = `
Object {
"count": 2,
"limit": 1,
"offset": 0,
"products": Array [
Object {
"id": Any<String>,
"title": "testprod",
"variants": Array [
Object {
"allow_backorder": false,
"barcode": null,
"calculated_price": null,
"calculated_price_incl_tax": null,
"calculated_tax": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": null,
"height": null,
"hs_code": null,
"id": Any<String>,
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"origin_country": null,
"original_price": null,
"original_price_incl_tax": null,
"original_tax": null,
"prices": Array [
Object {
"amount": 100,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": Any<String>,
"max_quantity": null,
"min_quantity": null,
"price_list": null,
"price_list_id": null,
"region_id": null,
"updated_at": Any<String>,
"variant_id": Any<String>,
},
],
"product_id": Any<String>,
"sku": null,
"tax_rates": null,
"title": "test-variant",
"upc": null,
"updated_at": Any<String>,
"weight": null,
"width": null,
},
],
},
],
}
`;

View File

@@ -6,12 +6,19 @@ const { initDb, useDb } = require("../../../helpers/use-db")
const { simpleProductFactory } = require("../../factories")
const productSeeder = require("../../helpers/store-product-seeder")
const adminSeeder = require("../../helpers/admin-seeder")
jest.setTimeout(30000)
describe("/store/products", () => {
let medusaProcess
let dbConnection
const giftCardId = "giftcard"
const testProductId = "test-product"
const testProductId1 = "test-product1"
const testProductFilteringId1 = "test-product_filtering_1"
const testProductFilteringId2 = "test-product_filtering_2"
beforeAll(async () => {
const cwd = path.resolve(path.join(__dirname, "..", ".."))
dbConnection = await initDb({ cwd })
@@ -35,6 +42,190 @@ describe("/store/products", () => {
await db.teardown()
})
it("returns a list of ordered products by id ASC", async () => {
const api = useApi()
const response = await api.get("/store/products?order=id")
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(5)
expect(response.data.products[0].id).toEqual(giftCardId)
expect(response.data.products[1].id).toEqual(testProductId)
expect(response.data.products[2].id).toEqual(testProductId1)
expect(response.data.products[3].id).toEqual(testProductFilteringId1)
expect(response.data.products[4].id).toEqual(testProductFilteringId2)
})
it("returns a list of ordered products by id DESC", async () => {
const api = useApi()
const response = await api.get("/store/products?order=-id")
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(5)
expect(response.data.products[0].id).toEqual(testProductFilteringId2)
expect(response.data.products[1].id).toEqual(testProductFilteringId1)
expect(response.data.products[2].id).toEqual(testProductId1)
expect(response.data.products[3].id).toEqual(testProductId)
expect(response.data.products[4].id).toEqual(giftCardId)
})
it("returns a list of ordered products by variants title DESC", async () => {
const api = useApi()
const response = await api.get("/store/products?order=-variants.title")
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(5)
const testProductIndex = response.data.products.indexOf(
response.data.products.find((p) => p.id === testProductId)
)
const testProduct1Index = response.data.products.indexOf(
response.data.products.find((p) => p.id === testProductId1)
)
expect(testProductIndex).toBe(3)
expect(testProduct1Index).toBe(4)
})
it("returns a list of ordered products by variants title ASC", async () => {
const api = useApi()
const response = await api.get("/store/products?order=variants.title")
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(5)
const testProductIndex = response.data.products.indexOf(
response.data.products.find((p) => p.id === testProductId)
)
const testProduct1Index = response.data.products.indexOf(
response.data.products.find((p) => p.id === testProductId1)
)
expect(testProductIndex).toBe(0)
expect(testProduct1Index).toBe(1)
})
it("returns a list of ordered products by variants prices DESC", async () => {
const api = useApi()
await simpleProductFactory(dbConnection, {
id: "test-product2",
status: "published",
variants: [
{
id: "test_variant_5",
prices: [
{
currency: "usd",
amount: 200,
},
],
},
],
})
const response = await api.get(
"/store/products?order=-variants.prices.amount"
)
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(6)
const testProductIndex = response.data.products.indexOf(
response.data.products.find((p) => p.id === testProductId)
)
const testProduct1Index = response.data.products.indexOf(
response.data.products.find((p) => p.id === testProductId1)
)
const testProduct2Index = response.data.products.indexOf(
response.data.products.find((p) => p.id === "test-product2")
)
expect(testProduct2Index).toBe(3) // 200
expect(testProductIndex).toBe(4) // 100
expect(testProduct1Index).toBe(5) // 100
})
it("returns a list of ordered products by variants prices ASC", async () => {
const api = useApi()
await simpleProductFactory(dbConnection, {
id: "test-product2",
status: "published",
variants: [
{
id: "test_variant_5",
prices: [
{
currency: "usd",
amount: 200,
},
],
},
],
})
const response = await api.get(
"/store/products?order=variants.prices.amount"
)
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(6)
const testProductIndex = response.data.products.indexOf(
response.data.products.find((p) => p.id === testProductId)
)
const testProduct1Index = response.data.products.indexOf(
response.data.products.find((p) => p.id === testProductId1)
)
const testProduct2Index = response.data.products.indexOf(
response.data.products.find((p) => p.id === "test-product2")
)
expect(testProductIndex).toBe(0) // 100
expect(testProduct1Index).toBe(1) // 100
expect(testProduct2Index).toBe(2) // 200
})
it("returns a list of ordered products by id ASC and filtered with free text search", async () => {
const api = useApi()
const response = await api.get("/store/products?q=filtering&order=id")
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(2)
expect(response.data.products).toEqual([
expect.objectContaining({
id: testProductFilteringId1,
}),
expect.objectContaining({
id: testProductFilteringId2,
}),
])
})
it("returns a list of ordered products by id DESC and filtered with free text search", async () => {
const api = useApi()
const response = await api.get("/store/products?q=filtering&order=-id")
expect(response.status).toEqual(200)
expect(response.data.products).toHaveLength(2)
expect(response.data.products).toEqual([
expect.objectContaining({
id: testProductFilteringId2,
}),
expect.objectContaining({
id: testProductFilteringId1,
}),
])
})
it("returns a list of products in collection", async () => {
const api = useApi()
@@ -54,7 +245,7 @@ describe("/store/products", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product_filtering_2",
id: testProductFilteringId2,
collection_id: "test-collection2",
}),
])
@@ -67,7 +258,7 @@ describe("/store/products", () => {
}
})
it("returns a list of products in with a given tag", async () => {
it("returns a list of products with a given tag", async () => {
const api = useApi()
const notExpected = [expect.objectContaining({ id: "tag4" })]
@@ -83,7 +274,7 @@ describe("/store/products", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product_filtering_1",
id: testProductFilteringId1,
collection_id: "test-collection1",
}),
])
@@ -110,7 +301,7 @@ describe("/store/products", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "giftcard",
id: giftCardId,
is_giftcard: true,
}),
])
@@ -151,7 +342,7 @@ describe("/store/products", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product_filtering_1",
id: testProductFilteringId1,
collection_id: "test-collection1",
}),
])
@@ -168,7 +359,7 @@ describe("/store/products", () => {
const api = useApi()
const notExpected = [
expect.objectContaining({ handle: "test-product_filtering_1" }),
expect.objectContaining({ handle: testProductFilteringId1 }),
]
const response = await api
@@ -182,8 +373,8 @@ describe("/store/products", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product_filtering_2",
handle: "test-product_filtering_2",
id: testProductFilteringId2,
handle: testProductFilteringId2,
}),
])
)
@@ -231,23 +422,23 @@ describe("/store/products", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product1",
id: testProductId1,
collection_id: "test-collection",
}),
expect.objectContaining({
id: "test-product",
id: testProductId,
collection_id: "test-collection",
}),
expect.objectContaining({
id: "test-product_filtering_2",
id: testProductFilteringId2,
collection_id: "test-collection2",
}),
expect.objectContaining({
id: "test-product_filtering_1",
id: testProductFilteringId1,
collection_id: "test-collection1",
}),
expect.objectContaining({
id: "giftcard",
id: giftCardId,
}),
])
)
@@ -284,11 +475,11 @@ describe("/store/products", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product1",
id: testProductId1,
collection_id: "test-collection",
}),
expect.objectContaining({
id: "test-product",
id: testProductId,
collection_id: "test-collection",
variants: [
expect.objectContaining({
@@ -307,22 +498,6 @@ describe("/store/products", () => {
}),
],
}),
expect.objectContaining({
original_price: 100,
calculated_price: 80,
prices: [
expect.objectContaining({
id: "test-price2",
currency_code: "usd",
amount: 100,
}),
expect.objectContaining({
id: "test-price2-discount",
currency_code: "usd",
amount: 80,
}),
],
}),
expect.objectContaining({
original_price: 100,
calculated_price: 80,
@@ -339,18 +514,34 @@ describe("/store/products", () => {
}),
],
}),
expect.objectContaining({
original_price: 100,
calculated_price: 80,
prices: [
expect.objectContaining({
id: "test-price2",
currency_code: "usd",
amount: 100,
}),
expect.objectContaining({
id: "test-price2-discount",
currency_code: "usd",
amount: 80,
}),
],
}),
],
}),
expect.objectContaining({
id: "test-product_filtering_2",
id: testProductFilteringId2,
collection_id: "test-collection2",
}),
expect.objectContaining({
id: "test-product_filtering_1",
id: testProductFilteringId1,
collection_id: "test-collection1",
}),
expect.objectContaining({
id: "giftcard",
id: giftCardId,
}),
])
)
@@ -394,29 +585,31 @@ describe("/store/products", () => {
"/store/products?expand=variants,variants.prices&fields=id,title&limit=1"
)
expect(response.data).toMatchSnapshot({
products: [
{
id: expect.any(String),
variants: [
{
created_at: expect.any(String),
updated_at: expect.any(String),
id: expect.any(String),
product_id: expect.any(String),
prices: [
{
created_at: expect.any(String),
updated_at: expect.any(String),
id: expect.any(String),
variant_id: expect.any(String),
},
],
},
],
},
],
})
expect(response.data).toEqual(
expect.objectContaining({
products: expect.arrayContaining([
expect.objectContaining({
id: expect.any(String),
variants: expect.arrayContaining([
expect.objectContaining({
created_at: expect.any(String),
updated_at: expect.any(String),
id: expect.any(String),
product_id: expect.any(String),
prices: expect.arrayContaining([
expect.objectContaining({
created_at: expect.any(String),
updated_at: expect.any(String),
id: expect.any(String),
variant_id: expect.any(String),
}),
]),
}),
]),
}),
]),
})
)
})
})
@@ -436,284 +629,286 @@ describe("/store/products", () => {
const response = await api.get("/store/products/test-product")
expect(response.data).toMatchSnapshot({
product: {
id: "test-product",
variants: [
{
id: "test-variant",
inventory_quantity: 10,
allow_backorder: false,
title: "Test variant",
sku: "test-sku",
ean: "test-ean",
upc: "test-upc",
length: null,
manage_inventory: true,
material: null,
metadata: null,
mid_code: null,
height: null,
hs_code: null,
origin_country: null,
calculated_price: null,
original_price: null,
barcode: "test-barcode",
product_id: "test-product",
created_at: expect.any(String),
updated_at: expect.any(String),
options: [
{
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
prices: [
{
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 100,
currency_code: "usd",
deleted_at: null,
min_quantity: null,
max_quantity: null,
price_list_id: null,
id: "test-price",
region_id: null,
variant_id: "test-variant",
},
{
id: "test-price-discount",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 80,
currency_code: "usd",
price_list_id: "pl",
deleted_at: null,
region_id: null,
variant_id: "test-variant",
price_list: {
id: "pl",
type: "sale",
expect(response.data).toEqual(
expect.objectContaining({
product: expect.objectContaining({
id: testProductId,
variants: expect.arrayContaining([
expect.objectContaining({
id: "test-variant",
inventory_quantity: 10,
allow_backorder: false,
title: "Test variant",
sku: "test-sku",
ean: "test-ean",
upc: "test-upc",
length: null,
manage_inventory: true,
material: null,
metadata: null,
mid_code: null,
height: null,
hs_code: null,
origin_country: null,
calculated_price: null,
original_price: null,
barcode: "test-barcode",
product_id: testProductId,
created_at: expect.any(String),
updated_at: expect.any(String),
options: expect.arrayContaining([
expect.objectContaining({
created_at: expect.any(String),
updated_at: expect.any(String),
},
},
],
},
{
id: "test-variant_2",
inventory_quantity: 10,
allow_backorder: false,
title: "Test variant rank (2)",
sku: "test-sku2",
ean: "test-ean2",
upc: "test-upc2",
length: null,
manage_inventory: true,
material: null,
metadata: null,
mid_code: null,
height: null,
hs_code: null,
origin_country: null,
barcode: null,
calculated_price: null,
original_price: null,
product_id: "test-product",
created_at: expect.any(String),
updated_at: expect.any(String),
options: [
{
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
prices: [
{
id: "test-price2",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 100,
currency_code: "usd",
price_list_id: null,
deleted_at: null,
region_id: null,
variant_id: "test-variant_2",
},
{
id: "test-price2-discount",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 80,
currency_code: "usd",
price_list_id: "pl",
deleted_at: null,
region_id: null,
variant_id: "test-variant_2",
price_list: {
id: "pl",
type: "sale",
}),
]),
prices: expect.arrayContaining([
expect.objectContaining({
created_at: expect.any(String),
updated_at: expect.any(String),
},
},
],
},
{
id: "test-variant_1",
inventory_quantity: 10,
allow_backorder: false,
title: "Test variant rank (1)",
sku: "test-sku1",
ean: "test-ean1",
upc: "test-upc1",
length: null,
manage_inventory: true,
material: null,
metadata: null,
mid_code: null,
height: null,
hs_code: null,
origin_country: null,
calculated_price: null,
original_price: null,
barcode: "test-barcode 1",
product_id: "test-product",
created_at: expect.any(String),
updated_at: expect.any(String),
options: [
{
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
prices: [
{
id: "test-price1",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 100,
currency_code: "usd",
min_quantity: null,
max_quantity: null,
price_list_id: null,
deleted_at: null,
region_id: null,
variant_id: "test-variant_1",
},
{
id: "test-price1-discount",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 80,
currency_code: "usd",
price_list_id: "pl",
deleted_at: null,
region_id: null,
variant_id: "test-variant_1",
price_list: {
id: "pl",
type: "sale",
amount: 100,
currency_code: "usd",
deleted_at: null,
min_quantity: null,
max_quantity: null,
price_list_id: null,
id: "test-price",
region_id: null,
variant_id: "test-variant",
}),
expect.objectContaining({
id: "test-price-discount",
created_at: expect.any(String),
updated_at: expect.any(String),
},
},
],
},
],
images: [
{
id: "test-image",
amount: 80,
currency_code: "usd",
price_list_id: "pl",
deleted_at: null,
region_id: null,
variant_id: "test-variant",
price_list: expect.objectContaining({
id: "pl",
type: "sale",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
}),
]),
}),
expect.objectContaining({
id: "test-variant_2",
inventory_quantity: 10,
allow_backorder: false,
title: "Test variant rank (2)",
sku: "test-sku2",
ean: "test-ean2",
upc: "test-upc2",
length: null,
manage_inventory: true,
material: null,
metadata: null,
mid_code: null,
height: null,
hs_code: null,
origin_country: null,
barcode: null,
calculated_price: null,
original_price: null,
product_id: testProductId,
created_at: expect.any(String),
updated_at: expect.any(String),
options: expect.arrayContaining([
expect.objectContaining({
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
prices: expect.arrayContaining([
expect.objectContaining({
id: "test-price2",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 100,
currency_code: "usd",
price_list_id: null,
deleted_at: null,
region_id: null,
variant_id: "test-variant_2",
}),
expect.objectContaining({
id: "test-price2-discount",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 80,
currency_code: "usd",
price_list_id: "pl",
deleted_at: null,
region_id: null,
variant_id: "test-variant_2",
price_list: expect.objectContaining({
id: "pl",
type: "sale",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
}),
]),
}),
expect.objectContaining({
id: "test-variant_1",
inventory_quantity: 10,
allow_backorder: false,
title: "Test variant rank (1)",
sku: "test-sku1",
ean: "test-ean1",
upc: "test-upc1",
length: null,
manage_inventory: true,
material: null,
metadata: null,
mid_code: null,
height: null,
hs_code: null,
origin_country: null,
calculated_price: null,
original_price: null,
barcode: "test-barcode 1",
product_id: testProductId,
created_at: expect.any(String),
updated_at: expect.any(String),
options: expect.arrayContaining([
expect.objectContaining({
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
prices: expect.arrayContaining([
expect.objectContaining({
id: "test-price1",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 100,
currency_code: "usd",
min_quantity: null,
max_quantity: null,
price_list_id: null,
deleted_at: null,
region_id: null,
variant_id: "test-variant_1",
}),
expect.objectContaining({
id: "test-price1-discount",
created_at: expect.any(String),
updated_at: expect.any(String),
amount: 80,
currency_code: "usd",
price_list_id: "pl",
deleted_at: null,
region_id: null,
variant_id: "test-variant_1",
price_list: expect.objectContaining({
id: "pl",
type: "sale",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
}),
]),
}),
]),
images: expect.arrayContaining([
expect.objectContaining({
id: "test-image",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
handle: testProductId,
title: "Test product",
profile_id: expect.stringMatching(/^sp_*/),
description: "test-product-description",
collection_id: "test-collection",
collection: expect.objectContaining({
id: "test-collection",
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
handle: "test-product",
title: "Test product",
profile_id: expect.stringMatching(/^sp_*/),
description: "test-product-description",
collection_id: "test-collection",
collection: {
id: "test-collection",
}),
type: expect.objectContaining({
id: "test-type",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
tags: expect.arrayContaining([
expect.objectContaining({
id: "tag1",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
options: expect.arrayContaining([
expect.objectContaining({
id: "test-option",
values: expect.arrayContaining([
expect.objectContaining({
id: "test-variant-option",
value: "Default variant",
option_id: "test-option",
variant_id: "test-variant",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: "test-variant-option-1",
value: "Default variant 1",
option_id: "test-option",
variant_id: "test-variant_1",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: "test-variant-option-2",
value: "Default variant 2",
option_id: "test-option",
variant_id: "test-variant_2",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: "test-variant-option-3",
value: "Default variant 3",
option_id: "test-option",
variant_id: "test-variant_3",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: "test-variant-option-4",
value: "Default variant 4",
option_id: "test-option",
variant_id: "test-variant_4",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
created_at: expect.any(String),
updated_at: expect.any(String),
},
type: {
id: "test-type",
created_at: expect.any(String),
updated_at: expect.any(String),
},
tags: [
{
id: "tag1",
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: "test-option",
values: [
{
id: "test-variant-option",
value: "Default variant",
option_id: "test-option",
variant_id: "test-variant",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
},
{
id: "test-variant-option-1",
value: "Default variant 1",
option_id: "test-option",
variant_id: "test-variant_1",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
},
{
id: "test-variant-option-2",
value: "Default variant 2",
option_id: "test-option",
variant_id: "test-variant_2",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
},
{
id: "test-variant-option-3",
value: "Default variant 3",
option_id: "test-option",
variant_id: "test-variant_3",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
},
{
id: "test-variant-option-4",
value: "Default variant 4",
option_id: "test-option",
variant_id: "test-variant_4",
metadata: null,
deleted_at: null,
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
created_at: expect.any(String),
updated_at: expect.any(String),
},
})
}),
})
)
})
it("lists all published products", async () => {
@@ -742,7 +937,7 @@ describe("/store/products", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product",
id: testProductId,
status: "published",
}),
])