Completes Cart Service and store/carts endpoints (#18)

Completes Cart Service to allow shopping and checkout flows.
This commit is contained in:
Sebastian Rindom authored and GitHub committed 2020-03-16 09:48:52 +01:00
1 parent 8e7b66a205
commit 51aaf5105c
31 files changed
+2091 -45

No files matched your search

+143 -11
View File
@@ -6,8 +6,117 @@ export const carts = {
title: "test",
region_id: IdMap.getId("testRegion"),
items: [],
shippingAddress: {},
billingAddress: {},
shipping_address: {},
billing_address: {},
discounts: [],
customer_id: "",
},
withShippingOptions: {
_id: IdMap.getId("withShippingOptions"),
title: "test",
region_id: IdMap.getId("region-france"),
items: [],
shipping_options: [
{
_id: IdMap.getId("freeShipping"),
name: "Free Shipping",
region_id: IdMap.getId("testRegion"),
price: 10,
provider_id: "test_shipper",
},
{
_id: IdMap.getId("expensiveShipping"),
name: "Expensive Shipping",
region_id: IdMap.getId("testRegion"),
price: 100,
provider_id: "test_shipper",
},
],
shipping_address: {},
billing_address: {},
discounts: [],
customer_id: "",
},
cartWithPaySessionsDifRegion: {
_id: IdMap.getId("cartWithPaySessionsDifRegion"),
region_id: IdMap.getId("region-france"),
items: [
{
_id: IdMap.getId("existingLine"),
title: "merge line",
description: "This is a new line",
thumbnail: "test-img-yeah.com/thumb",
content: {
unit_price: 123,
variant: {
_id: IdMap.getId("can-cover"),
},
product: {
_id: IdMap.getId("product"),
},
quantity: 1,
},
quantity: 10,
},
],
payment_sessions: [
{
provider_id: "default_provider",
data: {
id: "default_provider_session",
},
},
{
provider_id: "unregistered",
data: {
id: "unregistered_session",
},
},
],
shipping_address: {},
billing_address: {},
discounts: [],
customer_id: "",
},
cartWithPaySessions: {
_id: IdMap.getId("cartWithPaySessions"),
region_id: IdMap.getId("testRegion"),
shipping_methods: [],
items: [
{
_id: IdMap.getId("existingLine"),
title: "merge line",
description: "This is a new line",
thumbnail: "test-img-yeah.com/thumb",
content: {
unit_price: 123,
variant: {
_id: IdMap.getId("can-cover"),
},
product: {
_id: IdMap.getId("product"),
},
quantity: 1,
},
quantity: 10,
},
],
payment_sessions: [
{
provider_id: "default_provider",
data: {
id: "default_provider_session",
},
},
{
provider_id: "unregistered",
data: {
id: "unregistered_session",
},
},
],
shipping_address: {},
billing_address: {},
discounts: [],
customer_id: "",
},
@@ -34,8 +143,8 @@ export const carts = {
quantity: 10,
},
],
shippingAddress: {},
billingAddress: {},
shipping_address: {},
billing_address: {},
discounts: [],
customer_id: "",
},
@@ -50,12 +159,14 @@ export const carts = {
yes: "sir",
},
},
shipping_method: {
provider_id: "gls",
data: {
yes: "sir",
shipping_methods: [
{
provider_id: "gls",
data: {
yes: "sir",
},
},
},
],
shipping_address: {
first_name: "hi",
last_name: "you",
@@ -127,8 +238,20 @@ export const carts = {
quantity: 10,
},
],
shippingAddress: {},
billingAddress: {},
shipping_methods: [
{
_id: IdMap.getId("freeShipping"),
profile_id: "default_profile",
},
],
shipping_options: [
{
_id: IdMap.getId("freeShipping"),
profile_id: "default_profile",
},
],
shipping_address: {},
billing_address: {},
discounts: [],
customer_id: "",
},
@@ -141,6 +264,15 @@ export const CartModelMock = {
}),
deleteOne: jest.fn().mockReturnValue(Promise.resolve()),
findOne: jest.fn().mockImplementation(query => {
if (query._id === IdMap.getId("withShippingOptions")) {
return Promise.resolve(carts.withShippingOptions)
}
if (query._id === IdMap.getId("cartWithPaySessionsDifRegion")) {
return Promise.resolve(carts.cartWithPaySessionsDifRegion)
}
if (query._id === IdMap.getId("cartWithPaySessions")) {
return Promise.resolve(carts.cartWithPaySessions)
}
if (query._id === IdMap.getId("emptyCart")) {
return Promise.resolve(carts.emptyCart)
}
+2
View File
@@ -20,6 +20,8 @@ class CartModel extends BaseModel {
region_id: { type: String, required: true },
discounts: { type: [String], default: [] },
customer_id: { type: String, default: "" },
payment_sessions: { type: [PaymentMethodSchema], default: [] },
shipping_options: { type: [ShippingMethodSchema], default: [] },
payment_method: { type: PaymentMethodSchema, default: {} },
shipping_methods: { type: [ShippingMethodSchema], default: [] },
metadata: { type: mongoose.Schema.Types.Mixed, default: {} },