From e82737a03545f69a833d8329f52daef39cfca46d Mon Sep 17 00:00:00 2001 From: Sebastian Rindom Date: Wed, 3 Nov 2021 13:15:36 +0100 Subject: [PATCH] fix: adds options to default relations in storefront product endpoints (#712) --- .../store/__snapshots__/products.js.snap | 36 +++++++++++++++++++ .../api/__tests__/store/products.js | 29 +++++++++------ .../src/api/routes/store/products/index.js | 1 + 3 files changed, 55 insertions(+), 11 deletions(-) diff --git a/integration-tests/api/__tests__/store/__snapshots__/products.js.snap b/integration-tests/api/__tests__/store/__snapshots__/products.js.snap index 781d540f96..9639111c59 100644 --- a/integration-tests/api/__tests__/store/__snapshots__/products.js.snap +++ b/integration-tests/api/__tests__/store/__snapshots__/products.js.snap @@ -141,6 +141,18 @@ Object { "material": null, "metadata": null, "mid_code": null, + "options": Array [ + Object { + "created_at": Any, + "deleted_at": null, + "id": "test-variant-option", + "metadata": null, + "option_id": "test-option", + "updated_at": Any, + "value": "Default variant", + "variant_id": "test-variant", + }, + ], "origin_country": null, "prices": Array [ Object { @@ -178,6 +190,18 @@ Object { "material": null, "metadata": null, "mid_code": null, + "options": Array [ + Object { + "created_at": Any, + "deleted_at": null, + "id": "test-variant-option-2", + "metadata": null, + "option_id": "test-option", + "updated_at": Any, + "value": "Default variant 2", + "variant_id": "test-variant_2", + }, + ], "origin_country": null, "prices": Array [ Object { @@ -215,6 +239,18 @@ Object { "material": null, "metadata": null, "mid_code": null, + "options": Array [ + Object { + "created_at": Any, + "deleted_at": null, + "id": "test-variant-option-1", + "metadata": null, + "option_id": "test-option", + "updated_at": Any, + "value": "Default variant 1", + "variant_id": "test-variant_1", + }, + ], "origin_country": null, "prices": Array [ Object { diff --git a/integration-tests/api/__tests__/store/products.js b/integration-tests/api/__tests__/store/products.js index 22f35079d4..718709972a 100644 --- a/integration-tests/api/__tests__/store/products.js +++ b/integration-tests/api/__tests__/store/products.js @@ -68,6 +68,12 @@ describe("/store/products", () => { 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-money-amount", @@ -105,6 +111,12 @@ describe("/store/products", () => { 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-money-amount", @@ -117,7 +129,6 @@ describe("/store/products", () => { id: "test-price2", region_id: null, sale_amount: null, - updated_at: expect.any(String), variant_id: "test-variant_2", }, ], @@ -142,6 +153,12 @@ describe("/store/products", () => { 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-money-amount", @@ -254,16 +271,6 @@ describe("/store/products", () => { }) }) - it("Fetching variant options without additional relation fails", async () => { - const api = useApi() - - const response = await api.get("/store/products/test-product") - - const product = response.data.product - - expect(product.variants.some((variant) => variant.options)).toEqual(false) - }) - it("lists all published products", async () => { const api = useApi() diff --git a/packages/medusa/src/api/routes/store/products/index.js b/packages/medusa/src/api/routes/store/products/index.js index fb0ba76fa5..164202d0bb 100644 --- a/packages/medusa/src/api/routes/store/products/index.js +++ b/packages/medusa/src/api/routes/store/products/index.js @@ -16,6 +16,7 @@ export default (app) => { export const defaultRelations = [ "variants", "variants.prices", + "variants.options", "options", "options.values", "images",