Adds cart service skeleton

This commit is contained in:
Sebastian Rindom committed 2020-01-28 16:25:28 +01:00
1 parent b16f32f63f
commit 751adec7f7
7 files changed
+306

No files matched your search

@@ -0,0 +1,28 @@
import IdMap from "../../helpers/id-map"
export const carts = {
emptyCart: {
_id: IdMap.getId("emptyCart"),
title: "test",
region: IdMap.getId("testRegion"),
items: [],
shippingAddress: {},
billingAddress: {},
discounts: [],
customer_id: "",
},
}
export const CartModelMock = {
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("emptyCart")) {
return Promise.resolve(carts.emptyCart)
}
return Promise.resolve(undefined)
}),
}
+25
View File
@@ -0,0 +1,25 @@
/*******************************************************************************
* models/product-variant.js
*
******************************************************************************/
import mongoose from "mongoose"
import { BaseModel } from "../interfaces"
import LineItemSchema from "./schemas/line-item"
import AddressSchema from "./schemas/address"
class CartModel extends BaseModel {
static modelName = "Cart"
static schema = {
email: { type: String },
billingAddress: { type: AddressSchema },
shippingAddress: { type: AddressSchema },
items: { type: [LinetItemSchema], default: [] },
region: { type: String, required: true },
discounts: { type: [String], default: true },
customer_id: { type: String },
}
}
export default CartModel
@@ -0,0 +1,16 @@
/*******************************************************************************
*
******************************************************************************/
import mongoose from "mongoose"
export default new mongoose.Schema({
first_name: { type: String, required: true },
last_name: { type: String, required: true },
address1: { type: String, required: true },
address2: { type: String },
city: { type: String, required: true },
country_code: { type: String, required: true },
province: { type: String },
postal_code: { type: String, required: true },
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
})
@@ -0,0 +1,29 @@
/*******************************************************************************
*
******************************************************************************/
import mongoose from "mongoose"
export default new mongoose.Schema({
title: { type: String, required: true },
description: { type: String },
thumbnail: { type: String },
// mongoose doesn't allow multi-type validation but this field allows both
// an object containing:
// {
// variant: (ProductVariantSchema),
// product: (ProductSchema)
// }
//
// and and array containing:
// [
// {
// variant: (ProductVariantSchema),
// product: (ProductSchema)
// }
// ]
// validation is done in the cart service.
content: { type: mongoose.Schema.Types.Mixed, required: true },
quantity: { type: Number, required: true },
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },
})