@labdigital/commercetools-mock 2.17.0 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4219 -3989
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +268 -415
- package/dist/index.d.ts +268 -415
- package/dist/index.js +4219 -3989
- package/dist/index.js.map +1 -1
- package/package.json +44 -46
- package/src/constants.ts +2 -2
- package/src/ctMock.test.ts +11 -11
- package/src/ctMock.ts +141 -127
- package/src/deprecation.ts +8 -0
- package/src/exceptions.ts +17 -15
- package/src/helpers.ts +32 -32
- package/src/index.test.ts +128 -128
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +13 -13
- package/src/lib/haversine.test.ts +9 -9
- package/src/lib/haversine.ts +11 -11
- package/src/lib/masking.ts +11 -11
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +23 -3
- package/src/lib/predicateParser.test.ts +185 -183
- package/src/lib/predicateParser.ts +234 -234
- package/src/lib/projectionSearchFilter.test.ts +103 -101
- package/src/lib/projectionSearchFilter.ts +152 -150
- package/src/lib/proxy.ts +5 -5
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.test.ts +110 -67
- package/src/oauth/server.ts +161 -141
- package/src/oauth/store.ts +49 -44
- package/src/priceSelector.test.ts +35 -35
- package/src/priceSelector.ts +30 -30
- package/src/product-projection-search.ts +136 -134
- package/src/projectAPI.test.ts +7 -7
- package/src/projectAPI.ts +24 -22
- package/src/repositories/abstract.ts +168 -116
- package/src/repositories/associate-role.ts +90 -77
- package/src/repositories/attribute-group.ts +51 -40
- package/src/repositories/business-unit.ts +168 -148
- package/src/repositories/cart/actions.ts +489 -0
- package/src/repositories/cart/helpers.ts +30 -0
- package/src/repositories/cart/index.ts +180 -0
- package/src/repositories/cart-discount/actions.ts +148 -0
- package/src/repositories/cart-discount/index.ts +86 -0
- package/src/repositories/category/actions.ts +231 -0
- package/src/repositories/category/index.ts +52 -0
- package/src/repositories/channel.ts +88 -90
- package/src/repositories/custom-object.ts +46 -45
- package/src/repositories/customer/actions.ts +165 -0
- package/src/repositories/customer/index.ts +79 -0
- package/src/repositories/customer-group.ts +66 -55
- package/src/repositories/discount-code/actions.ts +149 -0
- package/src/repositories/discount-code/index.ts +50 -0
- package/src/repositories/errors.ts +10 -10
- package/src/repositories/extension.ts +64 -62
- package/src/repositories/helpers.ts +117 -118
- package/src/repositories/index.ts +80 -79
- package/src/repositories/inventory-entry/actions.ts +84 -0
- package/src/repositories/inventory-entry/index.ts +44 -0
- package/src/repositories/my-customer.ts +114 -0
- package/src/repositories/my-order.ts +8 -8
- package/src/repositories/order/actions.ts +281 -0
- package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
- package/src/repositories/order/index.ts +260 -0
- package/src/repositories/order-edit.ts +10 -23
- package/src/repositories/payment/actions.ts +305 -0
- package/src/repositories/payment/helpers.ts +17 -0
- package/src/repositories/payment/index.ts +56 -0
- package/src/repositories/product/actions.ts +943 -0
- package/src/repositories/product/helpers.ts +98 -0
- package/src/repositories/product/index.ts +130 -0
- package/src/repositories/product-discount.ts +127 -117
- package/src/repositories/product-projection.ts +56 -62
- package/src/repositories/product-selection.ts +31 -28
- package/src/repositories/product-type.ts +136 -134
- package/src/repositories/project.ts +133 -118
- package/src/repositories/quote-request.ts +7 -19
- package/src/repositories/quote.ts +7 -22
- package/src/repositories/review.ts +13 -26
- package/src/repositories/shipping-method/actions.ts +198 -0
- package/src/repositories/shipping-method/helpers.ts +10 -0
- package/src/repositories/shipping-method/index.ts +138 -0
- package/src/repositories/shopping-list/actions.ts +295 -0
- package/src/repositories/shopping-list/index.ts +122 -0
- package/src/repositories/staged-quote.ts +7 -20
- package/src/repositories/standalone-price.ts +57 -44
- package/src/repositories/state.ts +113 -68
- package/src/repositories/store.ts +106 -94
- package/src/repositories/subscription.ts +46 -22
- package/src/repositories/tax-category/actions.ts +94 -0
- package/src/repositories/tax-category/helpers.ts +8 -0
- package/src/repositories/tax-category/index.ts +25 -0
- package/src/repositories/type/actions.ts +162 -0
- package/src/repositories/type/index.ts +24 -0
- package/src/repositories/zone.ts +62 -58
- package/src/server.ts +9 -9
- package/src/services/abstract.ts +75 -72
- package/src/services/associate-roles.test.ts +27 -27
- package/src/services/associate-roles.ts +7 -7
- package/src/services/attribute-group.ts +7 -7
- package/src/services/business-units.test.ts +28 -28
- package/src/services/business-units.ts +7 -7
- package/src/services/cart-discount.test.ts +199 -199
- package/src/services/cart-discount.ts +7 -7
- package/src/services/cart.test.ts +261 -261
- package/src/services/cart.ts +22 -21
- package/src/services/category.test.ts +121 -121
- package/src/services/category.ts +7 -7
- package/src/services/channel.ts +7 -7
- package/src/services/custom-object.test.ts +130 -130
- package/src/services/custom-object.ts +34 -31
- package/src/services/customer-group.ts +7 -7
- package/src/services/customer.test.ts +205 -205
- package/src/services/customer.ts +31 -29
- package/src/services/discount-code.ts +7 -7
- package/src/services/extension.ts +7 -7
- package/src/services/index.ts +85 -81
- package/src/services/inventory-entry.test.ts +106 -106
- package/src/services/inventory-entry.ts +7 -7
- package/src/services/my-cart.test.ts +56 -56
- package/src/services/my-cart.ts +20 -20
- package/src/services/my-customer.test.ts +155 -104
- package/src/services/my-customer.ts +61 -75
- package/src/services/my-order.ts +16 -16
- package/src/services/my-payment.test.ts +40 -40
- package/src/services/my-payment.ts +7 -7
- package/src/services/my-shopping-list.ts +7 -7
- package/src/services/order.test.ts +243 -243
- package/src/services/order.ts +23 -18
- package/src/services/payment.test.ts +40 -40
- package/src/services/payment.ts +7 -7
- package/src/services/product-discount.ts +7 -7
- package/src/services/product-projection.test.ts +190 -190
- package/src/services/product-projection.ts +34 -32
- package/src/services/product-selection.test.ts +19 -19
- package/src/services/product-selection.ts +7 -7
- package/src/services/product-type.test.ts +38 -38
- package/src/services/product-type.ts +7 -7
- package/src/services/product.test.ts +658 -656
- package/src/services/product.ts +7 -7
- package/src/services/project.test.ts +24 -24
- package/src/services/project.ts +17 -17
- package/src/services/reviews.ts +7 -7
- package/src/services/shipping-method.test.ts +78 -78
- package/src/services/shipping-method.ts +16 -16
- package/src/services/shopping-list.test.ts +170 -170
- package/src/services/shopping-list.ts +7 -7
- package/src/services/standalone-price.test.ts +112 -112
- package/src/services/standalone-price.ts +7 -7
- package/src/services/state.test.ts +30 -30
- package/src/services/state.ts +7 -7
- package/src/services/store.test.ts +40 -40
- package/src/services/store.ts +7 -7
- package/src/services/subscription.ts +7 -7
- package/src/services/tax-category.test.ts +43 -43
- package/src/services/tax-category.ts +7 -7
- package/src/services/type.ts +7 -7
- package/src/services/zone.ts +7 -7
- package/src/shippingCalculator.test.ts +43 -43
- package/src/shippingCalculator.ts +23 -23
- package/src/storage/abstract.ts +36 -34
- package/src/storage/in-memory.ts +237 -233
- package/src/storage/index.ts +2 -2
- package/src/types.ts +91 -91
- package/src/repositories/cart-discount.ts +0 -219
- package/src/repositories/cart.ts +0 -659
- package/src/repositories/category.ts +0 -256
- package/src/repositories/customer.ts +0 -228
- package/src/repositories/discount-code.ts +0 -181
- package/src/repositories/inventory-entry.ts +0 -109
- package/src/repositories/order.ts +0 -514
- package/src/repositories/payment.ts +0 -342
- package/src/repositories/product.ts +0 -1106
- package/src/repositories/shipping-method.ts +0 -312
- package/src/repositories/shopping-list.ts +0 -392
- package/src/repositories/tax-category.ts +0 -111
- package/src/repositories/type.ts +0 -172
|
@@ -3,115 +3,115 @@ import type {
|
|
|
3
3
|
Cart,
|
|
4
4
|
CentPrecisionMoney,
|
|
5
5
|
ProductDraft,
|
|
6
|
-
} from
|
|
7
|
-
import assert from
|
|
8
|
-
import supertest from
|
|
9
|
-
import { afterEach, beforeEach, describe, expect, test } from
|
|
10
|
-
import { CommercetoolsMock } from
|
|
6
|
+
} from "@commercetools/platform-sdk";
|
|
7
|
+
import assert from "assert";
|
|
8
|
+
import supertest from "supertest";
|
|
9
|
+
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
10
|
+
import { CommercetoolsMock } from "../index";
|
|
11
11
|
|
|
12
|
-
describe(
|
|
13
|
-
const ctMock = new CommercetoolsMock()
|
|
12
|
+
describe("Carts Query", () => {
|
|
13
|
+
const ctMock = new CommercetoolsMock();
|
|
14
14
|
|
|
15
15
|
beforeEach(async () => {
|
|
16
|
-
let response
|
|
16
|
+
let response;
|
|
17
17
|
response = await supertest(ctMock.app)
|
|
18
|
-
.post(
|
|
18
|
+
.post("/dummy/types")
|
|
19
19
|
.send({
|
|
20
|
-
key:
|
|
20
|
+
key: "my-cart",
|
|
21
21
|
name: {
|
|
22
|
-
en:
|
|
22
|
+
en: "Test",
|
|
23
23
|
},
|
|
24
24
|
description: {
|
|
25
|
-
en:
|
|
25
|
+
en: "Test Type",
|
|
26
26
|
},
|
|
27
|
-
resourceTypeIds: [
|
|
27
|
+
resourceTypeIds: ["order"],
|
|
28
28
|
fieldDefinitions: [
|
|
29
29
|
{
|
|
30
|
-
name:
|
|
30
|
+
name: "offer_name",
|
|
31
31
|
label: {
|
|
32
|
-
en:
|
|
32
|
+
en: "offer_name",
|
|
33
33
|
},
|
|
34
34
|
required: false,
|
|
35
35
|
type: {
|
|
36
|
-
name:
|
|
36
|
+
name: "String",
|
|
37
37
|
},
|
|
38
|
-
inputHint:
|
|
38
|
+
inputHint: "SingleLine",
|
|
39
39
|
},
|
|
40
40
|
],
|
|
41
|
-
})
|
|
42
|
-
expect(response.status).toBe(201)
|
|
41
|
+
});
|
|
42
|
+
expect(response.status).toBe(201);
|
|
43
43
|
|
|
44
44
|
response = await supertest(ctMock.app)
|
|
45
|
-
.post(
|
|
45
|
+
.post("/dummy/carts")
|
|
46
46
|
.send({
|
|
47
|
-
currency:
|
|
47
|
+
currency: "EUR",
|
|
48
48
|
custom: {
|
|
49
49
|
type: {
|
|
50
|
-
typeId:
|
|
51
|
-
key:
|
|
50
|
+
typeId: "type",
|
|
51
|
+
key: "my-cart",
|
|
52
52
|
},
|
|
53
53
|
fields: {
|
|
54
|
-
description:
|
|
54
|
+
description: "example description",
|
|
55
55
|
},
|
|
56
56
|
},
|
|
57
|
-
})
|
|
58
|
-
expect(response.status).toBe(201)
|
|
59
|
-
})
|
|
57
|
+
});
|
|
58
|
+
expect(response.status).toBe(201);
|
|
59
|
+
});
|
|
60
60
|
|
|
61
|
-
test(
|
|
61
|
+
test("no filter", async () => {
|
|
62
62
|
const response = await supertest(ctMock.app)
|
|
63
|
-
.get(
|
|
63
|
+
.get("/dummy/carts")
|
|
64
64
|
.query({
|
|
65
|
-
expand:
|
|
65
|
+
expand: "custom.type",
|
|
66
66
|
})
|
|
67
|
-
.send()
|
|
67
|
+
.send();
|
|
68
68
|
|
|
69
|
-
expect(response.status).toBe(200)
|
|
70
|
-
expect(response.body.count).toBe(1)
|
|
69
|
+
expect(response.status).toBe(200);
|
|
70
|
+
expect(response.body.count).toBe(1);
|
|
71
71
|
|
|
72
|
-
const myCart = response.body.results[0] as Cart
|
|
72
|
+
const myCart = response.body.results[0] as Cart;
|
|
73
73
|
|
|
74
|
-
expect(myCart.custom?.type.id).not.toBeUndefined()
|
|
75
|
-
expect(myCart.custom?.type.id).toBe(myCart.custom?.type.obj?.id)
|
|
76
|
-
expect(myCart.custom?.type.obj?.description?.en).toBe(
|
|
77
|
-
})
|
|
78
|
-
})
|
|
74
|
+
expect(myCart.custom?.type.id).not.toBeUndefined();
|
|
75
|
+
expect(myCart.custom?.type.id).toBe(myCart.custom?.type.obj?.id);
|
|
76
|
+
expect(myCart.custom?.type.obj?.description?.en).toBe("Test Type");
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
79
|
|
|
80
|
-
describe(
|
|
81
|
-
const ctMock = new CommercetoolsMock()
|
|
82
|
-
let cart: Cart | undefined
|
|
80
|
+
describe("Cart Update Actions", () => {
|
|
81
|
+
const ctMock = new CommercetoolsMock();
|
|
82
|
+
let cart: Cart | undefined;
|
|
83
83
|
|
|
84
84
|
const createCart = async (currency: string) => {
|
|
85
|
-
const response = await supertest(ctMock.app).post(
|
|
85
|
+
const response = await supertest(ctMock.app).post("/dummy/carts").send({
|
|
86
86
|
currency,
|
|
87
|
-
})
|
|
88
|
-
expect(response.status).toBe(201)
|
|
89
|
-
cart = response.body
|
|
90
|
-
}
|
|
87
|
+
});
|
|
88
|
+
expect(response.status).toBe(201);
|
|
89
|
+
cart = response.body;
|
|
90
|
+
};
|
|
91
91
|
|
|
92
92
|
const productDraft: ProductDraft = {
|
|
93
93
|
name: {
|
|
94
|
-
|
|
94
|
+
"nl-NL": "test product",
|
|
95
95
|
},
|
|
96
96
|
productType: {
|
|
97
|
-
typeId:
|
|
98
|
-
id:
|
|
97
|
+
typeId: "product-type",
|
|
98
|
+
id: "some-uuid",
|
|
99
99
|
},
|
|
100
100
|
masterVariant: {
|
|
101
|
-
sku:
|
|
101
|
+
sku: "1337",
|
|
102
102
|
prices: [
|
|
103
103
|
{
|
|
104
104
|
value: {
|
|
105
|
-
type:
|
|
106
|
-
currencyCode:
|
|
105
|
+
type: "centPrecision",
|
|
106
|
+
currencyCode: "EUR",
|
|
107
107
|
centAmount: 14900,
|
|
108
108
|
fractionDigits: 2,
|
|
109
109
|
} as CentPrecisionMoney,
|
|
110
110
|
},
|
|
111
111
|
{
|
|
112
112
|
value: {
|
|
113
|
-
type:
|
|
114
|
-
currencyCode:
|
|
113
|
+
type: "centPrecision",
|
|
114
|
+
currencyCode: "GBP",
|
|
115
115
|
centAmount: 18900,
|
|
116
116
|
fractionDigits: 2,
|
|
117
117
|
} as CentPrecisionMoney,
|
|
@@ -120,19 +120,19 @@ describe('Cart Update Actions', () => {
|
|
|
120
120
|
|
|
121
121
|
attributes: [
|
|
122
122
|
{
|
|
123
|
-
name:
|
|
124
|
-
value:
|
|
123
|
+
name: "test",
|
|
124
|
+
value: "test",
|
|
125
125
|
},
|
|
126
126
|
],
|
|
127
127
|
},
|
|
128
128
|
variants: [
|
|
129
129
|
{
|
|
130
|
-
sku:
|
|
130
|
+
sku: "1338",
|
|
131
131
|
prices: [
|
|
132
132
|
{
|
|
133
133
|
value: {
|
|
134
|
-
type:
|
|
135
|
-
currencyCode:
|
|
134
|
+
type: "centPrecision",
|
|
135
|
+
currencyCode: "EUR",
|
|
136
136
|
centAmount: 14900,
|
|
137
137
|
fractionDigits: 2,
|
|
138
138
|
} as CentPrecisionMoney,
|
|
@@ -140,58 +140,58 @@ describe('Cart Update Actions', () => {
|
|
|
140
140
|
],
|
|
141
141
|
attributes: [
|
|
142
142
|
{
|
|
143
|
-
name:
|
|
144
|
-
value:
|
|
143
|
+
name: "test2",
|
|
144
|
+
value: "test2",
|
|
145
145
|
},
|
|
146
146
|
],
|
|
147
147
|
},
|
|
148
148
|
],
|
|
149
149
|
slug: {
|
|
150
|
-
|
|
150
|
+
"nl-NL": "test-product",
|
|
151
151
|
},
|
|
152
152
|
publish: true,
|
|
153
|
-
}
|
|
153
|
+
};
|
|
154
154
|
|
|
155
155
|
beforeEach(async () => {
|
|
156
|
-
await createCart(
|
|
157
|
-
})
|
|
156
|
+
await createCart("EUR");
|
|
157
|
+
});
|
|
158
158
|
|
|
159
159
|
afterEach(() => {
|
|
160
|
-
ctMock.clear()
|
|
161
|
-
})
|
|
160
|
+
ctMock.clear();
|
|
161
|
+
});
|
|
162
162
|
|
|
163
|
-
test(
|
|
164
|
-
assert(cart,
|
|
163
|
+
test("no update", async () => {
|
|
164
|
+
assert(cart, "cart not created");
|
|
165
165
|
|
|
166
166
|
const response = await supertest(ctMock.app)
|
|
167
167
|
.post(`/dummy/carts/${cart.id}`)
|
|
168
168
|
.send({
|
|
169
169
|
version: 1,
|
|
170
|
-
actions: [{ action:
|
|
171
|
-
})
|
|
172
|
-
expect(response.status).toBe(200)
|
|
173
|
-
expect(response.body.version).toBe(2)
|
|
174
|
-
expect(response.body.locale).toBe(
|
|
170
|
+
actions: [{ action: "setLocale", locale: "nl-NL" }],
|
|
171
|
+
});
|
|
172
|
+
expect(response.status).toBe(200);
|
|
173
|
+
expect(response.body.version).toBe(2);
|
|
174
|
+
expect(response.body.locale).toBe("nl-NL");
|
|
175
175
|
|
|
176
176
|
const responseAgain = await supertest(ctMock.app)
|
|
177
177
|
.post(`/dummy/carts/${cart.id}`)
|
|
178
178
|
.send({
|
|
179
179
|
version: 2,
|
|
180
|
-
actions: [{ action:
|
|
181
|
-
})
|
|
182
|
-
expect(responseAgain.status).toBe(200)
|
|
183
|
-
expect(responseAgain.body.version).toBe(2)
|
|
184
|
-
expect(responseAgain.body.locale).toBe(
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
test(
|
|
180
|
+
actions: [{ action: "setLocale", locale: "nl-NL" }],
|
|
181
|
+
});
|
|
182
|
+
expect(responseAgain.status).toBe(200);
|
|
183
|
+
expect(responseAgain.body.version).toBe(2);
|
|
184
|
+
expect(responseAgain.body.locale).toBe("nl-NL");
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
test("addLineItem", async () => {
|
|
188
188
|
const product = await supertest(ctMock.app)
|
|
189
189
|
.post(`/dummy/products`)
|
|
190
190
|
.send(productDraft)
|
|
191
|
-
.then((x) => x.body)
|
|
191
|
+
.then((x) => x.body);
|
|
192
192
|
|
|
193
|
-
assert(cart,
|
|
194
|
-
assert(product,
|
|
193
|
+
assert(cart, "cart not created");
|
|
194
|
+
assert(product, "product not created");
|
|
195
195
|
|
|
196
196
|
const response = await supertest(ctMock.app)
|
|
197
197
|
.post(`/dummy/carts/${cart.id}`)
|
|
@@ -199,86 +199,86 @@ describe('Cart Update Actions', () => {
|
|
|
199
199
|
version: 1,
|
|
200
200
|
actions: [
|
|
201
201
|
{
|
|
202
|
-
action:
|
|
202
|
+
action: "addLineItem",
|
|
203
203
|
productId: product.id,
|
|
204
204
|
variantId: product.masterData.current.variants[0].id,
|
|
205
205
|
},
|
|
206
206
|
],
|
|
207
|
-
})
|
|
208
|
-
expect(response.status).toBe(200)
|
|
209
|
-
expect(response.body.version).toBe(2)
|
|
210
|
-
expect(response.body.lineItems).toHaveLength(1)
|
|
211
|
-
expect(response.body.totalPrice.centAmount).toEqual(14900)
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
test(
|
|
207
|
+
});
|
|
208
|
+
expect(response.status).toBe(200);
|
|
209
|
+
expect(response.body.version).toBe(2);
|
|
210
|
+
expect(response.body.lineItems).toHaveLength(1);
|
|
211
|
+
expect(response.body.totalPrice.centAmount).toEqual(14900);
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
test("addLineItem by SKU", async () => {
|
|
215
215
|
const product = await supertest(ctMock.app)
|
|
216
216
|
.post(`/dummy/products`)
|
|
217
217
|
.send(productDraft)
|
|
218
|
-
.then((x) => x.body)
|
|
218
|
+
.then((x) => x.body);
|
|
219
219
|
|
|
220
|
-
assert(cart,
|
|
221
|
-
assert(product,
|
|
220
|
+
assert(cart, "cart not created");
|
|
221
|
+
assert(product, "product not created");
|
|
222
222
|
|
|
223
223
|
const response = await supertest(ctMock.app)
|
|
224
224
|
.post(`/dummy/carts/${cart.id}`)
|
|
225
225
|
.send({
|
|
226
226
|
version: 1,
|
|
227
|
-
actions: [{ action:
|
|
228
|
-
})
|
|
229
|
-
expect(response.status).toBe(200)
|
|
230
|
-
expect(response.body.version).toBe(2)
|
|
231
|
-
expect(response.body.lineItems).toHaveLength(1)
|
|
232
|
-
expect(response.body.totalPrice.centAmount).toEqual(29800)
|
|
233
|
-
})
|
|
227
|
+
actions: [{ action: "addLineItem", sku: "1337", quantity: 2 }],
|
|
228
|
+
});
|
|
229
|
+
expect(response.status).toBe(200);
|
|
230
|
+
expect(response.body.version).toBe(2);
|
|
231
|
+
expect(response.body.lineItems).toHaveLength(1);
|
|
232
|
+
expect(response.body.totalPrice.centAmount).toEqual(29800);
|
|
233
|
+
});
|
|
234
234
|
|
|
235
235
|
test.each([
|
|
236
|
-
[
|
|
237
|
-
[
|
|
238
|
-
])(
|
|
239
|
-
await createCart(currency)
|
|
236
|
+
["EUR", 29800],
|
|
237
|
+
["GBP", 37800],
|
|
238
|
+
])("addLineItem with price selection", async (currency, total) => {
|
|
239
|
+
await createCart(currency);
|
|
240
240
|
|
|
241
241
|
const product = await supertest(ctMock.app)
|
|
242
242
|
.post(`/dummy/products`)
|
|
243
243
|
.send(productDraft)
|
|
244
|
-
.then((x) => x.body)
|
|
244
|
+
.then((x) => x.body);
|
|
245
245
|
|
|
246
|
-
assert(cart,
|
|
247
|
-
assert(product,
|
|
246
|
+
assert(cart, "cart not created");
|
|
247
|
+
assert(product, "product not created");
|
|
248
248
|
|
|
249
249
|
const response = await supertest(ctMock.app)
|
|
250
250
|
.post(`/dummy/carts/${cart.id}`)
|
|
251
251
|
.send({
|
|
252
252
|
version: 1,
|
|
253
|
-
actions: [{ action:
|
|
254
|
-
})
|
|
255
|
-
expect(response.status).toBe(200)
|
|
256
|
-
expect(response.body.version).toBe(2)
|
|
257
|
-
expect(response.body.lineItems).toHaveLength(1)
|
|
258
|
-
expect(response.body.lineItems[0].price.value.currencyCode).toBe(currency)
|
|
259
|
-
expect(response.body.totalPrice.centAmount).toEqual(total)
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
test(
|
|
263
|
-
assert(cart,
|
|
253
|
+
actions: [{ action: "addLineItem", sku: "1337", quantity: 2 }],
|
|
254
|
+
});
|
|
255
|
+
expect(response.status).toBe(200);
|
|
256
|
+
expect(response.body.version).toBe(2);
|
|
257
|
+
expect(response.body.lineItems).toHaveLength(1);
|
|
258
|
+
expect(response.body.lineItems[0].price.value.currencyCode).toBe(currency);
|
|
259
|
+
expect(response.body.totalPrice.centAmount).toEqual(total);
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
test("addLineItem unknown product", async () => {
|
|
263
|
+
assert(cart, "cart not created");
|
|
264
264
|
|
|
265
265
|
const response = await supertest(ctMock.app)
|
|
266
266
|
.post(`/dummy/carts/${cart.id}`)
|
|
267
267
|
.send({
|
|
268
268
|
version: 1,
|
|
269
|
-
actions: [{ action:
|
|
270
|
-
})
|
|
271
|
-
expect(response.status).toBe(400)
|
|
272
|
-
expect(response.body.message).toBe("A product with ID '123' not found.")
|
|
273
|
-
})
|
|
269
|
+
actions: [{ action: "addLineItem", productId: "123", variantId: 1 }],
|
|
270
|
+
});
|
|
271
|
+
expect(response.status).toBe(400);
|
|
272
|
+
expect(response.body.message).toBe("A product with ID '123' not found.");
|
|
273
|
+
});
|
|
274
274
|
|
|
275
|
-
test(
|
|
275
|
+
test("addItemShippingAddress", async () => {
|
|
276
276
|
await supertest(ctMock.app)
|
|
277
277
|
.post(`/dummy/products`)
|
|
278
278
|
.send(productDraft)
|
|
279
|
-
.then((x) => x.body)
|
|
279
|
+
.then((x) => x.body);
|
|
280
280
|
|
|
281
|
-
assert(cart,
|
|
281
|
+
assert(cart, "cart not created");
|
|
282
282
|
|
|
283
283
|
const response = await supertest(ctMock.app)
|
|
284
284
|
.post(`/dummy/carts/${cart.id}`)
|
|
@@ -286,30 +286,30 @@ describe('Cart Update Actions', () => {
|
|
|
286
286
|
version: 1,
|
|
287
287
|
actions: [
|
|
288
288
|
{
|
|
289
|
-
action:
|
|
289
|
+
action: "addItemShippingAddress",
|
|
290
290
|
address: {
|
|
291
|
-
firstName:
|
|
292
|
-
lastName:
|
|
293
|
-
company:
|
|
294
|
-
country:
|
|
291
|
+
firstName: "John",
|
|
292
|
+
lastName: "Doe",
|
|
293
|
+
company: "My Company",
|
|
294
|
+
country: "NL",
|
|
295
295
|
},
|
|
296
296
|
},
|
|
297
297
|
],
|
|
298
|
-
})
|
|
298
|
+
});
|
|
299
299
|
|
|
300
|
-
expect(response.body.itemShippingAddresses).toHaveLength(1)
|
|
301
|
-
expect(response.status).toBe(200)
|
|
302
|
-
expect(response.body.version).toBe(2)
|
|
303
|
-
expect(response.body.lineItems).toHaveLength(0)
|
|
304
|
-
})
|
|
300
|
+
expect(response.body.itemShippingAddresses).toHaveLength(1);
|
|
301
|
+
expect(response.status).toBe(200);
|
|
302
|
+
expect(response.body.version).toBe(2);
|
|
303
|
+
expect(response.body.lineItems).toHaveLength(0);
|
|
304
|
+
});
|
|
305
305
|
|
|
306
|
-
test(
|
|
306
|
+
test("recalculate", async () => {
|
|
307
307
|
await supertest(ctMock.app)
|
|
308
308
|
.post(`/dummy/products`)
|
|
309
309
|
.send(productDraft)
|
|
310
|
-
.then((x) => x.body)
|
|
310
|
+
.then((x) => x.body);
|
|
311
311
|
|
|
312
|
-
assert(cart,
|
|
312
|
+
assert(cart, "cart not created");
|
|
313
313
|
|
|
314
314
|
const response = await supertest(ctMock.app)
|
|
315
315
|
.post(`/dummy/carts/${cart.id}`)
|
|
@@ -317,24 +317,24 @@ describe('Cart Update Actions', () => {
|
|
|
317
317
|
version: 1,
|
|
318
318
|
actions: [
|
|
319
319
|
{
|
|
320
|
-
action:
|
|
320
|
+
action: "recalculate",
|
|
321
321
|
updateProductData: true,
|
|
322
322
|
},
|
|
323
323
|
],
|
|
324
|
-
})
|
|
324
|
+
});
|
|
325
325
|
|
|
326
|
-
expect(response.status).toBe(200)
|
|
327
|
-
expect(response.body.version).toBe(1)
|
|
328
|
-
})
|
|
326
|
+
expect(response.status).toBe(200);
|
|
327
|
+
expect(response.body.version).toBe(1);
|
|
328
|
+
});
|
|
329
329
|
|
|
330
|
-
test(
|
|
330
|
+
test("removeLineItem", async () => {
|
|
331
331
|
const product = await supertest(ctMock.app)
|
|
332
332
|
.post(`/dummy/products`)
|
|
333
333
|
.send(productDraft)
|
|
334
|
-
.then((x) => x.body)
|
|
334
|
+
.then((x) => x.body);
|
|
335
335
|
|
|
336
|
-
assert(cart,
|
|
337
|
-
assert(product,
|
|
336
|
+
assert(cart, "cart not created");
|
|
337
|
+
assert(product, "product not created");
|
|
338
338
|
|
|
339
339
|
const updatedCart = await supertest(ctMock.app)
|
|
340
340
|
.post(`/dummy/carts/${cart.id}`)
|
|
@@ -342,36 +342,36 @@ describe('Cart Update Actions', () => {
|
|
|
342
342
|
version: 1,
|
|
343
343
|
actions: [
|
|
344
344
|
{
|
|
345
|
-
action:
|
|
345
|
+
action: "addLineItem",
|
|
346
346
|
productId: product.id,
|
|
347
347
|
variantId: product.masterData.current.variants[0].id,
|
|
348
348
|
},
|
|
349
349
|
],
|
|
350
|
-
})
|
|
351
|
-
const lineItem = updatedCart.body.lineItems[0]
|
|
352
|
-
assert(lineItem,
|
|
350
|
+
});
|
|
351
|
+
const lineItem = updatedCart.body.lineItems[0];
|
|
352
|
+
assert(lineItem, "lineItem not created");
|
|
353
353
|
|
|
354
|
-
expect(updatedCart.body.lineItems).toHaveLength(1)
|
|
354
|
+
expect(updatedCart.body.lineItems).toHaveLength(1);
|
|
355
355
|
|
|
356
356
|
const response = await supertest(ctMock.app)
|
|
357
357
|
.post(`/dummy/carts/${cart.id}`)
|
|
358
358
|
.send({
|
|
359
359
|
version: updatedCart.body.version,
|
|
360
|
-
actions: [{ action:
|
|
361
|
-
})
|
|
362
|
-
expect(response.status).toBe(200)
|
|
363
|
-
expect(response.body.version).toBe(3)
|
|
364
|
-
expect(response.body.lineItems).toHaveLength(0)
|
|
365
|
-
})
|
|
366
|
-
|
|
367
|
-
test(
|
|
360
|
+
actions: [{ action: "removeLineItem", lineItemId: lineItem.id }],
|
|
361
|
+
});
|
|
362
|
+
expect(response.status).toBe(200);
|
|
363
|
+
expect(response.body.version).toBe(3);
|
|
364
|
+
expect(response.body.lineItems).toHaveLength(0);
|
|
365
|
+
});
|
|
366
|
+
|
|
367
|
+
test("removeLineItem decrease quantity", async () => {
|
|
368
368
|
const product = await supertest(ctMock.app)
|
|
369
369
|
.post(`/dummy/products`)
|
|
370
370
|
.send(productDraft)
|
|
371
|
-
.then((x) => x.body)
|
|
371
|
+
.then((x) => x.body);
|
|
372
372
|
|
|
373
|
-
assert(cart,
|
|
374
|
-
assert(product,
|
|
373
|
+
assert(cart, "cart not created");
|
|
374
|
+
assert(product, "product not created");
|
|
375
375
|
|
|
376
376
|
const updatedCart = await supertest(ctMock.app)
|
|
377
377
|
.post(`/dummy/carts/${cart.id}`)
|
|
@@ -379,69 +379,69 @@ describe('Cart Update Actions', () => {
|
|
|
379
379
|
version: 1,
|
|
380
380
|
actions: [
|
|
381
381
|
{
|
|
382
|
-
action:
|
|
382
|
+
action: "addLineItem",
|
|
383
383
|
productId: product.id,
|
|
384
384
|
variantId: product.masterData.current.variants[0].id,
|
|
385
385
|
quantity: 2,
|
|
386
386
|
},
|
|
387
387
|
],
|
|
388
|
-
})
|
|
389
|
-
const lineItem = updatedCart.body.lineItems[0]
|
|
390
|
-
assert(lineItem,
|
|
388
|
+
});
|
|
389
|
+
const lineItem = updatedCart.body.lineItems[0];
|
|
390
|
+
assert(lineItem, "lineItem not created");
|
|
391
391
|
|
|
392
|
-
expect(updatedCart.body.lineItems).toHaveLength(1)
|
|
393
|
-
expect(updatedCart.body.lineItems[0].quantity).toBe(2)
|
|
392
|
+
expect(updatedCart.body.lineItems).toHaveLength(1);
|
|
393
|
+
expect(updatedCart.body.lineItems[0].quantity).toBe(2);
|
|
394
394
|
|
|
395
395
|
const response = await supertest(ctMock.app)
|
|
396
396
|
.post(`/dummy/carts/${cart.id}`)
|
|
397
397
|
.send({
|
|
398
398
|
version: updatedCart.body.version,
|
|
399
399
|
actions: [
|
|
400
|
-
{ action:
|
|
400
|
+
{ action: "removeLineItem", lineItemId: lineItem.id, quantity: 1 },
|
|
401
401
|
],
|
|
402
|
-
})
|
|
403
|
-
expect(response.status).toBe(200)
|
|
404
|
-
expect(response.body.version).toBe(3)
|
|
405
|
-
expect(response.body.lineItems).toHaveLength(1)
|
|
406
|
-
expect(response.body.lineItems[0].quantity).toBe(1)
|
|
407
|
-
})
|
|
402
|
+
});
|
|
403
|
+
expect(response.status).toBe(200);
|
|
404
|
+
expect(response.body.version).toBe(3);
|
|
405
|
+
expect(response.body.lineItems).toHaveLength(1);
|
|
406
|
+
expect(response.body.lineItems[0].quantity).toBe(1);
|
|
407
|
+
});
|
|
408
408
|
|
|
409
|
-
test(
|
|
410
|
-
assert(cart,
|
|
409
|
+
test("setBillingAddress", async () => {
|
|
410
|
+
assert(cart, "cart not created");
|
|
411
411
|
|
|
412
412
|
const address: Address = {
|
|
413
|
-
streetName:
|
|
414
|
-
city:
|
|
415
|
-
country:
|
|
416
|
-
}
|
|
413
|
+
streetName: "Street name",
|
|
414
|
+
city: "Utrecht",
|
|
415
|
+
country: "NL",
|
|
416
|
+
};
|
|
417
417
|
|
|
418
418
|
const response = await supertest(ctMock.app)
|
|
419
419
|
.post(`/dummy/carts/${cart.id}`)
|
|
420
420
|
.send({
|
|
421
421
|
version: 1,
|
|
422
|
-
actions: [{ action:
|
|
423
|
-
})
|
|
424
|
-
expect(response.status).toBe(200)
|
|
425
|
-
expect(response.body.version).toBe(2)
|
|
426
|
-
expect(response.body.billingAddress).toEqual(address)
|
|
427
|
-
})
|
|
422
|
+
actions: [{ action: "setBillingAddress", address }],
|
|
423
|
+
});
|
|
424
|
+
expect(response.status).toBe(200);
|
|
425
|
+
expect(response.body.version).toBe(2);
|
|
426
|
+
expect(response.body.billingAddress).toEqual(address);
|
|
427
|
+
});
|
|
428
428
|
|
|
429
|
-
test(
|
|
430
|
-
assert(cart,
|
|
429
|
+
test("setCountry", async () => {
|
|
430
|
+
assert(cart, "cart not created");
|
|
431
431
|
|
|
432
432
|
const response = await supertest(ctMock.app)
|
|
433
433
|
.post(`/dummy/carts/${cart.id}`)
|
|
434
434
|
.send({
|
|
435
435
|
version: 1,
|
|
436
|
-
actions: [{ action:
|
|
437
|
-
})
|
|
438
|
-
expect(response.status).toBe(200)
|
|
439
|
-
expect(response.body.version).toBe(2)
|
|
440
|
-
expect(response.body.country).toBe(
|
|
441
|
-
})
|
|
436
|
+
actions: [{ action: "setCountry", country: "NL" }],
|
|
437
|
+
});
|
|
438
|
+
expect(response.status).toBe(200);
|
|
439
|
+
expect(response.body.version).toBe(2);
|
|
440
|
+
expect(response.body.country).toBe("NL");
|
|
441
|
+
});
|
|
442
442
|
|
|
443
|
-
test(
|
|
444
|
-
assert(cart,
|
|
443
|
+
test("setDirectDiscounts", async () => {
|
|
444
|
+
assert(cart, "cart not created");
|
|
445
445
|
|
|
446
446
|
const response = await supertest(ctMock.app)
|
|
447
447
|
.post(`/dummy/carts/${cart.id}`)
|
|
@@ -449,89 +449,89 @@ describe('Cart Update Actions', () => {
|
|
|
449
449
|
version: 1,
|
|
450
450
|
actions: [
|
|
451
451
|
{
|
|
452
|
-
action:
|
|
452
|
+
action: "setDirectDiscounts",
|
|
453
453
|
discounts: [
|
|
454
454
|
{
|
|
455
|
-
target: { type:
|
|
455
|
+
target: { type: "totalPrice" },
|
|
456
456
|
value: {
|
|
457
457
|
money: [
|
|
458
458
|
{
|
|
459
459
|
centAmount: 500,
|
|
460
|
-
currencyCode:
|
|
460
|
+
currencyCode: "EUR",
|
|
461
461
|
fractionDigits: 2,
|
|
462
|
-
type:
|
|
462
|
+
type: "centPrecision",
|
|
463
463
|
},
|
|
464
464
|
],
|
|
465
|
-
type:
|
|
465
|
+
type: "absolute",
|
|
466
466
|
},
|
|
467
467
|
},
|
|
468
468
|
],
|
|
469
469
|
},
|
|
470
470
|
],
|
|
471
|
-
})
|
|
472
|
-
expect(response.status).toBe(200)
|
|
473
|
-
expect(response.body.version).toBe(2)
|
|
471
|
+
});
|
|
472
|
+
expect(response.status).toBe(200);
|
|
473
|
+
expect(response.body.version).toBe(2);
|
|
474
474
|
expect(response.body.directDiscounts).toMatchObject([
|
|
475
475
|
{
|
|
476
476
|
id: expect.any(String),
|
|
477
|
-
target: { type:
|
|
477
|
+
target: { type: "totalPrice" },
|
|
478
478
|
value: {
|
|
479
479
|
money: [
|
|
480
480
|
{
|
|
481
481
|
centAmount: 500,
|
|
482
|
-
currencyCode:
|
|
482
|
+
currencyCode: "EUR",
|
|
483
483
|
fractionDigits: 2,
|
|
484
|
-
type:
|
|
484
|
+
type: "centPrecision",
|
|
485
485
|
},
|
|
486
486
|
],
|
|
487
|
-
type:
|
|
487
|
+
type: "absolute",
|
|
488
488
|
},
|
|
489
489
|
},
|
|
490
|
-
])
|
|
491
|
-
})
|
|
490
|
+
]);
|
|
491
|
+
});
|
|
492
492
|
|
|
493
|
-
test(
|
|
494
|
-
assert(cart,
|
|
493
|
+
test("setCustomerEmail", async () => {
|
|
494
|
+
assert(cart, "cart not created");
|
|
495
495
|
|
|
496
496
|
const response = await supertest(ctMock.app)
|
|
497
497
|
.post(`/dummy/carts/${cart.id}`)
|
|
498
498
|
.send({
|
|
499
499
|
version: 1,
|
|
500
|
-
actions: [{ action:
|
|
501
|
-
})
|
|
502
|
-
expect(response.status).toBe(200)
|
|
503
|
-
expect(response.body.version).toBe(2)
|
|
504
|
-
expect(response.body.customerEmail).toBe(
|
|
505
|
-
})
|
|
500
|
+
actions: [{ action: "setCustomerEmail", email: "john@doe.com" }],
|
|
501
|
+
});
|
|
502
|
+
expect(response.status).toBe(200);
|
|
503
|
+
expect(response.body.version).toBe(2);
|
|
504
|
+
expect(response.body.customerEmail).toBe("john@doe.com");
|
|
505
|
+
});
|
|
506
506
|
|
|
507
|
-
test(
|
|
508
|
-
assert(cart,
|
|
507
|
+
test("setShippingAddress", async () => {
|
|
508
|
+
assert(cart, "cart not created");
|
|
509
509
|
|
|
510
510
|
const address: Address = {
|
|
511
|
-
streetName:
|
|
512
|
-
city:
|
|
513
|
-
country:
|
|
514
|
-
}
|
|
511
|
+
streetName: "Street name",
|
|
512
|
+
city: "Utrecht",
|
|
513
|
+
country: "NL",
|
|
514
|
+
};
|
|
515
515
|
|
|
516
516
|
const response = await supertest(ctMock.app)
|
|
517
517
|
.post(`/dummy/carts/${cart.id}`)
|
|
518
518
|
.send({
|
|
519
519
|
version: 1,
|
|
520
|
-
actions: [{ action:
|
|
521
|
-
})
|
|
522
|
-
expect(response.status).toBe(200)
|
|
523
|
-
expect(response.body.version).toBe(2)
|
|
524
|
-
expect(response.body.shippingAddress).toEqual(address)
|
|
525
|
-
})
|
|
526
|
-
|
|
527
|
-
test(
|
|
520
|
+
actions: [{ action: "setShippingAddress", address }],
|
|
521
|
+
});
|
|
522
|
+
expect(response.status).toBe(200);
|
|
523
|
+
expect(response.body.version).toBe(2);
|
|
524
|
+
expect(response.body.shippingAddress).toEqual(address);
|
|
525
|
+
});
|
|
526
|
+
|
|
527
|
+
test("setLineItemShippingDetails", async () => {
|
|
528
528
|
const product = await supertest(ctMock.app)
|
|
529
529
|
.post(`/dummy/products`)
|
|
530
530
|
.send(productDraft)
|
|
531
|
-
.then((x) => x.body)
|
|
531
|
+
.then((x) => x.body);
|
|
532
532
|
|
|
533
|
-
assert(cart,
|
|
534
|
-
assert(product,
|
|
533
|
+
assert(cart, "cart not created");
|
|
534
|
+
assert(product, "product not created");
|
|
535
535
|
|
|
536
536
|
const updatedCart = await supertest(ctMock.app)
|
|
537
537
|
.post(`/dummy/carts/${cart.id}`)
|
|
@@ -539,17 +539,17 @@ describe('Cart Update Actions', () => {
|
|
|
539
539
|
version: 1,
|
|
540
540
|
actions: [
|
|
541
541
|
{
|
|
542
|
-
action:
|
|
542
|
+
action: "addLineItem",
|
|
543
543
|
productId: product.id,
|
|
544
544
|
variantId: product.masterData.current.variants[0].id,
|
|
545
545
|
},
|
|
546
546
|
],
|
|
547
|
-
})
|
|
548
|
-
const lineItem = updatedCart.body.lineItems[0]
|
|
549
|
-
assert(lineItem,
|
|
547
|
+
});
|
|
548
|
+
const lineItem = updatedCart.body.lineItems[0];
|
|
549
|
+
assert(lineItem, "lineItem not created");
|
|
550
550
|
|
|
551
|
-
expect(updatedCart.body.version).toBe(2)
|
|
552
|
-
expect(updatedCart.body.lineItems).toHaveLength(1)
|
|
551
|
+
expect(updatedCart.body.version).toBe(2);
|
|
552
|
+
expect(updatedCart.body.lineItems).toHaveLength(1);
|
|
553
553
|
|
|
554
554
|
const response = await supertest(ctMock.app)
|
|
555
555
|
.post(`/dummy/carts/${cart.id}`)
|
|
@@ -557,26 +557,26 @@ describe('Cart Update Actions', () => {
|
|
|
557
557
|
version: updatedCart.body.version,
|
|
558
558
|
actions: [
|
|
559
559
|
{
|
|
560
|
-
action:
|
|
560
|
+
action: "setLineItemShippingDetails",
|
|
561
561
|
lineItemId: lineItem.id,
|
|
562
562
|
shippingDetails: {
|
|
563
563
|
targets: [
|
|
564
564
|
{
|
|
565
|
-
addressKey:
|
|
565
|
+
addressKey: "address-key",
|
|
566
566
|
quantity: 1,
|
|
567
567
|
},
|
|
568
568
|
],
|
|
569
569
|
},
|
|
570
570
|
},
|
|
571
571
|
],
|
|
572
|
-
})
|
|
572
|
+
});
|
|
573
573
|
|
|
574
|
-
expect(response.status).toBe(200)
|
|
575
|
-
expect(response.body.version).toBe(3)
|
|
576
|
-
expect(response.body.lineItems).toHaveLength(1)
|
|
574
|
+
expect(response.status).toBe(200);
|
|
575
|
+
expect(response.body.version).toBe(3);
|
|
576
|
+
expect(response.body.lineItems).toHaveLength(1);
|
|
577
577
|
|
|
578
|
-
const updatedLineItem = response.body.lineItems[0]
|
|
579
|
-
expect(updatedLineItem.shippingDetails).toBeDefined()
|
|
580
|
-
expect(updatedLineItem.shippingDetails.targets).toHaveLength(1)
|
|
581
|
-
})
|
|
582
|
-
})
|
|
578
|
+
const updatedLineItem = response.body.lineItems[0];
|
|
579
|
+
expect(updatedLineItem.shippingDetails).toBeDefined();
|
|
580
|
+
expect(updatedLineItem.shippingDetails.targets).toHaveLength(1);
|
|
581
|
+
});
|
|
582
|
+
});
|