Skip to content

Commit

Permalink
feat: Add variant SKU field to SaleorProviderFieldsMapping
Browse files Browse the repository at this point in the history
  • Loading branch information
peelar committed Jul 24, 2024
1 parent 57f7aa0 commit 8d6d7bd
Show file tree
Hide file tree
Showing 14 changed files with 30 additions and 6 deletions.
2 changes: 2 additions & 0 deletions apps/cms-v2/src/modules/configuration/app-config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const getMockContentfulInput = (): ContentfulProviderConfig.InputShape => {
productSlug: "productSlug",
variantId: "variantId",
variantName: "variantName",
variantSku: "variantSku",
},
spaceId: "test",
};
Expand All @@ -34,6 +35,7 @@ const getMockDatocmsInput = (): DatocmsProviderConfig.InputShape => {
productSlug: "productSlug",
variantId: "variantId",
variantName: "variantName",
variantSku: "variantSku",
},
};
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,8 @@ export const printSaleorProductFields = (fieldName: SaleorProviderFieldsMappingK
case "variantId": {
return "Variant ID";
}
case "variantSku": {
return "Variant SKU";
}
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { z } from "zod";
export const SaleorProviderFieldsMappingSchema = z.object({
variantId: z.string().min(1),
variantName: z.string().min(1),
variantSku: z.string().min(1),
productId: z.string().min(1),
productName: z.string().min(1),
productSlug: z.string().min(1),
Expand All @@ -22,4 +23,5 @@ export const SaleorProviderFieldsMappingKeys: Array<SaleorProviderFieldsMappingK
"productName",
"productSlug",
"channels",
"variantSku",
];
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ const AddFormVariant = () => {
productName: "",
productSlug: "",
variantId: "",
variantSku: "",
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@ const getMockContenfulConfiguration = (): ContentfulProviderConfig.FullShape =>
productSlug: "product-slug",
variantId: "variant-id",
variantName: "variant-name",
variantSku: "variant-sku",
},
});

const getMockWebhookProductVariant = (): WebhookProductVariantFragment => {
return {
id: "test-id",
name: "test-name",
sku: "test-sku",
product: {
id: "test-product-id",
name: "test-product-name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@ const AddVariant = () => {
productName: "",
productSlug: "",
variantId: "",
variantSku: "",
},
spaceId: "",
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,15 @@ const getMockContenfulConfiguration = (): ContentfulProviderConfig.FullShape =>
productSlug: "product-slug",
variantId: "variant-id",
variantName: "variant-name",
variantSku: "variant-sku",
},
});

const getMockWebhookProductVariant = (): WebhookProductVariantFragment => {
return {
id: "test-id",
name: "test-name",
sku: "test-sku",
product: {
id: "test-product-id",
name: "test-product-name",
Expand Down Expand Up @@ -61,7 +63,7 @@ describe("ContentfulWebhooksProcessor", () => {

processor = new ContentfulWebhooksProcessor(
getMockContenfulConfiguration(),
() => mockContentfulClient
() => mockContentfulClient,
);
});

Expand All @@ -74,7 +76,7 @@ describe("ContentfulWebhooksProcessor", () => {
expect.objectContaining({
configuration: getMockContenfulConfiguration(),
variant: mockProductVariant,
})
}),
);
});

Expand All @@ -87,7 +89,7 @@ describe("ContentfulWebhooksProcessor", () => {
expect.objectContaining({
configuration: getMockContenfulConfiguration(),
variant: mockProductVariant,
})
}),
);
});

Expand All @@ -100,7 +102,7 @@ describe("ContentfulWebhooksProcessor", () => {
expect.objectContaining({
configuration: getMockContenfulConfiguration(),
variant: mockProductVariant,
})
}),
);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ const AddFormVariant = () => {
productName: "",
productSlug: "",
variantId: "",
variantSku: "",
},
}}
/>
Expand Down
3 changes: 3 additions & 0 deletions apps/cms-v2/src/modules/providers/fields-mapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ describe("FieldsMapper", () => {
productSlug: "product-slug",
variantId: "variant-id",
variantName: "variant-name",
variantSku: "variant-sku",
},
variant: {
id: "aaa-bbb-ccc",
name: "43",
sku: "sku",
channelListings: [
{
channel: {
Expand All @@ -37,6 +39,7 @@ describe("FieldsMapper", () => {
"product-name": "Shoes",
"product-slug": "shoes",
"variant-id": "aaa-bbb-ccc",
"variant-sku": "sku",
channels: [
{
channel: {
Expand Down
4 changes: 3 additions & 1 deletion apps/cms-v2/src/modules/providers/fields-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ export class FieldsMapper {
variant: WebhookProductVariantFragment;
configMapping: ProvidersConfig.AnyFullShape["productVariantFieldsMapping"];
}) {
const { channels, variantName, productId, productName, productSlug, variantId } = configMapping;
const { channels, variantName, productId, productName, productSlug, variantId, variantSku } =
configMapping;

return {
[variantName]: variant.name,
Expand All @@ -18,6 +19,7 @@ export class FieldsMapper {
[productSlug]: variant.product.slug,
[variantId]: variant.id,
[channels]: variant.channelListings,
[variantSku]: variant.sku,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ const AddFormVariant = () => {
productName: "",
productSlug: "",
variantId: "",
variantSku: "",
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ const AddFormVariant = () => {
productName: "",
productSlug: "",
variantId: "",
variantSku: "",
},
}}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const getMockContentfulInput = (): ContentfulProviderConfig.InputShape => {
productSlug: "productSlug",
variantId: "variantId",
variantName: "variantName",
variantSku: "variantSku",
},
spaceId: "test",
};
Expand All @@ -36,6 +37,7 @@ const getMockDatocmsInput = (): DatocmsProviderConfig.InputShape => {
productSlug: "productSlug",
variantId: "variantId",
variantName: "variantName",
variantSku: "variantSku",
},
};
};
Expand Down Expand Up @@ -81,6 +83,7 @@ const getMockProductVariantWebhookFragment = (): WebhookProductVariantFragment =
return {
id: "variant-id",
name: "variant-name",
sku: "variant-sku",
product: {
id: "product-id",
name: "product-name",
Expand Down
2 changes: 1 addition & 1 deletion apps/cms-v2/src/pages/api/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const handler = createManifestHandler({
*/
],
homepageUrl: "https://github.com/saleor/apps",
id: "saleor.app.cms2",
id: "saleor.app.cms4",
name: "CMS",
permissions: ["MANAGE_PRODUCTS"],
requiredSaleorVersion: ">=3.10 <4",
Expand Down

0 comments on commit 8d6d7bd

Please sign in to comment.