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,598 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`/admin/products GET /admin/products returns a list of products with child entities 1`] = `
Array [
Object {
"collection": Object {
"created_at": Any<String>,
"deleted_at": null,
"handle": "test-collection",
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"title": "Test collection",
"updated_at": Any<String>,
},
"collection_id": "test-collection",
"created_at": Any<String>,
"deleted_at": null,
"description": "test-product-description",
"discountable": true,
"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": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"url": "test-image.png",
},
],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"product_id": StringMatching /\\^test-\\*/,
"title": "test-option",
"updated_at": Any<String>,
},
],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"tags": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^tag\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "123",
},
],
"thumbnail": null,
"title": "Test product",
"type": Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "test-type",
},
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Array [
Object {
"allow_backorder": false,
"barcode": "test-barcode",
"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": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"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": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"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": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 2",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"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": StringMatching /\\^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_2",
},
],
"product_id": StringMatching /\\^test-\\*/,
"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": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 1",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"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": StringMatching /\\^test-price\\*/,
"max_quantity": null,
"min_quantity": null,
"price_list": null,
"price_list_id": null,
"region_id": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku1",
"tax_rates": null,
"title": "Test variant rank (1)",
"upc": "test-upc1",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
Object {
"allow_backorder": false,
"barcode": "test-barcode-sale",
"calculated_price": null,
"calculated_price_incl_tax": null,
"calculated_tax": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean-sale",
"height": null,
"hs_code": null,
"id": "test-variant-sale",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"original_price": null,
"original_price_incl_tax": null,
"original_tax": null,
"prices": Array [
Object {
"amount": 1000,
"created_at": Any<String>,
"currency_code": "usd",
"deleted_at": null,
"id": "test-price-sale",
"max_quantity": null,
"min_quantity": null,
"price_list": null,
"price_list_id": null,
"region_id": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku-sale",
"tax_rates": null,
"title": "Test variant",
"upc": "test-upc-sale",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
],
"weight": null,
"width": null,
},
Object {
"collection": Object {
"created_at": Any<String>,
"deleted_at": null,
"handle": "test-collection",
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"title": "Test collection",
"updated_at": Any<String>,
},
"collection_id": "test-collection",
"created_at": Any<String>,
"deleted_at": null,
"description": "test-product-description1",
"discountable": true,
"external_id": null,
"handle": "test-product1",
"height": null,
"hs_code": null,
"id": "test-product1",
"images": Array [],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [],
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"tags": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^tag\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "123",
},
],
"thumbnail": null,
"title": "Test product1",
"type": Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-\\*/,
"metadata": null,
"updated_at": Any<String>,
"value": "test-type",
},
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Array [
Object {
"allow_backorder": false,
"barcode": null,
"calculated_price": null,
"calculated_price_incl_tax": null,
"calculated_tax": null,
"created_at": Any<String>,
"deleted_at": null,
"ean": "test-ean4",
"height": null,
"hs_code": null,
"id": "test-variant_4",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 4",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"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": StringMatching /\\^test-price\\*/,
"max_quantity": null,
"min_quantity": null,
"price_list": null,
"price_list_id": null,
"region_id": null,
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku4",
"tax_rates": null,
"title": "Test variant rank (2)",
"upc": "test-upc4",
"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-ean3",
"height": null,
"hs_code": null,
"id": "test-variant_3",
"inventory_quantity": 10,
"length": null,
"manage_inventory": true,
"material": null,
"metadata": null,
"mid_code": null,
"options": Array [
Object {
"created_at": Any<String>,
"deleted_at": null,
"id": StringMatching /\\^test-variant-option\\*/,
"metadata": null,
"option_id": StringMatching /\\^test-opt\\*/,
"updated_at": Any<String>,
"value": "Default variant 3",
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"origin_country": null,
"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": StringMatching /\\^test-price\\*/,
"max_quantity": null,
"min_quantity": null,
"price_list": null,
"price_list_id": null,
"region_id": "test-region",
"updated_at": Any<String>,
"variant_id": StringMatching /\\^test-variant\\*/,
},
],
"product_id": StringMatching /\\^test-\\*/,
"sku": "test-sku3",
"tax_rates": null,
"title": "Test variant rank (2)",
"upc": "test-upc3",
"updated_at": Any<String>,
"weight": null,
"width": null,
},
],
"weight": null,
"width": null,
},
Object {
"collection": Any<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",
"images": Array [],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Any<Array>,
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "proposed",
"subtitle": null,
"tags": Any<Array>,
"thumbnail": null,
"title": "Test product filtering 1",
"type": Any<Object>,
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Any<Array>,
"weight": null,
"width": null,
},
Object {
"collection": Any<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",
"images": Array [],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Any<Array>,
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "published",
"subtitle": null,
"tags": Any<Array>,
"thumbnail": null,
"title": "Test product filtering 2",
"type": Any<Object>,
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Any<Array>,
"weight": null,
"width": null,
},
Object {
"collection": Any<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",
"images": Array [],
"is_giftcard": false,
"length": null,
"material": null,
"metadata": null,
"mid_code": null,
"options": Any<Array>,
"origin_country": null,
"profile_id": StringMatching /\\^sp_\\*/,
"status": "draft",
"subtitle": null,
"tags": Any<Array>,
"thumbnail": null,
"title": "Test product filtering 3",
"type": Any<Object>,
"type_id": "test-type",
"updated_at": Any<String>,
"variants": Any<Array>,
"weight": null,
"width": null,
},
]
`;
exports[`/admin/products GET /admin/products returns a list of products with only giftcard in list 1`] = `
Array [
Object {

View File

@@ -88,11 +88,7 @@ describe("/admin/price-lists", () => {
}
const response = await api
.post("/admin/price-lists", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.post("/admin/price-lists", payload, adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -147,11 +143,7 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get("/admin/price-lists/pl_no_customer_groups", {
headers: {
Authorization: "Bearer test_token",
},
})
.get("/admin/price-lists/pl_no_customer_groups", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -209,11 +201,7 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get("/admin/price-lists", {
headers: {
Authorization: "Bearer test_token",
},
})
.get("/admin/price-lists", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -232,11 +220,7 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get("/admin/price-lists?q=winter", {
headers: {
Authorization: "Bearer test_token",
},
})
.get("/admin/price-lists?q=winter", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -256,11 +240,7 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get("/admin/price-lists?q=25%", {
headers: {
Authorization: "Bearer test_token",
},
})
.get("/admin/price-lists?q=25%", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -282,11 +262,7 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get("/admin/price-lists?q=blablabla", {
headers: {
Authorization: "Bearer test_token",
},
})
.get("/admin/price-lists?q=blablabla", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -300,11 +276,7 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get("/admin/price-lists?q=vip&status[]=draft", {
headers: {
Authorization: "Bearer test_token",
},
})
.get("/admin/price-lists?q=vip&status[]=draft", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -318,11 +290,7 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get("/admin/price-lists?q=vip&status[]=active", {
headers: {
Authorization: "Bearer test_token",
},
})
.get("/admin/price-lists?q=vip&status[]=active", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -363,11 +331,7 @@ describe("/admin/price-lists", () => {
const response = await api
.get(
`/admin/price-lists?customer_groups[]=customer-group-1,customer-group-2`,
{
headers: {
Authorization: "Bearer test_token",
},
}
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
@@ -406,11 +370,10 @@ describe("/admin/price-lists", () => {
})
const api = useApi()
const getResult = await api.get(`/admin/price-lists/${priceList.id}`, {
headers: {
Authorization: "Bearer test_token",
},
})
const getResult = await api.get(
`/admin/price-lists/${priceList.id}`,
adminReqConfig
)
expect(getResult.status).toEqual(200)
expect(getResult.data.price_list.starts_at).toBeTruthy()
@@ -420,11 +383,7 @@ describe("/admin/price-lists", () => {
const updateResult = await api.post(
`/admin/price-lists/${priceList.id}`,
{ ends_at: null, starts_at: null, customer_groups: [] },
{
headers: {
Authorization: "Bearer test_token",
},
}
adminReqConfig
)
expect(updateResult.status).toEqual(200)
@@ -463,11 +422,11 @@ describe("/admin/price-lists", () => {
}
const response = await api
.post("/admin/price-lists/pl_no_customer_groups", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.post(
"/admin/price-lists/pl_no_customer_groups",
payload,
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
})
@@ -575,11 +534,11 @@ describe("/admin/price-lists", () => {
}
const response = await api
.post("/admin/price-lists/pl_no_customer_groups", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.post(
"/admin/price-lists/pl_no_customer_groups",
payload,
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
})
@@ -626,11 +585,7 @@ describe("/admin/price-lists", () => {
}
const response = await api
.post("/admin/price-lists/pl_with_some_ma", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.post("/admin/price-lists/pl_with_some_ma", payload, adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -714,11 +669,7 @@ describe("/admin/price-lists", () => {
.post(
"/admin/price-lists/pl_no_customer_groups/prices/batch",
payload,
{
headers: {
Authorization: "Bearer test_token",
},
}
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
@@ -832,11 +783,7 @@ describe("/admin/price-lists", () => {
.post(
"/admin/price-lists/pl_no_customer_groups/prices/batch",
payload,
{
headers: {
Authorization: "Bearer test_token",
},
}
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
@@ -900,11 +847,11 @@ describe("/admin/price-lists", () => {
}
const response = await api
.post("/admin/price-lists/pl_with_some_ma/prices/batch", payload, {
headers: {
Authorization: "Bearer test_token",
},
})
.post(
"/admin/price-lists/pl_with_some_ma/prices/batch",
payload,
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
})
@@ -970,11 +917,7 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.delete("/admin/price-lists/pl_no_customer_groups", {
headers: {
Authorization: "Bearer test_token",
},
})
.delete("/admin/price-lists/pl_no_customer_groups", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -987,11 +930,10 @@ describe("/admin/price-lists", () => {
})
try {
await api.get("/admin/price-lists/pl_no_customer_groups", {
headers: {
Authorization: "Bearer test_token",
},
})
await api.get(
"/admin/price-lists/pl_no_customer_groups",
adminReqConfig
)
} catch (error) {
expect(error.response.status).toBe(404)
expect(error.response.data.message).toEqual(
@@ -1017,22 +959,17 @@ describe("/admin/price-lists", () => {
const api = useApi()
await api
.delete("/admin/products/test-product/variants/test-variant", {
headers: {
Authorization: "Bearer test_token",
},
})
.delete(
"/admin/products/test-product/variants/test-variant",
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
})
const response = await api.get(
"/admin/price-lists/pl_no_customer_groups",
{
headers: {
Authorization: "Bearer test_token",
},
}
adminReqConfig
)
expect(response.status).toEqual(200)
@@ -1057,9 +994,7 @@ describe("/admin/price-lists", () => {
const response = await api
.delete("/admin/price-lists/pl_no_customer_groups/prices/batch", {
headers: {
Authorization: "Bearer test_token",
},
...adminReqConfig,
data: {
price_ids: ["ma_test_1", "ma_test_2"],
},
@@ -1069,11 +1004,7 @@ describe("/admin/price-lists", () => {
})
const getPriceListResponse = await api
.get("/admin/price-lists/pl_no_customer_groups", {
headers: {
Authorization: "Bearer test_token",
},
})
.get("/admin/price-lists/pl_no_customer_groups", adminReqConfig)
.catch((err) => {
console.warn(err.response.data)
})
@@ -1166,11 +1097,10 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get(`/admin/price-lists/test-list/products?order=-created_at`, {
headers: {
Authorization: "Bearer test_token",
},
})
.get(
`/admin/price-lists/test-list/products?order=-created_at`,
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
})
@@ -1179,28 +1109,6 @@ describe("/admin/price-lists", () => {
expect(response.data.count).toEqual(2)
expect(response.data.products).toHaveLength(2)
expect(response.data.products).toEqual([
expect.objectContaining({
id: "test-prod-1",
variants: expect.arrayContaining([
expect.objectContaining({
id: "test-variant-1",
prices: expect.arrayContaining([
expect.objectContaining({ currency_code: "usd", amount: 100 }),
expect.objectContaining({
currency_code: "usd",
amount: 150,
price_list_id: "test-list",
}),
]),
}),
expect.objectContaining({
id: "test-variant-2",
prices: expect.arrayContaining([
expect.objectContaining({ currency_code: "usd", amount: 100 }),
]),
}),
]),
}),
expect.objectContaining({
id: "test-prod-2",
variants: expect.arrayContaining([
@@ -1223,6 +1131,28 @@ describe("/admin/price-lists", () => {
}),
]),
}),
expect.objectContaining({
id: "test-prod-1",
variants: expect.arrayContaining([
expect.objectContaining({
id: "test-variant-1",
prices: expect.arrayContaining([
expect.objectContaining({ currency_code: "usd", amount: 100 }),
expect.objectContaining({
currency_code: "usd",
amount: 150,
price_list_id: "test-list",
}),
]),
}),
expect.objectContaining({
id: "test-variant-2",
prices: expect.arrayContaining([
expect.objectContaining({ currency_code: "usd", amount: 100 }),
]),
}),
]),
}),
])
})
@@ -1230,11 +1160,10 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get(`/admin/price-lists/test-list/products?tags[]=${tag}`, {
headers: {
Authorization: "Bearer test_token",
},
})
.get(
`/admin/price-lists/test-list/products?tags[]=${tag}`,
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
})
@@ -1251,11 +1180,10 @@ describe("/admin/price-lists", () => {
const api = useApi()
const response = await api
.get(`/admin/price-lists/test-list/products?q=Headphones`, {
headers: {
Authorization: "Bearer test_token",
},
})
.get(
`/admin/price-lists/test-list/products?q=Headphones`,
adminReqConfig
)
.catch((err) => {
console.warn(err.response.data)
})
@@ -1343,22 +1271,14 @@ describe("/admin/price-lists", () => {
it("should delete all the prices that are part of the price list for the specified product", async () => {
const api = useApi()
response = await api.get("/admin/price-lists/test-list", {
headers: {
Authorization: "Bearer test_token",
},
})
response = await api.get("/admin/price-lists/test-list", adminReqConfig)
expect(response.status).toBe(200)
expect(response.data.price_list.prices.length).toBe(3)
let response = await api.delete(
`/admin/price-lists/test-list/products/${product1.id}/prices`,
{
headers: {
Authorization: "Bearer test_token",
},
}
adminReqConfig
)
expect(response.status).toBe(200)
@@ -1370,11 +1290,7 @@ describe("/admin/price-lists", () => {
deleted: true,
})
response = await api.get("/admin/price-lists/test-list", {
headers: {
Authorization: "Bearer test_token",
},
})
response = await api.get("/admin/price-lists/test-list", adminReqConfig)
expect(response.status).toBe(200)
expect(response.data.price_list.prices.length).toBe(1)
@@ -1383,11 +1299,7 @@ describe("/admin/price-lists", () => {
it("should delete all the prices that are part of the price list for the specified variant", async () => {
const api = useApi()
response = await api.get("/admin/price-lists/test-list", {
headers: {
Authorization: "Bearer test_token",
},
})
response = await api.get("/admin/price-lists/test-list", adminReqConfig)
expect(response.status).toBe(200)
expect(response.data.price_list.prices.length).toBe(3)
@@ -1395,11 +1307,7 @@ describe("/admin/price-lists", () => {
const variant = product2.variants[0]
let response = await api.delete(
`/admin/price-lists/test-list/variants/${variant.id}/prices`,
{
headers: {
Authorization: "Bearer test_token",
},
}
adminReqConfig
)
expect(response.status).toBe(200)
@@ -1409,11 +1317,7 @@ describe("/admin/price-lists", () => {
deleted: true,
})
response = await api.get("/admin/price-lists/test-list", {
headers: {
Authorization: "Bearer test_token",
},
})
response = await api.get("/admin/price-lists/test-list", adminReqConfig)
expect(response.status).toBe(200)
expect(response.data.price_list.prices.length).toBe(2)

View File

@@ -647,254 +647,253 @@ describe("/admin/products", () => {
const api = useApi()
const response = await api
.get("/admin/products", adminHeaders)
.get("/admin/products?order=created_at", adminHeaders)
.catch((err) => {
console.log(err)
})
response.data.products.sort((a, b) =>
a.created_at > b.created_at ? 1 : -1
expect(response.data.products).toHaveLength(5)
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: "test-product",
options: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-*/),
product_id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
images: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
variants: expect.arrayContaining([
expect.objectContaining({
id: "test-variant",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: expect.arrayContaining([
expect.objectContaining({
id: "test-price",
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
options: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
}),
expect.objectContaining({
id: "test-variant_2",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-price*/),
variant_id: "test-variant_2",
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
options: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
}),
expect.objectContaining({
id: "test-variant_1",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
options: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
}),
expect.objectContaining({
id: "test-variant-sale",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: expect.arrayContaining([
expect.objectContaining({
id: "test-price-sale",
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
options: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
}),
]),
tags: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^tag*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
type: expect.objectContaining({
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
collection: expect.objectContaining({
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: "test-product1",
created_at: expect.any(String),
options: [],
variants: expect.arrayContaining([
expect.objectContaining({
id: "test-variant_4",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
options: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
}),
expect.objectContaining({
id: "test-variant_3",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
options: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
}),
]),
tags: expect.arrayContaining([
expect.objectContaining({
id: expect.stringMatching(/^tag*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
]),
type: expect.objectContaining({
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
collection: expect.objectContaining({
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
}),
profile_id: expect.stringMatching(/^sp_*/),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: "test-product_filtering_1",
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
type: expect.any(Object),
collection: expect.any(Object),
options: expect.any(Array),
tags: expect.any(Array),
variants: expect.any(Array),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: "test-product_filtering_2",
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
type: expect.any(Object),
collection: expect.any(Object),
options: expect.any(Array),
tags: expect.any(Array),
variants: expect.any(Array),
updated_at: expect.any(String),
}),
expect.objectContaining({
id: "test-product_filtering_3",
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
type: expect.any(Object),
collection: expect.any(Object),
options: expect.any(Array),
tags: expect.any(Array),
variants: expect.any(Array),
updated_at: expect.any(String),
}),
])
)
expect(response.data.products).toMatchSnapshot([
{
id: "test-product",
options: [
{
id: expect.stringMatching(/^test-*/),
product_id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
images: [
{
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
variants: [
{
id: "test-variant",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: "test-price",
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
{
id: "test-variant_2",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: "test-variant_2",
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
{
id: "test-variant_1",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
{
id: "test-variant-sale",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: "test-price-sale",
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
],
tags: [
{
id: expect.stringMatching(/^tag*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
type: {
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
collection: {
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
{
id: "test-product1",
created_at: expect.any(String),
options: [],
variants: [
{
id: "test-variant_4",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
{
id: "test-variant_3",
created_at: expect.any(String),
updated_at: expect.any(String),
product_id: expect.stringMatching(/^test-*/),
prices: [
{
id: expect.stringMatching(/^test-price*/),
variant_id: expect.stringMatching(/^test-variant*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
options: [
{
id: expect.stringMatching(/^test-variant-option*/),
variant_id: expect.stringMatching(/^test-variant*/),
option_id: expect.stringMatching(/^test-opt*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
},
],
tags: [
{
id: expect.stringMatching(/^tag*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
],
type: {
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
collection: {
id: expect.stringMatching(/^test-*/),
created_at: expect.any(String),
updated_at: expect.any(String),
},
profile_id: expect.stringMatching(/^sp_*/),
updated_at: expect.any(String),
},
{
id: "test-product_filtering_1",
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
type: expect.any(Object),
collection: expect.any(Object),
options: expect.any(Array),
tags: expect.any(Array),
variants: expect.any(Array),
updated_at: expect.any(String),
},
{
id: "test-product_filtering_2",
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
type: expect.any(Object),
collection: expect.any(Object),
options: expect.any(Array),
tags: expect.any(Array),
variants: expect.any(Array),
updated_at: expect.any(String),
},
{
id: "test-product_filtering_3",
profile_id: expect.stringMatching(/^sp_*/),
created_at: expect.any(String),
type: expect.any(Object),
collection: expect.any(Object),
options: expect.any(Array),
tags: expect.any(Array),
variants: expect.any(Array),
updated_at: expect.any(String),
},
])
})
})
@@ -1800,11 +1799,11 @@ describe("/admin/products", () => {
expect(response.status).toEqual(200)
expect(response.data.product.variants[1].prices.length).toEqual(
expect(response.data.product.variants[0].prices.length).toEqual(
data.prices.length
)
expect(response.data.product.variants[1].prices).toEqual(
expect(response.data.product.variants[0].prices).toEqual(
expect.arrayContaining([
expect.objectContaining({
amount: 8000,

View File

@@ -647,10 +647,10 @@ describe("[MEDUSA_FF_PUBLISHABLE_API_KEYS] Publishable API keys", () => {
expect(response.data.products).toEqual(
expect.arrayContaining([
expect.objectContaining({
id: product1.id,
id: product2.id,
}),
expect.objectContaining({
id: product2.id,
id: product1.id,
}),
])
)