Makes ProductVariant operations go through ProductService (#68)
Ensures that we can reliably manage product variants and their relationship to products
This commit is contained in:
@@ -39,7 +39,7 @@ export const orders = {
|
||||
quantity: 10,
|
||||
},
|
||||
],
|
||||
region: IdMap.getId("region-france"),
|
||||
region_id: IdMap.getId("region-france"),
|
||||
customer_id: IdMap.getId("test-customer"),
|
||||
payment_method: {
|
||||
provider_id: "default_provider",
|
||||
@@ -102,7 +102,7 @@ export const orders = {
|
||||
quantity: 10,
|
||||
},
|
||||
],
|
||||
region: IdMap.getId("region-france"),
|
||||
region_id: IdMap.getId("region-france"),
|
||||
customer_id: IdMap.getId("test-customer"),
|
||||
payment_method: {
|
||||
provider_id: "default_provider",
|
||||
@@ -182,7 +182,7 @@ export const orders = {
|
||||
quantity: 10,
|
||||
},
|
||||
],
|
||||
region: IdMap.getId("region-france"),
|
||||
region_id: IdMap.getId("region-france"),
|
||||
customer_id: IdMap.getId("test-customer"),
|
||||
payment_method: {
|
||||
provider_id: "default_provider",
|
||||
|
||||
@@ -10,6 +10,13 @@ export const ProductModelMock = {
|
||||
}),
|
||||
deleteOne: jest.fn().mockReturnValue(Promise.resolve()),
|
||||
findOne: jest.fn().mockImplementation(query => {
|
||||
if (query._id === IdMap.getId("fakeId")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("fakeId"),
|
||||
title: "Product With Variants",
|
||||
variants: ["1", "2", "3"],
|
||||
})
|
||||
}
|
||||
if (query._id === IdMap.getId("productWithFourVariants")) {
|
||||
return Promise.resolve({
|
||||
_id: IdMap.getId("productWithFourVariants"),
|
||||
|
||||
@@ -8,7 +8,7 @@ import LineItemSchema from "./schemas/line-item"
|
||||
import PaymentMethodSchema from "./schemas/payment-method"
|
||||
import ShippingMethodSchema from "./schemas/shipping-method"
|
||||
import AddressSchema from "./schemas/address"
|
||||
import DiscountModel from "./discount"
|
||||
import DiscountSchema from "./schemas/discount"
|
||||
|
||||
class CartModel extends BaseModel {
|
||||
static modelName = "Cart"
|
||||
@@ -19,7 +19,7 @@ class CartModel extends BaseModel {
|
||||
shipping_address: { type: AddressSchema },
|
||||
items: { type: [LineItemSchema], default: [] },
|
||||
region_id: { type: String, required: true },
|
||||
discounts: { type: [DiscountModel.schema], default: [] },
|
||||
discounts: { type: [DiscountSchema], default: [] },
|
||||
customer_id: { type: String, default: "" },
|
||||
payment_sessions: { type: [PaymentMethodSchema], default: [] },
|
||||
shipping_options: { type: [ShippingMethodSchema], default: [] },
|
||||
|
||||
@@ -21,7 +21,7 @@ class OrderModel extends BaseModel {
|
||||
billing_address: { type: AddressSchema, required: true },
|
||||
shipping_address: { type: AddressSchema, required: true },
|
||||
items: { type: [LineItemSchema], required: true },
|
||||
region: { type: String, required: true },
|
||||
region_id: { type: String, required: true },
|
||||
discounts: { type: [DiscountModel.schema], default: [] },
|
||||
customer_id: { type: String, required: true },
|
||||
payment_method: { type: PaymentMethodSchema, required: true },
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import mongoose from "mongoose"
|
||||
|
||||
import DiscountRule from "./discount-rule"
|
||||
|
||||
export default new mongoose.Schema({
|
||||
code: { type: String },
|
||||
discount_rule: { type: DiscountRule },
|
||||
usage_count: { type: Number },
|
||||
disabled: { type: Boolean },
|
||||
starts_at: { type: Date },
|
||||
ends_at: { type: Date },
|
||||
regions: { type: [String], default: [] },
|
||||
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
|
||||
})
|
||||
Reference in New Issue
Block a user