Skip to content

Commit

Permalink
use-locations-metafields
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalsoueidan committed May 19, 2024
1 parent 2dbab4c commit 415db39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
22 changes: 12 additions & 10 deletions src/functions/customer/controllers/product/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -134,14 +143,7 @@ describe("CustomerProductControllerAdd", () => {
descriptionHtml: "<b>test</b>",
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",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions src/functions/customer/services/product/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ describe("CustomerProductServiceAdd", () => {
},
locations: {
id: "gid://shopify/Metafield/44429081411911",
value: "{}",
value: "[]",
},
bookingPeriodValue: {
id: "gid://shopify/Metafield/44429081313607",
Expand Down Expand Up @@ -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!,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/functions/customer/services/product/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
},
]
: []),
Expand Down

0 comments on commit 415db39

Please sign in to comment.