Adds ProductVariantService
This commit is contained in:
1 parent
4ba63ccc0d
commit
8c0f6107a0
12 files changed
+777
-177
No files matched your search
@@ -0,0 +1,33 @@
|
||||
import IdMap from "../../helpers/id-map"
|
||||
|
||||
export const ProductVariantModelMock = {
|
||||
create: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
updateOne: jest.fn().mockImplementation((query, update) => {
|
||||
return Promise.resolve()
|
||||
}),
|
||||
deleteOne: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
findOne: jest.fn().mockImplementation(query => {
|
||||
if (query._id === IdMap.getId("validId")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("validId"),
|
||||
title: "test",
|
||||
})
|
||||
}
|
||||
if (query._id === IdMap.getId("testVariant")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("testVariant"),
|
||||
title: "test",
|
||||
})
|
||||
}
|
||||
if (query._id === IdMap.getId("deleteId")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("deleteId"),
|
||||
title: "test",
|
||||
})
|
||||
}
|
||||
if (query._id === IdMap.getId("failId")) {
|
||||
return Promise.reject(new Error("test error"))
|
||||
}
|
||||
return Promise.resolve(undefined)
|
||||
}),
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
import IdMap from "../../helpers/id-map"
|
||||
|
||||
export const ProductModelMock = {
|
||||
create: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
updateOne: jest.fn().mockImplementation((query, update) => {
|
||||
if (query._id === IdMap.getId("productWithVariantsFail")) {
|
||||
return Promise.reject()
|
||||
}
|
||||
return Promise.resolve()
|
||||
}),
|
||||
deleteOne: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
findOne: jest.fn().mockImplementation(query => {
|
||||
if (query._id === IdMap.getId("productWithFourVariants")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("productWithFourVariants"),
|
||||
title: "Product With Variants",
|
||||
variants: ["1", "2", "3", "4"],
|
||||
options: [
|
||||
{
|
||||
_id: IdMap.getId("color_id"),
|
||||
title: "Color",
|
||||
},
|
||||
{
|
||||
_id: IdMap.getId("size_id"),
|
||||
title: "Size",
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
if (query._id === IdMap.getId("productWithVariantsFail")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("productWithVariantsFail"),
|
||||
title: "Product With Variants",
|
||||
variants: ["1", "3", "4"],
|
||||
options: [
|
||||
{
|
||||
_id: IdMap.getId("color_id"),
|
||||
title: "Color",
|
||||
},
|
||||
{
|
||||
_id: IdMap.getId("size_id"),
|
||||
title: "Size",
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
if (query._id === IdMap.getId("productWithVariants")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("productWithVariants"),
|
||||
title: "Product With Variants",
|
||||
variants: ["1", "3", "4"],
|
||||
options: [
|
||||
{
|
||||
_id: IdMap.getId("color_id"),
|
||||
title: "Color",
|
||||
},
|
||||
{
|
||||
_id: IdMap.getId("size_id"),
|
||||
title: "Size",
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
if (query._id === IdMap.getId("variantProductId")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("variantProductId"),
|
||||
title: "testtitle",
|
||||
options: [
|
||||
{
|
||||
_id: IdMap.getId("color_id"),
|
||||
title: "Color",
|
||||
},
|
||||
{
|
||||
_id: IdMap.getId("size_id"),
|
||||
title: "Size",
|
||||
},
|
||||
],
|
||||
})
|
||||
}
|
||||
|
||||
if (query._id === IdMap.getId("emptyVariantProductId")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("emptyVariantProductId"),
|
||||
title: "testtitle",
|
||||
options: [],
|
||||
})
|
||||
}
|
||||
|
||||
if (query._id === IdMap.getId("deleteId")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("deleteId"),
|
||||
variants: ["1", "2"],
|
||||
})
|
||||
}
|
||||
|
||||
if (query._id === IdMap.getId("validId")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("validId"),
|
||||
title: "test",
|
||||
})
|
||||
}
|
||||
|
||||
if (query._id === IdMap.getId("failId")) {
|
||||
return Promise.reject(new Error("test error"))
|
||||
}
|
||||
return Promise.resolve(undefined)
|
||||
}),
|
||||
}
|
||||
@@ -15,6 +15,8 @@ class ProductVariantModel extends BaseModel {
|
||||
prices: { type: [MoneyAmountSchema], default: [], required: true },
|
||||
options: { type: [OptionValueSchema], default: [] },
|
||||
image: { type: String, default: "" },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
published: { type: Boolean, default: false },
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
import mongoose from "mongoose"
|
||||
|
||||
export default new mongoose.Schema({
|
||||
product_id: { type: mongoose.Types.ObjectId, required: true },
|
||||
title: { type: String, required: true },
|
||||
values: { type: [String], default: [] },
|
||||
})
|
||||
Reference in new issue
Block a user