From 415db39f4c789ccf4247e83857e92a0f6ee7462d Mon Sep 17 00:00:00 2001 From: Jamal Soueidan Date: Sun, 19 May 2024 16:29:07 +0200 Subject: [PATCH] use-locations-metafields --- .../customer/controllers/product/add.spec.ts | 22 ++++++++++--------- .../customer/services/product/add.spec.ts | 10 ++++++--- .../customer/services/product/update.ts | 2 +- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/functions/customer/controllers/product/add.spec.ts b/src/functions/customer/controllers/product/add.spec.ts index efb531b2..3aaef64c 100644 --- a/src/functions/customer/controllers/product/add.spec.ts +++ b/src/functions/customer/controllers/product/add.spec.ts @@ -126,6 +126,15 @@ describe("CustomerProductControllerAdd", () => { customerId, }); + const locations = [ + { + metafieldId: "1", + location: new mongoose.Types.ObjectId(), + locationType: LocationTypes.DESTINATION, + originType: LocationOriginTypes.COMMERCIAL, + }, + ]; + const body: CustomerProductControllerAddRequest["body"] = { hideFromCombine: false, hideFromProfile: true, @@ -134,14 +143,7 @@ describe("CustomerProductControllerAdd", () => { descriptionHtml: "test", scheduleId: newSchedule._id, parentId: 1, - locations: [ - { - metafieldId: "1", - location: new mongoose.Types.ObjectId(), - locationType: LocationTypes.DESTINATION, - originType: LocationOriginTypes.COMMERCIAL, - }, - ], + locations, price: { amount: "100", currencyCode: "DKK", @@ -204,7 +206,7 @@ describe("CustomerProductControllerAdd", () => { }, locations: { id: mockProduct.productDuplicate?.newProduct?.locations?.id!, - value: '{"locations":[]}', + value: JSON.stringify(locations.map((l) => l.metafieldId)), }, bookingPeriodValue: { id: mockProduct.productDuplicate?.newProduct?.bookingPeriodValue @@ -325,7 +327,7 @@ describe("CustomerProductControllerAdd", () => { }, { id: mockProductUpdate.productUpdate?.product?.locations?.id, - value: JSON.stringify(body.locations), + value: JSON.stringify(locations.map((l) => l.metafieldId)), }, { id: mockProductUpdate.productUpdate?.product?.user?.id, diff --git a/src/functions/customer/services/product/add.spec.ts b/src/functions/customer/services/product/add.spec.ts index 823f8d05..374241a8 100644 --- a/src/functions/customer/services/product/add.spec.ts +++ b/src/functions/customer/services/product/add.spec.ts @@ -107,7 +107,7 @@ describe("CustomerProductServiceAdd", () => { }, locations: { id: "gid://shopify/Metafield/44429081411911", - value: "{}", + value: "[]", }, bookingPeriodValue: { id: "gid://shopify/Metafield/44429081313607", @@ -195,7 +195,9 @@ describe("CustomerProductServiceAdd", () => { }, locations: { id: mockProduct.productDuplicate?.newProduct?.locations?.id!, - value: '{"locations":[]}', + value: JSON.stringify( + productBody.locations.map((l) => l.metafieldId) + ), }, user: { id: mockProduct.productDuplicate?.newProduct?.user?.id!, @@ -330,7 +332,9 @@ describe("CustomerProductServiceAdd", () => { }, { id: mockProductUpdate.productUpdate?.product?.locations?.id, - value: JSON.stringify(productBody.locations), + value: JSON.stringify( + productBody.locations.map((l) => l.metafieldId) + ), }, { id: mockProductUpdate.productUpdate?.product?.user?.id, diff --git a/src/functions/customer/services/product/update.ts b/src/functions/customer/services/product/update.ts index ee517098..1940429e 100644 --- a/src/functions/customer/services/product/update.ts +++ b/src/functions/customer/services/product/update.ts @@ -120,7 +120,7 @@ export const CustomerProductServiceUpdate = async ( ? [ { id: oldProduct?.locationsMetafieldId, - value: JSON.stringify(body.locations), + value: JSON.stringify(body.locations.map((p) => p.metafieldId)), }, ] : []),