Validate channels only when it has no variants (#4095)
* Validate channels only when it has no variants * Add test
This commit is contained in:
parent
4a66b5f625
commit
8a12d5496f
2 changed files with 27 additions and 3 deletions
|
@ -28,10 +28,12 @@ describe("validateProductCreateData", () => {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns errors when there is no prices for channels", () => {
|
it("returns errors when there is no prices for channels in simple product", () => {
|
||||||
// Arrange
|
// Arrange
|
||||||
const data = {
|
const data = {
|
||||||
productType: "something",
|
productType: {
|
||||||
|
hasVariants: false,
|
||||||
|
},
|
||||||
name: "something",
|
name: "something",
|
||||||
channelListings: [
|
channelListings: [
|
||||||
{ id: "chann-1", price: "" },
|
{ id: "chann-1", price: "" },
|
||||||
|
@ -60,4 +62,24 @@ describe("validateProductCreateData", () => {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("returns errors when there is no prices for channels in product with variants", () => {
|
||||||
|
// Arrange
|
||||||
|
const data = {
|
||||||
|
productType: {
|
||||||
|
hasVariants: true,
|
||||||
|
},
|
||||||
|
name: "something",
|
||||||
|
channelListings: [
|
||||||
|
{ id: "chann-1", price: "" },
|
||||||
|
{ id: "chann-2", price: "" },
|
||||||
|
],
|
||||||
|
} as unknown as ProductCreateData;
|
||||||
|
|
||||||
|
// Act
|
||||||
|
const errors = validateProductCreateData(data);
|
||||||
|
|
||||||
|
// Assert
|
||||||
|
expect(errors).toEqual([]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -34,7 +34,9 @@ export const validateProductCreateData = (data: ProductCreateData) => {
|
||||||
errors = [...errors, createEmptyRequiredError("name")];
|
errors = [...errors, createEmptyRequiredError("name")];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (data.channelListings) {
|
const { productType, channelListings } = data;
|
||||||
|
|
||||||
|
if (!productType.hasVariants && channelListings) {
|
||||||
const emptyPrices = data.channelListings
|
const emptyPrices = data.channelListings
|
||||||
.filter(channel => channel.price?.length === 0)
|
.filter(channel => channel.price?.length === 0)
|
||||||
.map(({ id }) => createEmptyRequiredError(`${id}-channel-price`));
|
.map(({ id }) => createEmptyRequiredError(`${id}-channel-price`));
|
||||||
|
|
Loading…
Reference in a new issue