@labdigital/commercetools-mock 2.66.0 → 3.0.0-beta.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/README.md +31 -8
- package/dist/abstract-BKFcva6S.mjs +1044 -0
- package/dist/abstract-BKFcva6S.mjs.map +1 -0
- package/dist/config-BcNSzPZz.d.mts +1718 -0
- package/dist/index.d.mts +50 -1633
- package/dist/index.mjs +3769 -2653
- package/dist/index.mjs.map +1 -1
- package/dist/storage/sqlite.d.mts +59 -0
- package/dist/storage/sqlite.mjs +234 -0
- package/dist/storage/sqlite.mjs.map +1 -0
- package/package.json +26 -29
- package/src/ctMock.ts +125 -136
- package/src/helpers.ts +14 -6
- package/src/index.ts +5 -0
- package/src/lib/masking.ts +4 -5
- package/src/lib/product-review-statistics.test.ts +257 -294
- package/src/lib/review-statistics.ts +17 -4
- package/src/oauth/helpers.ts +7 -4
- package/src/oauth/server.test.ts +102 -62
- package/src/oauth/server.ts +215 -213
- package/src/oauth/store.ts +20 -6
- package/src/orderSearch.ts +3 -3
- package/src/product-projection-search.ts +38 -20
- package/src/product-search-availability.test.ts +31 -52
- package/src/product-search.ts +19 -10
- package/src/projectAPI.ts +6 -22
- package/src/repositories/abstract.ts +182 -48
- package/src/repositories/as-associate.test.ts +19 -19
- package/src/repositories/associate-role.ts +12 -23
- package/src/repositories/attribute-group.test.ts +23 -23
- package/src/repositories/attribute-group.ts +6 -4
- package/src/repositories/business-unit.test.ts +63 -57
- package/src/repositories/business-unit.ts +107 -55
- package/src/repositories/cart/actions.ts +96 -65
- package/src/repositories/cart/helpers.ts +15 -11
- package/src/repositories/cart/index.test.ts +136 -30
- package/src/repositories/cart/index.ts +76 -59
- package/src/repositories/cart-discount/actions.ts +12 -44
- package/src/repositories/cart-discount/index.ts +20 -8
- package/src/repositories/category/actions.ts +27 -27
- package/src/repositories/category/index.test.ts +13 -9
- package/src/repositories/category/index.ts +40 -23
- package/src/repositories/channel.test.ts +53 -51
- package/src/repositories/channel.ts +12 -22
- package/src/repositories/custom-object.ts +34 -25
- package/src/repositories/customer/actions.ts +47 -25
- package/src/repositories/customer/index.test.ts +11 -11
- package/src/repositories/customer/index.ts +65 -35
- package/src/repositories/customer-group.test.ts +44 -42
- package/src/repositories/customer-group.ts +12 -22
- package/src/repositories/discount-code/actions.ts +3 -19
- package/src/repositories/discount-code/index.ts +9 -4
- package/src/repositories/discount-group/index.ts +8 -3
- package/src/repositories/extension.test.ts +27 -27
- package/src/repositories/extension.ts +10 -5
- package/src/repositories/helpers.ts +126 -47
- package/src/repositories/inventory-entry/actions.ts +3 -24
- package/src/repositories/inventory-entry/index.ts +19 -11
- package/src/repositories/my-customer.ts +13 -12
- package/src/repositories/my-order.ts +5 -2
- package/src/repositories/order/actions.ts +84 -56
- package/src/repositories/order/index.test.ts +36 -31
- package/src/repositories/order/index.ts +83 -49
- package/src/repositories/order-edit.ts +8 -3
- package/src/repositories/payment/actions.ts +64 -44
- package/src/repositories/payment/helpers.ts +3 -3
- package/src/repositories/payment/index.ts +28 -12
- package/src/repositories/product/actions.ts +133 -98
- package/src/repositories/product/helpers.ts +29 -16
- package/src/repositories/product/index.ts +42 -25
- package/src/repositories/product-discount.ts +6 -4
- package/src/repositories/product-projection.ts +41 -21
- package/src/repositories/product-selection.ts +8 -15
- package/src/repositories/product-tailoring.ts +22 -3
- package/src/repositories/product-type.ts +45 -4
- package/src/repositories/project.ts +57 -13
- package/src/repositories/quote/actions.ts +5 -28
- package/src/repositories/quote/index.ts +29 -6
- package/src/repositories/quote-request/actions.ts +5 -28
- package/src/repositories/quote-request/index.test.ts +3 -3
- package/src/repositories/quote-request/index.ts +31 -11
- package/src/repositories/quote-staged/actions.ts +5 -28
- package/src/repositories/quote-staged/index.ts +22 -8
- package/src/repositories/recurrence-policy/index.ts +6 -4
- package/src/repositories/recurring-order/actions.ts +7 -32
- package/src/repositories/recurring-order/index.ts +8 -6
- package/src/repositories/review.test.ts +147 -142
- package/src/repositories/review.ts +31 -37
- package/src/repositories/shipping-method/actions.ts +11 -28
- package/src/repositories/shipping-method/index.ts +26 -15
- package/src/repositories/shopping-list/actions.ts +21 -31
- package/src/repositories/shopping-list/index.ts +44 -22
- package/src/repositories/standalone-price.ts +6 -4
- package/src/repositories/state.ts +15 -9
- package/src/repositories/store.ts +21 -32
- package/src/repositories/subscription.test.ts +22 -22
- package/src/repositories/subscription.ts +8 -3
- package/src/repositories/tax-category/index.ts +8 -3
- package/src/repositories/type/actions.ts +21 -3
- package/src/repositories/type/index.ts +5 -3
- package/src/repositories/zone.test.ts +112 -77
- package/src/repositories/zone.ts +5 -3
- package/src/schemas/generated/associate-role.ts +13 -0
- package/src/schemas/generated/attribute-group.ts +12 -0
- package/src/schemas/generated/business-unit.ts +38 -0
- package/src/schemas/generated/cart-discount.ts +33 -0
- package/src/schemas/generated/cart.ts +61 -0
- package/src/schemas/generated/category.ts +25 -0
- package/src/schemas/generated/channel.ts +21 -0
- package/src/schemas/generated/common.ts +1372 -0
- package/src/schemas/generated/custom-object.ts +11 -0
- package/src/schemas/generated/customer-group.ts +11 -0
- package/src/schemas/generated/customer.ts +47 -0
- package/src/schemas/generated/discount-code.ts +25 -0
- package/src/schemas/generated/discount-group.ts +13 -0
- package/src/schemas/generated/extension.ts +15 -0
- package/src/schemas/generated/index.ts +42 -0
- package/src/schemas/generated/inventory-entry.ts +20 -0
- package/src/schemas/generated/my-quote-request.ts +10 -0
- package/src/schemas/generated/order-edit.ts +18 -0
- package/src/schemas/generated/order-from-cart.ts +25 -0
- package/src/schemas/generated/payment.ts +30 -0
- package/src/schemas/generated/product-discount.ts +20 -0
- package/src/schemas/generated/product-selection.ts +18 -0
- package/src/schemas/generated/product-tailoring.ts +26 -0
- package/src/schemas/generated/product-type.ts +12 -0
- package/src/schemas/generated/product.ts +37 -0
- package/src/schemas/generated/quote-request.ts +19 -0
- package/src/schemas/generated/quote.ts +18 -0
- package/src/schemas/generated/recurrence-policy.ts +15 -0
- package/src/schemas/generated/recurring-order.ts +19 -0
- package/src/schemas/generated/review.ts +24 -0
- package/src/schemas/generated/shipping-method.ts +24 -0
- package/src/schemas/generated/shopping-list.ts +28 -0
- package/src/schemas/generated/staged-quote.ts +18 -0
- package/src/schemas/generated/standalone-price.ts +32 -0
- package/src/schemas/generated/state.ts +20 -0
- package/src/schemas/generated/store.ts +23 -0
- package/src/schemas/generated/subscription.ts +20 -0
- package/src/schemas/generated/tax-category.ts +12 -0
- package/src/schemas/generated/type.ts +17 -0
- package/src/schemas/generated/zone.ts +12 -0
- package/src/schemas/update-request.ts +3 -5
- package/src/server.ts +32 -4
- package/src/services/abstract.ts +207 -101
- package/src/services/as-associate-cart.test.ts +28 -36
- package/src/services/as-associate-cart.ts +15 -12
- package/src/services/as-associate-order.test.ts +33 -40
- package/src/services/as-associate-order.ts +15 -12
- package/src/services/as-associate-quote-request.ts +15 -12
- package/src/services/as-associate-shopping-list.test.ts +25 -35
- package/src/services/as-associate-shopping-list.ts +15 -12
- package/src/services/as-associate.test.ts +21 -15
- package/src/services/as-associate.ts +23 -22
- package/src/services/associate-roles.test.ts +16 -22
- package/src/services/associate-roles.ts +2 -2
- package/src/services/attribute-group.test.ts +40 -44
- package/src/services/attribute-group.ts +2 -2
- package/src/services/business-units.test.ts +227 -163
- package/src/services/business-units.ts +2 -2
- package/src/services/cart-discount.test.ts +253 -187
- package/src/services/cart-discount.ts +2 -2
- package/src/services/cart.test.ts +833 -832
- package/src/services/cart.ts +31 -12
- package/src/services/category.test.ts +208 -130
- package/src/services/category.ts +2 -2
- package/src/services/channel.test.ts +39 -44
- package/src/services/channel.ts +2 -2
- package/src/services/custom-object.test.ts +103 -79
- package/src/services/custom-object.ts +106 -38
- package/src/services/customer-group.test.ts +39 -44
- package/src/services/customer-group.ts +2 -2
- package/src/services/customer.test.ts +357 -292
- package/src/services/customer.ts +70 -23
- package/src/services/discount-code.test.ts +57 -68
- package/src/services/discount-code.ts +2 -2
- package/src/services/discount-group.test.ts +111 -134
- package/src/services/discount-group.ts +2 -2
- package/src/services/draft-validation.test.ts +255 -0
- package/src/services/extension.test.ts +39 -44
- package/src/services/extension.ts +2 -2
- package/src/services/inventory-entry.test.ts +106 -87
- package/src/services/inventory-entry.ts +2 -2
- package/src/services/my-business-unit.test.ts +82 -112
- package/src/services/my-business-unit.ts +25 -19
- package/src/services/my-cart.test.ts +46 -41
- package/src/services/my-cart.ts +32 -28
- package/src/services/my-customer.test.ts +153 -88
- package/src/services/my-customer.ts +130 -61
- package/src/services/my-order.ts +15 -12
- package/src/services/my-payment.test.ts +30 -24
- package/src/services/my-payment.ts +2 -2
- package/src/services/my-shopping-list.ts +2 -2
- package/src/services/order.test.ts +332 -276
- package/src/services/order.ts +45 -27
- package/src/services/payment.test.ts +31 -29
- package/src/services/payment.ts +2 -2
- package/src/services/product-discount.test.ts +39 -46
- package/src/services/product-discount.ts +2 -2
- package/src/services/product-projection.test.ts +176 -166
- package/src/services/product-projection.ts +31 -15
- package/src/services/product-selection.test.ts +17 -9
- package/src/services/product-selection.ts +2 -2
- package/src/services/product-type.test.ts +80 -21
- package/src/services/product-type.ts +2 -2
- package/src/services/product.test.ts +569 -534
- package/src/services/product.ts +14 -7
- package/src/services/project.test.ts +22 -12
- package/src/services/project.ts +28 -13
- package/src/services/quote-request.test.ts +36 -39
- package/src/services/quote-request.ts +2 -2
- package/src/services/quote-staged.ts +2 -2
- package/src/services/quote.ts +2 -2
- package/src/services/recurrence-policy.test.ts +114 -139
- package/src/services/recurrence-policy.ts +2 -2
- package/src/services/recurring-order.test.ts +149 -194
- package/src/services/recurring-order.ts +2 -2
- package/src/services/reviews.test.ts +127 -106
- package/src/services/reviews.ts +2 -2
- package/src/services/shipping-method.test.ts +96 -125
- package/src/services/shipping-method.ts +24 -12
- package/src/services/shopping-list.test.ts +183 -141
- package/src/services/shopping-list.ts +2 -2
- package/src/services/standalone-price.test.ts +60 -46
- package/src/services/standalone-price.ts +2 -2
- package/src/services/state.test.ts +20 -25
- package/src/services/state.ts +2 -2
- package/src/services/store.test.ts +26 -45
- package/src/services/store.ts +2 -2
- package/src/services/subscription.test.ts +39 -44
- package/src/services/subscription.ts +2 -2
- package/src/services/tax-category.test.ts +33 -36
- package/src/services/tax-category.ts +2 -2
- package/src/services/type.test.ts +45 -44
- package/src/services/type.ts +2 -2
- package/src/services/zone.test.ts +40 -44
- package/src/services/zone.ts +2 -2
- package/src/shipping.ts +41 -11
- package/src/storage/abstract.ts +248 -17
- package/src/storage/in-memory.ts +147 -290
- package/src/storage/sqlite.ts +429 -0
- package/src/storage/storage-map.ts +75 -0
- package/src/storage/storage.test-helpers.ts +97 -0
- package/src/storage/storage.test.ts +802 -0
- package/src/testing/associate-role.ts +28 -0
- package/src/testing/attribute-group.ts +27 -0
- package/src/testing/business-unit.ts +9 -8
- package/src/testing/cart-discount.ts +34 -0
- package/src/testing/cart.ts +20 -0
- package/src/testing/category.ts +25 -0
- package/src/testing/channel.ts +23 -0
- package/src/testing/custom-object.ts +27 -0
- package/src/testing/customer-group.ts +26 -0
- package/src/testing/customer.ts +36 -33
- package/src/testing/discount-code.ts +29 -0
- package/src/testing/discount-group.ts +27 -0
- package/src/testing/extension.ts +32 -0
- package/src/testing/index.ts +33 -0
- package/src/testing/inventory-entry.ts +26 -0
- package/src/testing/order.ts +27 -0
- package/src/testing/payment.ts +23 -0
- package/src/testing/product-discount.ts +33 -0
- package/src/testing/product-selection.ts +28 -0
- package/src/testing/product-type.ts +27 -0
- package/src/testing/product.ts +38 -0
- package/src/testing/quote-request.ts +29 -0
- package/src/testing/recurrence-policy.ts +33 -0
- package/src/testing/recurring-order.ts +32 -0
- package/src/testing/review.ts +24 -0
- package/src/testing/shipping-method.ts +31 -0
- package/src/testing/shopping-list.ts +25 -0
- package/src/testing/standalone-price.ts +31 -0
- package/src/testing/state.ts +21 -0
- package/src/testing/store.ts +26 -0
- package/src/testing/subscription.ts +38 -0
- package/src/testing/tax-category.ts +27 -0
- package/src/testing/type.ts +9 -6
- package/src/testing/zone.ts +22 -0
- package/src/validate.test.ts +122 -0
- package/src/validate.ts +78 -7
- package/src/.env +0 -0
|
@@ -4,81 +4,79 @@ import type {
|
|
|
4
4
|
Cart,
|
|
5
5
|
CentPrecisionMoney,
|
|
6
6
|
HighPrecisionMoneyDraft,
|
|
7
|
-
ProductDraft,
|
|
8
7
|
ShippingMethod,
|
|
9
|
-
ShippingMethodDraft,
|
|
10
8
|
ShippingMethodResourceIdentifier,
|
|
11
9
|
TaxCategory,
|
|
12
|
-
TaxCategoryDraft,
|
|
13
|
-
Zone,
|
|
14
10
|
} from "@commercetools/platform-sdk";
|
|
15
|
-
import supertest from "supertest";
|
|
16
11
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
17
12
|
import { calculateMoneyTotalCentAmount } from "#src/repositories/helpers.ts";
|
|
18
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
cartDraftFactory,
|
|
15
|
+
customerDraftFactory,
|
|
16
|
+
productDraftFactory,
|
|
17
|
+
productTypeDraftFactory,
|
|
18
|
+
shippingMethodDraftFactory,
|
|
19
|
+
taxCategoryDraftFactory,
|
|
20
|
+
typeDraftFactory,
|
|
21
|
+
zoneDraftFactory,
|
|
22
|
+
} from "#src/testing/index.ts";
|
|
19
23
|
import { CommercetoolsMock } from "../index.ts";
|
|
20
24
|
|
|
21
25
|
describe("Carts Query", () => {
|
|
22
26
|
const ctMock = new CommercetoolsMock();
|
|
23
27
|
|
|
24
28
|
beforeEach(async () => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
.post("/dummy/types")
|
|
28
|
-
.send({
|
|
29
|
-
key: "my-cart",
|
|
30
|
-
name: {
|
|
31
|
-
en: "Test",
|
|
32
|
-
},
|
|
33
|
-
description: {
|
|
34
|
-
en: "Test Type",
|
|
35
|
-
},
|
|
36
|
-
resourceTypeIds: ["order"],
|
|
37
|
-
fieldDefinitions: [
|
|
38
|
-
{
|
|
39
|
-
name: "offer_name",
|
|
40
|
-
label: {
|
|
41
|
-
en: "offer_name",
|
|
42
|
-
},
|
|
43
|
-
required: false,
|
|
44
|
-
type: {
|
|
45
|
-
name: "String",
|
|
46
|
-
},
|
|
47
|
-
inputHint: "SingleLine",
|
|
48
|
-
},
|
|
49
|
-
],
|
|
50
|
-
});
|
|
51
|
-
expect(response.status).toBe(201);
|
|
29
|
+
const typeFactory = typeDraftFactory(ctMock);
|
|
30
|
+
const cartFactory = cartDraftFactory(ctMock);
|
|
52
31
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
32
|
+
await typeFactory.create({
|
|
33
|
+
key: "my-cart",
|
|
34
|
+
name: {
|
|
35
|
+
en: "Test",
|
|
36
|
+
},
|
|
37
|
+
description: {
|
|
38
|
+
en: "Test Type",
|
|
39
|
+
},
|
|
40
|
+
resourceTypeIds: ["order"],
|
|
41
|
+
fieldDefinitions: [
|
|
42
|
+
{
|
|
43
|
+
name: "offer_name",
|
|
44
|
+
label: {
|
|
45
|
+
en: "offer_name",
|
|
61
46
|
},
|
|
62
|
-
|
|
63
|
-
|
|
47
|
+
required: false,
|
|
48
|
+
type: {
|
|
49
|
+
name: "String",
|
|
64
50
|
},
|
|
51
|
+
inputHint: "SingleLine",
|
|
65
52
|
},
|
|
66
|
-
|
|
67
|
-
|
|
53
|
+
],
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
await cartFactory.create({
|
|
57
|
+
currency: "EUR",
|
|
58
|
+
custom: {
|
|
59
|
+
type: {
|
|
60
|
+
typeId: "type",
|
|
61
|
+
key: "my-cart",
|
|
62
|
+
},
|
|
63
|
+
fields: {
|
|
64
|
+
description: "example description",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
});
|
|
68
68
|
});
|
|
69
69
|
|
|
70
70
|
test("no filter", async () => {
|
|
71
|
-
const response = await
|
|
72
|
-
|
|
73
|
-
.
|
|
74
|
-
|
|
75
|
-
})
|
|
76
|
-
.send();
|
|
71
|
+
const response = await ctMock.app.inject({
|
|
72
|
+
method: "GET",
|
|
73
|
+
url: "/dummy/carts?expand=custom.type",
|
|
74
|
+
});
|
|
77
75
|
|
|
78
|
-
expect(response.
|
|
79
|
-
expect(response.
|
|
76
|
+
expect(response.statusCode).toBe(200);
|
|
77
|
+
expect(response.json().count).toBe(1);
|
|
80
78
|
|
|
81
|
-
const myCart = response.
|
|
79
|
+
const myCart = response.json().results[0] as Cart;
|
|
82
80
|
|
|
83
81
|
expect(myCart.custom?.type.id).not.toBeUndefined();
|
|
84
82
|
expect(myCart.custom?.type.id).toBe(myCart.custom?.type.obj?.id);
|
|
@@ -88,25 +86,33 @@ describe("Carts Query", () => {
|
|
|
88
86
|
test("throw error when anonymousId and customerId are given", async () => {
|
|
89
87
|
const customerId = "400be09e-bfe8-4925-a307-4ef6280b063e";
|
|
90
88
|
const anonymousId = "a99f27d1-7e7e-4592-8d5a-aa5da1adfe24";
|
|
91
|
-
const response = await
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
const response = await ctMock.app.inject({
|
|
90
|
+
method: "POST",
|
|
91
|
+
url: "/dummy/carts",
|
|
92
|
+
payload: {
|
|
93
|
+
currency: "EUR",
|
|
94
|
+
anonymousId,
|
|
95
|
+
customerId,
|
|
96
|
+
},
|
|
95
97
|
});
|
|
96
|
-
expect(response.
|
|
97
|
-
expect(response.
|
|
98
|
+
expect(response.statusCode).toBe(400);
|
|
99
|
+
expect(response.json().message).toBe(
|
|
98
100
|
"Can set only one of customer OR anonymousId",
|
|
99
101
|
);
|
|
100
102
|
});
|
|
101
103
|
|
|
102
104
|
test("create cart with existing customer", async () => {
|
|
103
105
|
const customer = await customerDraftFactory(ctMock).create();
|
|
104
|
-
const response = await
|
|
105
|
-
|
|
106
|
-
|
|
106
|
+
const response = await ctMock.app.inject({
|
|
107
|
+
method: "POST",
|
|
108
|
+
url: "/dummy/carts",
|
|
109
|
+
payload: {
|
|
110
|
+
currency: "EUR",
|
|
111
|
+
customerId: customer.id,
|
|
112
|
+
},
|
|
107
113
|
});
|
|
108
|
-
expect(response.
|
|
109
|
-
expect(response.
|
|
114
|
+
expect(response.statusCode).toBe(201);
|
|
115
|
+
expect(response.json().customerId).toBe(customer.id);
|
|
110
116
|
});
|
|
111
117
|
});
|
|
112
118
|
|
|
@@ -114,90 +120,33 @@ describe("Cart Update Actions", () => {
|
|
|
114
120
|
const ctMock = new CommercetoolsMock();
|
|
115
121
|
let cart: Cart | undefined;
|
|
116
122
|
let taxCategory: TaxCategory;
|
|
123
|
+
let productDraft: Parameters<
|
|
124
|
+
ReturnType<typeof productDraftFactory>["create"]
|
|
125
|
+
>[0];
|
|
117
126
|
|
|
118
|
-
const
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
cart = response.body;
|
|
125
|
-
};
|
|
127
|
+
const cartFactory = cartDraftFactory(ctMock);
|
|
128
|
+
const taxCategoryFactory = taxCategoryDraftFactory(ctMock);
|
|
129
|
+
const productFactory = productDraftFactory(ctMock);
|
|
130
|
+
const typeFactory = typeDraftFactory(ctMock);
|
|
131
|
+
const zoneFactory = zoneDraftFactory(ctMock);
|
|
132
|
+
const shippingMethodFactory = shippingMethodDraftFactory(ctMock);
|
|
126
133
|
|
|
127
|
-
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
locations: [
|
|
133
|
-
{
|
|
134
|
-
country,
|
|
135
|
-
},
|
|
136
|
-
],
|
|
137
|
-
});
|
|
138
|
-
expect(response.status).toBe(201);
|
|
139
|
-
return response.body;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
const createTaxCategory = async (
|
|
143
|
-
draft: TaxCategoryDraft,
|
|
144
|
-
): Promise<TaxCategory> => {
|
|
145
|
-
const response = await supertest(ctMock.app)
|
|
146
|
-
.post("/dummy/tax-categories")
|
|
147
|
-
.send(draft);
|
|
148
|
-
expect(response.status).toBe(201);
|
|
149
|
-
return response.body;
|
|
150
|
-
};
|
|
151
|
-
|
|
152
|
-
const createShippingMethod = async (
|
|
153
|
-
draft: ShippingMethodDraft,
|
|
154
|
-
): Promise<ShippingMethod> => {
|
|
155
|
-
const response = await supertest(ctMock.app)
|
|
156
|
-
.post("/dummy/shipping-methods")
|
|
157
|
-
.send(draft);
|
|
158
|
-
expect(response.status).toBe(201);
|
|
159
|
-
return response.body;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
const productDraft: ProductDraft = {
|
|
163
|
-
name: {
|
|
164
|
-
"nl-NL": "test product",
|
|
165
|
-
},
|
|
166
|
-
productType: {
|
|
167
|
-
typeId: "product-type",
|
|
168
|
-
id: "some-uuid",
|
|
169
|
-
},
|
|
170
|
-
masterVariant: {
|
|
171
|
-
sku: "1337",
|
|
172
|
-
prices: [
|
|
173
|
-
{
|
|
174
|
-
value: {
|
|
175
|
-
type: "centPrecision",
|
|
176
|
-
currencyCode: "EUR",
|
|
177
|
-
centAmount: 14900,
|
|
178
|
-
fractionDigits: 2,
|
|
179
|
-
} as CentPrecisionMoney,
|
|
180
|
-
},
|
|
181
|
-
{
|
|
182
|
-
value: {
|
|
183
|
-
type: "centPrecision",
|
|
184
|
-
currencyCode: "GBP",
|
|
185
|
-
centAmount: 18900,
|
|
186
|
-
fractionDigits: 2,
|
|
187
|
-
} as CentPrecisionMoney,
|
|
188
|
-
},
|
|
189
|
-
],
|
|
134
|
+
beforeEach(async () => {
|
|
135
|
+
const productType = await productTypeDraftFactory(ctMock).create({
|
|
136
|
+
name: "Test Product Type",
|
|
137
|
+
description: "Product type for cart tests",
|
|
138
|
+
});
|
|
190
139
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
{
|
|
200
|
-
sku: "
|
|
140
|
+
productDraft = {
|
|
141
|
+
name: {
|
|
142
|
+
"nl-NL": "test product",
|
|
143
|
+
},
|
|
144
|
+
productType: {
|
|
145
|
+
typeId: "product-type" as const,
|
|
146
|
+
id: productType.id,
|
|
147
|
+
},
|
|
148
|
+
masterVariant: {
|
|
149
|
+
sku: "1337",
|
|
201
150
|
prices: [
|
|
202
151
|
{
|
|
203
152
|
value: {
|
|
@@ -207,24 +156,55 @@ describe("Cart Update Actions", () => {
|
|
|
207
156
|
fractionDigits: 2,
|
|
208
157
|
} as CentPrecisionMoney,
|
|
209
158
|
},
|
|
159
|
+
{
|
|
160
|
+
value: {
|
|
161
|
+
type: "centPrecision",
|
|
162
|
+
currencyCode: "GBP",
|
|
163
|
+
centAmount: 18900,
|
|
164
|
+
fractionDigits: 2,
|
|
165
|
+
} as CentPrecisionMoney,
|
|
166
|
+
},
|
|
210
167
|
],
|
|
168
|
+
|
|
211
169
|
attributes: [
|
|
212
170
|
{
|
|
213
|
-
name: "
|
|
214
|
-
value: "
|
|
171
|
+
name: "test",
|
|
172
|
+
value: "test",
|
|
215
173
|
},
|
|
216
174
|
],
|
|
217
175
|
},
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
176
|
+
variants: [
|
|
177
|
+
{
|
|
178
|
+
sku: "1338",
|
|
179
|
+
prices: [
|
|
180
|
+
{
|
|
181
|
+
value: {
|
|
182
|
+
type: "centPrecision",
|
|
183
|
+
currencyCode: "EUR",
|
|
184
|
+
centAmount: 14900,
|
|
185
|
+
fractionDigits: 2,
|
|
186
|
+
} as CentPrecisionMoney,
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
attributes: [
|
|
190
|
+
{
|
|
191
|
+
name: "test2",
|
|
192
|
+
value: "test2",
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
},
|
|
196
|
+
],
|
|
197
|
+
slug: {
|
|
198
|
+
"nl-NL": "test-product",
|
|
199
|
+
},
|
|
200
|
+
publish: true,
|
|
201
|
+
};
|
|
224
202
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
203
|
+
cart = await cartFactory.create({
|
|
204
|
+
currency: "EUR",
|
|
205
|
+
country: "NL",
|
|
206
|
+
});
|
|
207
|
+
taxCategory = await taxCategoryFactory.create({
|
|
228
208
|
name: "Standard VAT",
|
|
229
209
|
key: "standard-vat",
|
|
230
210
|
rates: [
|
|
@@ -245,39 +225,41 @@ describe("Cart Update Actions", () => {
|
|
|
245
225
|
test("no update", async () => {
|
|
246
226
|
assert(cart, "cart not created");
|
|
247
227
|
|
|
248
|
-
const response = await
|
|
249
|
-
|
|
250
|
-
.
|
|
228
|
+
const response = await ctMock.app.inject({
|
|
229
|
+
method: "POST",
|
|
230
|
+
url: `/dummy/carts/${cart.id}`,
|
|
231
|
+
payload: {
|
|
251
232
|
version: 1,
|
|
252
233
|
actions: [{ action: "setLocale", locale: "nl-NL" }],
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
expect(response.
|
|
256
|
-
expect(response.
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
234
|
+
},
|
|
235
|
+
});
|
|
236
|
+
expect(response.statusCode).toBe(200);
|
|
237
|
+
expect(response.json().version).toBe(2);
|
|
238
|
+
expect(response.json().locale).toBe("nl-NL");
|
|
239
|
+
|
|
240
|
+
const responseAgain = await ctMock.app.inject({
|
|
241
|
+
method: "POST",
|
|
242
|
+
url: `/dummy/carts/${cart.id}`,
|
|
243
|
+
payload: {
|
|
261
244
|
version: 2,
|
|
262
245
|
actions: [{ action: "setLocale", locale: "nl-NL" }],
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
expect(responseAgain.
|
|
266
|
-
expect(responseAgain.
|
|
246
|
+
},
|
|
247
|
+
});
|
|
248
|
+
expect(responseAgain.statusCode).toBe(200);
|
|
249
|
+
expect(responseAgain.json().version).toBe(2);
|
|
250
|
+
expect(responseAgain.json().locale).toBe("nl-NL");
|
|
267
251
|
});
|
|
268
252
|
|
|
269
253
|
test("addLineItem", async () => {
|
|
270
|
-
const product = await
|
|
271
|
-
.post("/dummy/products")
|
|
272
|
-
.send(productDraft)
|
|
273
|
-
.then((x) => x.body);
|
|
254
|
+
const product = await productFactory.create(productDraft);
|
|
274
255
|
|
|
275
256
|
assert(cart, "cart not created");
|
|
276
257
|
assert(product, "product not created");
|
|
277
258
|
|
|
278
|
-
const response = await
|
|
279
|
-
|
|
280
|
-
.
|
|
259
|
+
const response = await ctMock.app.inject({
|
|
260
|
+
method: "POST",
|
|
261
|
+
url: `/dummy/carts/${cart.id}`,
|
|
262
|
+
payload: {
|
|
281
263
|
version: 1,
|
|
282
264
|
actions: [
|
|
283
265
|
{
|
|
@@ -286,100 +268,99 @@ describe("Cart Update Actions", () => {
|
|
|
286
268
|
variantId: product.masterData.current.variants[0].id,
|
|
287
269
|
},
|
|
288
270
|
],
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
expect(response.
|
|
292
|
-
expect(response.
|
|
293
|
-
expect(response.
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
expect(response.statusCode).toBe(200);
|
|
274
|
+
expect(response.json().version).toBe(2);
|
|
275
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
276
|
+
expect(response.json().totalPrice.centAmount).toEqual(14900);
|
|
294
277
|
});
|
|
295
278
|
|
|
296
279
|
test("addLineItem by SKU", async () => {
|
|
297
|
-
const product = await
|
|
298
|
-
.post("/dummy/products")
|
|
299
|
-
.send(productDraft)
|
|
300
|
-
.then((x) => x.body);
|
|
280
|
+
const product = await productFactory.create(productDraft);
|
|
301
281
|
|
|
302
282
|
assert(cart, "cart not created");
|
|
303
283
|
assert(product, "product not created");
|
|
304
284
|
|
|
305
|
-
const response = await
|
|
306
|
-
|
|
307
|
-
.
|
|
285
|
+
const response = await ctMock.app.inject({
|
|
286
|
+
method: "POST",
|
|
287
|
+
url: `/dummy/carts/${cart.id}`,
|
|
288
|
+
payload: {
|
|
308
289
|
version: 1,
|
|
309
290
|
actions: [{ action: "addLineItem", sku: "1337", quantity: 2 }],
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
expect(response.
|
|
313
|
-
expect(response.
|
|
314
|
-
expect(response.
|
|
291
|
+
},
|
|
292
|
+
});
|
|
293
|
+
expect(response.statusCode).toBe(200);
|
|
294
|
+
expect(response.json().version).toBe(2);
|
|
295
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
296
|
+
expect(response.json().totalPrice.centAmount).toEqual(29800);
|
|
315
297
|
});
|
|
316
298
|
|
|
317
299
|
test.each([
|
|
318
300
|
["EUR", 29800],
|
|
319
301
|
["GBP", 37800],
|
|
320
302
|
])("addLineItem with price selection", async (currency, total) => {
|
|
321
|
-
await
|
|
303
|
+
cart = await cartFactory.create({
|
|
304
|
+
currency,
|
|
305
|
+
country: "NL",
|
|
306
|
+
});
|
|
322
307
|
|
|
323
|
-
const product = await
|
|
324
|
-
.post("/dummy/products")
|
|
325
|
-
.send(productDraft)
|
|
326
|
-
.then((x) => x.body);
|
|
308
|
+
const product = await productFactory.create(productDraft);
|
|
327
309
|
|
|
328
310
|
assert(cart, "cart not created");
|
|
329
311
|
assert(product, "product not created");
|
|
330
312
|
|
|
331
|
-
const response = await
|
|
332
|
-
|
|
333
|
-
.
|
|
313
|
+
const response = await ctMock.app.inject({
|
|
314
|
+
method: "POST",
|
|
315
|
+
url: `/dummy/carts/${cart.id}`,
|
|
316
|
+
payload: {
|
|
334
317
|
version: 1,
|
|
335
318
|
actions: [{ action: "addLineItem", sku: "1337", quantity: 2 }],
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
expect(response.
|
|
339
|
-
expect(response.
|
|
340
|
-
expect(response.
|
|
341
|
-
expect(response.
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
expect(response.statusCode).toBe(200);
|
|
322
|
+
expect(response.json().version).toBe(2);
|
|
323
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
324
|
+
expect(response.json().lineItems[0].price.value.currencyCode).toBe(
|
|
325
|
+
currency,
|
|
326
|
+
);
|
|
327
|
+
expect(response.json().totalPrice.centAmount).toEqual(total);
|
|
342
328
|
});
|
|
343
329
|
|
|
344
330
|
test("addLineItem with custom field", async () => {
|
|
345
|
-
const product = await
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
fieldDefinitions: [
|
|
361
|
-
{
|
|
362
|
-
name: "foo",
|
|
363
|
-
label: {
|
|
364
|
-
en: "foo",
|
|
365
|
-
},
|
|
366
|
-
required: false,
|
|
367
|
-
type: {
|
|
368
|
-
name: "String",
|
|
369
|
-
},
|
|
370
|
-
inputHint: "SingleLine",
|
|
331
|
+
const product = await productFactory.create(productDraft);
|
|
332
|
+
|
|
333
|
+
const type = await typeFactory.create({
|
|
334
|
+
key: "my-type",
|
|
335
|
+
name: {
|
|
336
|
+
en: "My Type",
|
|
337
|
+
},
|
|
338
|
+
description: {
|
|
339
|
+
en: "My Type Description",
|
|
340
|
+
},
|
|
341
|
+
fieldDefinitions: [
|
|
342
|
+
{
|
|
343
|
+
name: "foo",
|
|
344
|
+
label: {
|
|
345
|
+
en: "foo",
|
|
371
346
|
},
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
347
|
+
required: false,
|
|
348
|
+
type: {
|
|
349
|
+
name: "String",
|
|
350
|
+
},
|
|
351
|
+
inputHint: "SingleLine",
|
|
352
|
+
},
|
|
353
|
+
],
|
|
354
|
+
});
|
|
375
355
|
|
|
376
356
|
assert(type, "type not created");
|
|
377
357
|
assert(cart, "cart not created");
|
|
378
358
|
assert(product, "product not created");
|
|
379
359
|
|
|
380
|
-
const response = await
|
|
381
|
-
|
|
382
|
-
.
|
|
360
|
+
const response = await ctMock.app.inject({
|
|
361
|
+
method: "POST",
|
|
362
|
+
url: `/dummy/carts/${cart.id}`,
|
|
363
|
+
payload: {
|
|
383
364
|
version: 1,
|
|
384
365
|
actions: [
|
|
385
366
|
{
|
|
@@ -392,55 +373,51 @@ describe("Cart Update Actions", () => {
|
|
|
392
373
|
},
|
|
393
374
|
},
|
|
394
375
|
],
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
expect(response.
|
|
398
|
-
expect(response.
|
|
399
|
-
expect(response.
|
|
376
|
+
},
|
|
377
|
+
});
|
|
378
|
+
expect(response.statusCode).toBe(200);
|
|
379
|
+
expect(response.json().version).toBe(2);
|
|
380
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
381
|
+
expect(response.json().lineItems[0].custom).toEqual({
|
|
400
382
|
type: { typeId: "type", id: expect.any(String) },
|
|
401
383
|
fields: { foo: "bar" },
|
|
402
384
|
});
|
|
403
385
|
});
|
|
404
386
|
|
|
405
387
|
test("addLineItem with key", async () => {
|
|
406
|
-
const product = await
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
fieldDefinitions: [
|
|
422
|
-
{
|
|
423
|
-
name: "foo",
|
|
424
|
-
label: {
|
|
425
|
-
en: "foo",
|
|
426
|
-
},
|
|
427
|
-
required: false,
|
|
428
|
-
type: {
|
|
429
|
-
name: "String",
|
|
430
|
-
},
|
|
431
|
-
inputHint: "SingleLine",
|
|
388
|
+
const product = await productFactory.create(productDraft);
|
|
389
|
+
|
|
390
|
+
const type = await typeFactory.create({
|
|
391
|
+
key: "my-type",
|
|
392
|
+
name: {
|
|
393
|
+
en: "My Type",
|
|
394
|
+
},
|
|
395
|
+
description: {
|
|
396
|
+
en: "My Type Description",
|
|
397
|
+
},
|
|
398
|
+
fieldDefinitions: [
|
|
399
|
+
{
|
|
400
|
+
name: "foo",
|
|
401
|
+
label: {
|
|
402
|
+
en: "foo",
|
|
432
403
|
},
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
404
|
+
required: false,
|
|
405
|
+
type: {
|
|
406
|
+
name: "String",
|
|
407
|
+
},
|
|
408
|
+
inputHint: "SingleLine",
|
|
409
|
+
},
|
|
410
|
+
],
|
|
411
|
+
});
|
|
436
412
|
|
|
437
413
|
assert(type, "type not created");
|
|
438
414
|
assert(cart, "cart not created");
|
|
439
415
|
assert(product, "product not created");
|
|
440
416
|
|
|
441
|
-
const response = await
|
|
442
|
-
|
|
443
|
-
.
|
|
417
|
+
const response = await ctMock.app.inject({
|
|
418
|
+
method: "POST",
|
|
419
|
+
url: `/dummy/carts/${cart.id}`,
|
|
420
|
+
payload: {
|
|
444
421
|
version: 1,
|
|
445
422
|
actions: [
|
|
446
423
|
{
|
|
@@ -454,38 +431,39 @@ describe("Cart Update Actions", () => {
|
|
|
454
431
|
},
|
|
455
432
|
},
|
|
456
433
|
],
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
expect(response.
|
|
460
|
-
expect(response.
|
|
461
|
-
expect(response.
|
|
462
|
-
expect(response.
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
expect(response.statusCode).toBe(200);
|
|
437
|
+
expect(response.json().version).toBe(2);
|
|
438
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
439
|
+
expect(response.json().lineItems[0].key).toBeDefined();
|
|
440
|
+
expect(response.json().lineItems[0].key).toBe("my-key");
|
|
463
441
|
});
|
|
464
442
|
|
|
465
443
|
test("addLineItem unknown product", async () => {
|
|
466
444
|
assert(cart, "cart not created");
|
|
467
445
|
|
|
468
|
-
const response = await
|
|
469
|
-
|
|
470
|
-
.
|
|
446
|
+
const response = await ctMock.app.inject({
|
|
447
|
+
method: "POST",
|
|
448
|
+
url: `/dummy/carts/${cart.id}`,
|
|
449
|
+
payload: {
|
|
471
450
|
version: 1,
|
|
472
451
|
actions: [{ action: "addLineItem", productId: "123", variantId: 1 }],
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
expect(response.
|
|
452
|
+
},
|
|
453
|
+
});
|
|
454
|
+
expect(response.statusCode).toBe(400);
|
|
455
|
+
expect(response.json().message).toBe("A product with ID '123' not found.");
|
|
476
456
|
});
|
|
477
457
|
|
|
478
458
|
test("addItemShippingAddress", async () => {
|
|
479
|
-
await
|
|
480
|
-
.post("/dummy/products")
|
|
481
|
-
.send(productDraft)
|
|
482
|
-
.then((x) => x.body);
|
|
459
|
+
await productFactory.create(productDraft);
|
|
483
460
|
|
|
484
461
|
assert(cart, "cart not created");
|
|
485
462
|
|
|
486
|
-
const response = await
|
|
487
|
-
|
|
488
|
-
.
|
|
463
|
+
const response = await ctMock.app.inject({
|
|
464
|
+
method: "POST",
|
|
465
|
+
url: `/dummy/carts/${cart.id}`,
|
|
466
|
+
payload: {
|
|
489
467
|
version: 1,
|
|
490
468
|
actions: [
|
|
491
469
|
{
|
|
@@ -498,20 +476,22 @@ describe("Cart Update Actions", () => {
|
|
|
498
476
|
},
|
|
499
477
|
},
|
|
500
478
|
],
|
|
501
|
-
}
|
|
479
|
+
},
|
|
480
|
+
});
|
|
502
481
|
|
|
503
|
-
expect(response.
|
|
504
|
-
expect(response.
|
|
505
|
-
expect(response.
|
|
506
|
-
expect(response.
|
|
482
|
+
expect(response.json().itemShippingAddresses).toHaveLength(1);
|
|
483
|
+
expect(response.statusCode).toBe(200);
|
|
484
|
+
expect(response.json().version).toBe(2);
|
|
485
|
+
expect(response.json().lineItems).toHaveLength(0);
|
|
507
486
|
});
|
|
508
487
|
|
|
509
488
|
test("changeTaxRoundingMode", async () => {
|
|
510
489
|
assert(cart, "cart not created");
|
|
511
490
|
|
|
512
|
-
const response = await
|
|
513
|
-
|
|
514
|
-
.
|
|
491
|
+
const response = await ctMock.app.inject({
|
|
492
|
+
method: "POST",
|
|
493
|
+
url: `/dummy/carts/${cart.id}`,
|
|
494
|
+
payload: {
|
|
515
495
|
version: 1,
|
|
516
496
|
actions: [
|
|
517
497
|
{
|
|
@@ -519,24 +499,23 @@ describe("Cart Update Actions", () => {
|
|
|
519
499
|
taxRoundingMode: "HalfUp",
|
|
520
500
|
},
|
|
521
501
|
],
|
|
522
|
-
}
|
|
502
|
+
},
|
|
503
|
+
});
|
|
523
504
|
|
|
524
|
-
expect(response.
|
|
525
|
-
expect(response.
|
|
526
|
-
expect(response.
|
|
505
|
+
expect(response.statusCode).toBe(200);
|
|
506
|
+
expect(response.json().version).toBe(2);
|
|
507
|
+
expect(response.json().taxRoundingMode).toBe("HalfUp");
|
|
527
508
|
});
|
|
528
509
|
|
|
529
510
|
test("recalculate", async () => {
|
|
530
|
-
await
|
|
531
|
-
.post("/dummy/products")
|
|
532
|
-
.send(productDraft)
|
|
533
|
-
.then((x) => x.body);
|
|
511
|
+
await productFactory.create(productDraft);
|
|
534
512
|
|
|
535
513
|
assert(cart, "cart not created");
|
|
536
514
|
|
|
537
|
-
const response = await
|
|
538
|
-
|
|
539
|
-
.
|
|
515
|
+
const response = await ctMock.app.inject({
|
|
516
|
+
method: "POST",
|
|
517
|
+
url: `/dummy/carts/${cart.id}`,
|
|
518
|
+
payload: {
|
|
540
519
|
version: 1,
|
|
541
520
|
actions: [
|
|
542
521
|
{
|
|
@@ -544,24 +523,23 @@ describe("Cart Update Actions", () => {
|
|
|
544
523
|
updateProductData: true,
|
|
545
524
|
},
|
|
546
525
|
],
|
|
547
|
-
}
|
|
526
|
+
},
|
|
527
|
+
});
|
|
548
528
|
|
|
549
|
-
expect(response.
|
|
550
|
-
expect(response.
|
|
529
|
+
expect(response.statusCode).toBe(200);
|
|
530
|
+
expect(response.json().version).toBe(1);
|
|
551
531
|
});
|
|
552
532
|
|
|
553
533
|
test("removeLineItem", async () => {
|
|
554
|
-
const product = await
|
|
555
|
-
.post("/dummy/products")
|
|
556
|
-
.send(productDraft)
|
|
557
|
-
.then((x) => x.body);
|
|
534
|
+
const product = await productFactory.create(productDraft);
|
|
558
535
|
|
|
559
536
|
assert(cart, "cart not created");
|
|
560
537
|
assert(product, "product not created");
|
|
561
538
|
|
|
562
|
-
const updatedCart = await
|
|
563
|
-
|
|
564
|
-
.
|
|
539
|
+
const updatedCart = await ctMock.app.inject({
|
|
540
|
+
method: "POST",
|
|
541
|
+
url: `/dummy/carts/${cart.id}`,
|
|
542
|
+
payload: {
|
|
565
543
|
version: 1,
|
|
566
544
|
actions: [
|
|
567
545
|
{
|
|
@@ -570,35 +548,36 @@ describe("Cart Update Actions", () => {
|
|
|
570
548
|
variantId: product.masterData.current.variants[0].id,
|
|
571
549
|
},
|
|
572
550
|
],
|
|
573
|
-
}
|
|
574
|
-
|
|
551
|
+
},
|
|
552
|
+
});
|
|
553
|
+
const lineItem = updatedCart.json().lineItems[0];
|
|
575
554
|
assert(lineItem, "lineItem not created");
|
|
576
555
|
|
|
577
|
-
expect(updatedCart.
|
|
556
|
+
expect(updatedCart.json().lineItems).toHaveLength(1);
|
|
578
557
|
|
|
579
|
-
const response = await
|
|
580
|
-
|
|
581
|
-
.
|
|
582
|
-
|
|
558
|
+
const response = await ctMock.app.inject({
|
|
559
|
+
method: "POST",
|
|
560
|
+
url: `/dummy/carts/${cart.id}`,
|
|
561
|
+
payload: {
|
|
562
|
+
version: updatedCart.json().version,
|
|
583
563
|
actions: [{ action: "removeLineItem", lineItemId: lineItem.id }],
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
expect(response.
|
|
587
|
-
expect(response.
|
|
564
|
+
},
|
|
565
|
+
});
|
|
566
|
+
expect(response.statusCode).toBe(200);
|
|
567
|
+
expect(response.json().version).toBe(3);
|
|
568
|
+
expect(response.json().lineItems).toHaveLength(0);
|
|
588
569
|
});
|
|
589
570
|
|
|
590
571
|
test("removeLineItem decrease quantity", async () => {
|
|
591
|
-
const product = await
|
|
592
|
-
.post("/dummy/products")
|
|
593
|
-
.send(productDraft)
|
|
594
|
-
.then((x) => x.body);
|
|
572
|
+
const product = await productFactory.create(productDraft);
|
|
595
573
|
|
|
596
574
|
assert(cart, "cart not created");
|
|
597
575
|
assert(product, "product not created");
|
|
598
576
|
|
|
599
|
-
const updatedCart = await
|
|
600
|
-
|
|
601
|
-
.
|
|
577
|
+
const updatedCart = await ctMock.app.inject({
|
|
578
|
+
method: "POST",
|
|
579
|
+
url: `/dummy/carts/${cart.id}`,
|
|
580
|
+
payload: {
|
|
602
581
|
version: 1,
|
|
603
582
|
actions: [
|
|
604
583
|
{
|
|
@@ -608,25 +587,28 @@ describe("Cart Update Actions", () => {
|
|
|
608
587
|
quantity: 2,
|
|
609
588
|
},
|
|
610
589
|
],
|
|
611
|
-
}
|
|
612
|
-
|
|
590
|
+
},
|
|
591
|
+
});
|
|
592
|
+
const lineItem = updatedCart.json().lineItems[0];
|
|
613
593
|
assert(lineItem, "lineItem not created");
|
|
614
594
|
|
|
615
|
-
expect(updatedCart.
|
|
616
|
-
expect(updatedCart.
|
|
595
|
+
expect(updatedCart.json().lineItems).toHaveLength(1);
|
|
596
|
+
expect(updatedCart.json().lineItems[0].quantity).toBe(2);
|
|
617
597
|
|
|
618
|
-
const response = await
|
|
619
|
-
|
|
620
|
-
.
|
|
621
|
-
|
|
598
|
+
const response = await ctMock.app.inject({
|
|
599
|
+
method: "POST",
|
|
600
|
+
url: `/dummy/carts/${cart.id}`,
|
|
601
|
+
payload: {
|
|
602
|
+
version: updatedCart.json().version,
|
|
622
603
|
actions: [
|
|
623
604
|
{ action: "removeLineItem", lineItemId: lineItem.id, quantity: 1 },
|
|
624
605
|
],
|
|
625
|
-
}
|
|
626
|
-
|
|
627
|
-
expect(response.
|
|
628
|
-
expect(response.
|
|
629
|
-
expect(response.
|
|
606
|
+
},
|
|
607
|
+
});
|
|
608
|
+
expect(response.statusCode).toBe(200);
|
|
609
|
+
expect(response.json().version).toBe(3);
|
|
610
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
611
|
+
expect(response.json().lineItems[0].quantity).toBe(1);
|
|
630
612
|
});
|
|
631
613
|
|
|
632
614
|
test("setBillingAddress", async () => {
|
|
@@ -638,15 +620,17 @@ describe("Cart Update Actions", () => {
|
|
|
638
620
|
country: "NL",
|
|
639
621
|
};
|
|
640
622
|
|
|
641
|
-
const response = await
|
|
642
|
-
|
|
643
|
-
.
|
|
623
|
+
const response = await ctMock.app.inject({
|
|
624
|
+
method: "POST",
|
|
625
|
+
url: `/dummy/carts/${cart.id}`,
|
|
626
|
+
payload: {
|
|
644
627
|
version: 1,
|
|
645
628
|
actions: [{ action: "setBillingAddress", address }],
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
expect(response.
|
|
649
|
-
expect(response.
|
|
629
|
+
},
|
|
630
|
+
});
|
|
631
|
+
expect(response.statusCode).toBe(200);
|
|
632
|
+
expect(response.json().version).toBe(2);
|
|
633
|
+
expect(response.json().billingAddress).toEqual({
|
|
650
634
|
...address,
|
|
651
635
|
id: expect.any(String),
|
|
652
636
|
});
|
|
@@ -655,23 +639,26 @@ describe("Cart Update Actions", () => {
|
|
|
655
639
|
test("setCountry", async () => {
|
|
656
640
|
assert(cart, "cart not created");
|
|
657
641
|
|
|
658
|
-
const response = await
|
|
659
|
-
|
|
660
|
-
.
|
|
642
|
+
const response = await ctMock.app.inject({
|
|
643
|
+
method: "POST",
|
|
644
|
+
url: `/dummy/carts/${cart.id}`,
|
|
645
|
+
payload: {
|
|
661
646
|
version: 1,
|
|
662
647
|
actions: [{ action: "setCountry", country: "BE" }],
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
expect(response.
|
|
666
|
-
expect(response.
|
|
648
|
+
},
|
|
649
|
+
});
|
|
650
|
+
expect(response.statusCode).toBe(200);
|
|
651
|
+
expect(response.json().version).toBe(2);
|
|
652
|
+
expect(response.json().country).toBe("BE");
|
|
667
653
|
});
|
|
668
654
|
|
|
669
655
|
test("setDirectDiscounts", async () => {
|
|
670
656
|
assert(cart, "cart not created");
|
|
671
657
|
|
|
672
|
-
const response = await
|
|
673
|
-
|
|
674
|
-
.
|
|
658
|
+
const response = await ctMock.app.inject({
|
|
659
|
+
method: "POST",
|
|
660
|
+
url: `/dummy/carts/${cart.id}`,
|
|
661
|
+
payload: {
|
|
675
662
|
version: 1,
|
|
676
663
|
actions: [
|
|
677
664
|
{
|
|
@@ -694,10 +681,11 @@ describe("Cart Update Actions", () => {
|
|
|
694
681
|
],
|
|
695
682
|
},
|
|
696
683
|
],
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
expect(response.
|
|
700
|
-
expect(response.
|
|
684
|
+
},
|
|
685
|
+
});
|
|
686
|
+
expect(response.statusCode).toBe(200);
|
|
687
|
+
expect(response.json().version).toBe(2);
|
|
688
|
+
expect(response.json().directDiscounts).toMatchObject([
|
|
701
689
|
{
|
|
702
690
|
id: expect.any(String),
|
|
703
691
|
target: { type: "totalPrice" },
|
|
@@ -717,22 +705,16 @@ describe("Cart Update Actions", () => {
|
|
|
717
705
|
});
|
|
718
706
|
|
|
719
707
|
test("setLineItemPrice sets an external price for a line item", async () => {
|
|
720
|
-
const product = await
|
|
721
|
-
.post("/dummy/products")
|
|
722
|
-
.send(productDraft)
|
|
723
|
-
.then((x) => x.body);
|
|
708
|
+
const product = await productFactory.create(productDraft);
|
|
724
709
|
|
|
725
710
|
assert(product, "product not created");
|
|
726
711
|
|
|
727
|
-
const
|
|
728
|
-
.post("/dummy/carts")
|
|
729
|
-
.send({ currency: "EUR" });
|
|
730
|
-
expect(baseCartResponse.status).toBe(201);
|
|
731
|
-
const baseCart = baseCartResponse.body as Cart;
|
|
712
|
+
const baseCart = await cartFactory.create({ currency: "EUR" });
|
|
732
713
|
|
|
733
|
-
const addLineItemResponse = await
|
|
734
|
-
|
|
735
|
-
.
|
|
714
|
+
const addLineItemResponse = await ctMock.app.inject({
|
|
715
|
+
method: "POST",
|
|
716
|
+
url: `/dummy/carts/${baseCart.id}`,
|
|
717
|
+
payload: {
|
|
736
718
|
version: baseCart.version,
|
|
737
719
|
actions: [
|
|
738
720
|
{
|
|
@@ -742,9 +724,10 @@ describe("Cart Update Actions", () => {
|
|
|
742
724
|
key: "line-item-key",
|
|
743
725
|
},
|
|
744
726
|
],
|
|
745
|
-
}
|
|
746
|
-
|
|
747
|
-
|
|
727
|
+
},
|
|
728
|
+
});
|
|
729
|
+
expect(addLineItemResponse.statusCode).toBe(200);
|
|
730
|
+
const cartWithLineItem = addLineItemResponse.json() as Cart;
|
|
748
731
|
const lineItem = cartWithLineItem.lineItems[0];
|
|
749
732
|
assert(lineItem, "lineItem not created");
|
|
750
733
|
|
|
@@ -755,9 +738,10 @@ describe("Cart Update Actions", () => {
|
|
|
755
738
|
fractionDigits: 2,
|
|
756
739
|
};
|
|
757
740
|
|
|
758
|
-
const response = await
|
|
759
|
-
|
|
760
|
-
.
|
|
741
|
+
const response = await ctMock.app.inject({
|
|
742
|
+
method: "POST",
|
|
743
|
+
url: `/dummy/carts/${cartWithLineItem.id}`,
|
|
744
|
+
payload: {
|
|
761
745
|
version: cartWithLineItem.version,
|
|
762
746
|
actions: [
|
|
763
747
|
{
|
|
@@ -766,13 +750,14 @@ describe("Cart Update Actions", () => {
|
|
|
766
750
|
externalPrice,
|
|
767
751
|
},
|
|
768
752
|
],
|
|
769
|
-
}
|
|
753
|
+
},
|
|
754
|
+
});
|
|
770
755
|
|
|
771
|
-
expect(response.
|
|
772
|
-
expect(response.
|
|
773
|
-
expect(response.
|
|
756
|
+
expect(response.statusCode).toBe(200);
|
|
757
|
+
expect(response.json().version).toBe(cartWithLineItem.version + 1);
|
|
758
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
774
759
|
|
|
775
|
-
const updatedLineItem = response.
|
|
760
|
+
const updatedLineItem = response.json().lineItems[0];
|
|
776
761
|
expect(updatedLineItem.priceMode).toBe("ExternalPrice");
|
|
777
762
|
expect(updatedLineItem.price.value.centAmount).toBe(
|
|
778
763
|
externalPrice.centAmount,
|
|
@@ -783,28 +768,22 @@ describe("Cart Update Actions", () => {
|
|
|
783
768
|
expect(updatedLineItem.totalPrice.centAmount).toBe(
|
|
784
769
|
externalPrice.centAmount * updatedLineItem.quantity,
|
|
785
770
|
);
|
|
786
|
-
expect(response.
|
|
771
|
+
expect(response.json().totalPrice.centAmount).toBe(
|
|
787
772
|
externalPrice.centAmount * updatedLineItem.quantity,
|
|
788
773
|
);
|
|
789
774
|
});
|
|
790
775
|
|
|
791
776
|
test("setLineItemPrice supports high precision external price", async () => {
|
|
792
|
-
const product = await
|
|
793
|
-
.post("/dummy/products")
|
|
794
|
-
.send(productDraft)
|
|
795
|
-
.then((x) => x.body);
|
|
777
|
+
const product = await productFactory.create(productDraft);
|
|
796
778
|
|
|
797
779
|
assert(product, "product not created");
|
|
798
780
|
|
|
799
|
-
const
|
|
800
|
-
.post("/dummy/carts")
|
|
801
|
-
.send({ currency: "EUR" });
|
|
802
|
-
expect(baseCartResponse.status).toBe(201);
|
|
803
|
-
const baseCart = baseCartResponse.body as Cart;
|
|
781
|
+
const baseCart = await cartFactory.create({ currency: "EUR" });
|
|
804
782
|
|
|
805
|
-
const addLineItemResponse = await
|
|
806
|
-
|
|
807
|
-
.
|
|
783
|
+
const addLineItemResponse = await ctMock.app.inject({
|
|
784
|
+
method: "POST",
|
|
785
|
+
url: `/dummy/carts/${baseCart.id}`,
|
|
786
|
+
payload: {
|
|
808
787
|
version: baseCart.version,
|
|
809
788
|
actions: [
|
|
810
789
|
{
|
|
@@ -813,9 +792,10 @@ describe("Cart Update Actions", () => {
|
|
|
813
792
|
quantity: 2,
|
|
814
793
|
},
|
|
815
794
|
],
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
|
|
795
|
+
},
|
|
796
|
+
});
|
|
797
|
+
expect(addLineItemResponse.statusCode).toBe(200);
|
|
798
|
+
const cartWithLineItem = addLineItemResponse.json() as Cart;
|
|
819
799
|
const lineItem = cartWithLineItem.lineItems[0];
|
|
820
800
|
assert(lineItem, "lineItem not created");
|
|
821
801
|
|
|
@@ -834,9 +814,10 @@ describe("Cart Update Actions", () => {
|
|
|
834
814
|
2,
|
|
835
815
|
);
|
|
836
816
|
|
|
837
|
-
const response = await
|
|
838
|
-
|
|
839
|
-
.
|
|
817
|
+
const response = await ctMock.app.inject({
|
|
818
|
+
method: "POST",
|
|
819
|
+
url: `/dummy/carts/${cartWithLineItem.id}`,
|
|
820
|
+
payload: {
|
|
840
821
|
version: cartWithLineItem.version,
|
|
841
822
|
actions: [
|
|
842
823
|
{
|
|
@@ -845,13 +826,14 @@ describe("Cart Update Actions", () => {
|
|
|
845
826
|
externalPrice,
|
|
846
827
|
},
|
|
847
828
|
],
|
|
848
|
-
}
|
|
829
|
+
},
|
|
830
|
+
});
|
|
849
831
|
|
|
850
|
-
expect(response.
|
|
851
|
-
expect(response.
|
|
852
|
-
expect(response.
|
|
832
|
+
expect(response.statusCode).toBe(200);
|
|
833
|
+
expect(response.json().version).toBe(cartWithLineItem.version + 1);
|
|
834
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
853
835
|
|
|
854
|
-
const updatedLineItem = response.
|
|
836
|
+
const updatedLineItem = response.json().lineItems[0];
|
|
855
837
|
expect(updatedLineItem.priceMode).toBe("ExternalPrice");
|
|
856
838
|
expect(updatedLineItem.price.value.type).toBe("highPrecision");
|
|
857
839
|
expect(updatedLineItem.price.value.currencyCode).toBe(
|
|
@@ -865,26 +847,20 @@ describe("Cart Update Actions", () => {
|
|
|
865
847
|
);
|
|
866
848
|
expect(updatedLineItem.price.value.centAmount).toBe(expectedUnitCentAmount);
|
|
867
849
|
expect(updatedLineItem.totalPrice.centAmount).toBe(expectedTotalCentAmount);
|
|
868
|
-
expect(response.
|
|
850
|
+
expect(response.json().totalPrice.centAmount).toBe(expectedTotalCentAmount);
|
|
869
851
|
});
|
|
870
852
|
|
|
871
853
|
test("setLineItemPrice supports high precision external price with fractionDigits 5", async () => {
|
|
872
|
-
const product = await
|
|
873
|
-
.post("/dummy/products")
|
|
874
|
-
.send(productDraft)
|
|
875
|
-
.then((x) => x.body);
|
|
854
|
+
const product = await productFactory.create(productDraft);
|
|
876
855
|
|
|
877
856
|
assert(product, "product not created");
|
|
878
857
|
|
|
879
|
-
const
|
|
880
|
-
.post("/dummy/carts")
|
|
881
|
-
.send({ currency: "EUR" });
|
|
882
|
-
expect(baseCartResponse.status).toBe(201);
|
|
883
|
-
const baseCart = baseCartResponse.body as Cart;
|
|
858
|
+
const baseCart = await cartFactory.create({ currency: "EUR" });
|
|
884
859
|
|
|
885
|
-
const addLineItemResponse = await
|
|
886
|
-
|
|
887
|
-
.
|
|
860
|
+
const addLineItemResponse = await ctMock.app.inject({
|
|
861
|
+
method: "POST",
|
|
862
|
+
url: `/dummy/carts/${baseCart.id}`,
|
|
863
|
+
payload: {
|
|
888
864
|
version: baseCart.version,
|
|
889
865
|
actions: [
|
|
890
866
|
{
|
|
@@ -893,9 +869,10 @@ describe("Cart Update Actions", () => {
|
|
|
893
869
|
quantity: 2,
|
|
894
870
|
},
|
|
895
871
|
],
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
|
|
872
|
+
},
|
|
873
|
+
});
|
|
874
|
+
expect(addLineItemResponse.statusCode).toBe(200);
|
|
875
|
+
const cartWithLineItem = addLineItemResponse.json() as Cart;
|
|
899
876
|
const lineItem = cartWithLineItem.lineItems[0];
|
|
900
877
|
assert(lineItem, "lineItem not created");
|
|
901
878
|
|
|
@@ -914,9 +891,10 @@ describe("Cart Update Actions", () => {
|
|
|
914
891
|
2,
|
|
915
892
|
);
|
|
916
893
|
|
|
917
|
-
const response = await
|
|
918
|
-
|
|
919
|
-
.
|
|
894
|
+
const response = await ctMock.app.inject({
|
|
895
|
+
method: "POST",
|
|
896
|
+
url: `/dummy/carts/${cartWithLineItem.id}`,
|
|
897
|
+
payload: {
|
|
920
898
|
version: cartWithLineItem.version,
|
|
921
899
|
actions: [
|
|
922
900
|
{
|
|
@@ -925,13 +903,14 @@ describe("Cart Update Actions", () => {
|
|
|
925
903
|
externalPrice,
|
|
926
904
|
},
|
|
927
905
|
],
|
|
928
|
-
}
|
|
906
|
+
},
|
|
907
|
+
});
|
|
929
908
|
|
|
930
|
-
expect(response.
|
|
931
|
-
expect(response.
|
|
932
|
-
expect(response.
|
|
909
|
+
expect(response.statusCode).toBe(200);
|
|
910
|
+
expect(response.json().version).toBe(cartWithLineItem.version + 1);
|
|
911
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
933
912
|
|
|
934
|
-
const updatedLineItem = response.
|
|
913
|
+
const updatedLineItem = response.json().lineItems[0];
|
|
935
914
|
expect(updatedLineItem.priceMode).toBe("ExternalPrice");
|
|
936
915
|
expect(updatedLineItem.price.value.type).toBe("highPrecision");
|
|
937
916
|
expect(updatedLineItem.price.value.currencyCode).toBe(
|
|
@@ -945,26 +924,20 @@ describe("Cart Update Actions", () => {
|
|
|
945
924
|
);
|
|
946
925
|
expect(updatedLineItem.price.value.centAmount).toBe(expectedUnitCentAmount);
|
|
947
926
|
expect(updatedLineItem.totalPrice.centAmount).toBe(expectedTotalCentAmount);
|
|
948
|
-
expect(response.
|
|
927
|
+
expect(response.json().totalPrice.centAmount).toBe(expectedTotalCentAmount);
|
|
949
928
|
});
|
|
950
929
|
|
|
951
930
|
test("setLineItemPrice fails when the money uses another currency", async () => {
|
|
952
|
-
const product = await
|
|
953
|
-
.post("/dummy/products")
|
|
954
|
-
.send(productDraft)
|
|
955
|
-
.then((x) => x.body);
|
|
931
|
+
const product = await productFactory.create(productDraft);
|
|
956
932
|
|
|
957
933
|
assert(product, "product not created");
|
|
958
934
|
|
|
959
|
-
const
|
|
960
|
-
.post("/dummy/carts")
|
|
961
|
-
.send({ currency: "EUR" });
|
|
962
|
-
expect(baseCartResponse.status).toBe(201);
|
|
963
|
-
const baseCart = baseCartResponse.body as Cart;
|
|
935
|
+
const baseCart = await cartFactory.create({ currency: "EUR" });
|
|
964
936
|
|
|
965
|
-
const addLineItemResponse = await
|
|
966
|
-
|
|
967
|
-
.
|
|
937
|
+
const addLineItemResponse = await ctMock.app.inject({
|
|
938
|
+
method: "POST",
|
|
939
|
+
url: `/dummy/carts/${baseCart.id}`,
|
|
940
|
+
payload: {
|
|
968
941
|
version: baseCart.version,
|
|
969
942
|
actions: [
|
|
970
943
|
{
|
|
@@ -973,15 +946,17 @@ describe("Cart Update Actions", () => {
|
|
|
973
946
|
quantity: 1,
|
|
974
947
|
},
|
|
975
948
|
],
|
|
976
|
-
}
|
|
977
|
-
|
|
978
|
-
|
|
949
|
+
},
|
|
950
|
+
});
|
|
951
|
+
expect(addLineItemResponse.statusCode).toBe(200);
|
|
952
|
+
const cartWithLineItem = addLineItemResponse.json() as Cart;
|
|
979
953
|
const lineItem = cartWithLineItem.lineItems[0];
|
|
980
954
|
assert(lineItem, "lineItem not created");
|
|
981
955
|
|
|
982
|
-
const response = await
|
|
983
|
-
|
|
984
|
-
.
|
|
956
|
+
const response = await ctMock.app.inject({
|
|
957
|
+
method: "POST",
|
|
958
|
+
url: `/dummy/carts/${cartWithLineItem.id}`,
|
|
959
|
+
payload: {
|
|
985
960
|
version: cartWithLineItem.version,
|
|
986
961
|
actions: [
|
|
987
962
|
{
|
|
@@ -995,29 +970,24 @@ describe("Cart Update Actions", () => {
|
|
|
995
970
|
},
|
|
996
971
|
},
|
|
997
972
|
],
|
|
998
|
-
}
|
|
973
|
+
},
|
|
974
|
+
});
|
|
999
975
|
|
|
1000
|
-
expect(response.
|
|
1001
|
-
expect(response.
|
|
976
|
+
expect(response.statusCode).toBe(400);
|
|
977
|
+
expect(response.json().message).toContain("Currency mismatch");
|
|
1002
978
|
});
|
|
1003
979
|
|
|
1004
980
|
test("setLineItemPrice removes external price when no value is provided", async () => {
|
|
1005
|
-
const product = await
|
|
1006
|
-
.post("/dummy/products")
|
|
1007
|
-
.send(productDraft)
|
|
1008
|
-
.then((x) => x.body);
|
|
981
|
+
const product = await productFactory.create(productDraft);
|
|
1009
982
|
|
|
1010
983
|
assert(product, "product not created");
|
|
1011
984
|
|
|
1012
|
-
const
|
|
1013
|
-
.post("/dummy/carts")
|
|
1014
|
-
.send({ currency: "EUR" });
|
|
1015
|
-
expect(baseCartResponse.status).toBe(201);
|
|
1016
|
-
const baseCart = baseCartResponse.body as Cart;
|
|
985
|
+
const baseCart = await cartFactory.create({ currency: "EUR" });
|
|
1017
986
|
|
|
1018
|
-
const addLineItemResponse = await
|
|
1019
|
-
|
|
1020
|
-
.
|
|
987
|
+
const addLineItemResponse = await ctMock.app.inject({
|
|
988
|
+
method: "POST",
|
|
989
|
+
url: `/dummy/carts/${baseCart.id}`,
|
|
990
|
+
payload: {
|
|
1021
991
|
version: baseCart.version,
|
|
1022
992
|
actions: [
|
|
1023
993
|
{
|
|
@@ -1026,9 +996,10 @@ describe("Cart Update Actions", () => {
|
|
|
1026
996
|
quantity: 1,
|
|
1027
997
|
},
|
|
1028
998
|
],
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
|
|
999
|
+
},
|
|
1000
|
+
});
|
|
1001
|
+
expect(addLineItemResponse.statusCode).toBe(200);
|
|
1002
|
+
const cartWithLineItem = addLineItemResponse.json() as Cart;
|
|
1032
1003
|
const lineItem = cartWithLineItem.lineItems[0];
|
|
1033
1004
|
assert(lineItem, "lineItem not created");
|
|
1034
1005
|
|
|
@@ -1039,9 +1010,10 @@ describe("Cart Update Actions", () => {
|
|
|
1039
1010
|
fractionDigits: 2,
|
|
1040
1011
|
};
|
|
1041
1012
|
|
|
1042
|
-
const setExternalPriceResponse = await
|
|
1043
|
-
|
|
1044
|
-
.
|
|
1013
|
+
const setExternalPriceResponse = await ctMock.app.inject({
|
|
1014
|
+
method: "POST",
|
|
1015
|
+
url: `/dummy/carts/${cartWithLineItem.id}`,
|
|
1016
|
+
payload: {
|
|
1045
1017
|
version: cartWithLineItem.version,
|
|
1046
1018
|
actions: [
|
|
1047
1019
|
{
|
|
@@ -1050,14 +1022,16 @@ describe("Cart Update Actions", () => {
|
|
|
1050
1022
|
externalPrice,
|
|
1051
1023
|
},
|
|
1052
1024
|
],
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
|
|
1025
|
+
},
|
|
1026
|
+
});
|
|
1027
|
+
expect(setExternalPriceResponse.statusCode).toBe(200);
|
|
1028
|
+
const cartWithExternalPrice = setExternalPriceResponse.json() as Cart;
|
|
1056
1029
|
expect(cartWithExternalPrice.lineItems[0].priceMode).toBe("ExternalPrice");
|
|
1057
1030
|
|
|
1058
|
-
const resetResponse = await
|
|
1059
|
-
|
|
1060
|
-
.
|
|
1031
|
+
const resetResponse = await ctMock.app.inject({
|
|
1032
|
+
method: "POST",
|
|
1033
|
+
url: `/dummy/carts/${cartWithExternalPrice.id}`,
|
|
1034
|
+
payload: {
|
|
1061
1035
|
version: cartWithExternalPrice.version,
|
|
1062
1036
|
actions: [
|
|
1063
1037
|
{
|
|
@@ -1065,13 +1039,16 @@ describe("Cart Update Actions", () => {
|
|
|
1065
1039
|
lineItemId: lineItem.id,
|
|
1066
1040
|
},
|
|
1067
1041
|
],
|
|
1068
|
-
}
|
|
1042
|
+
},
|
|
1043
|
+
});
|
|
1069
1044
|
|
|
1070
|
-
expect(resetResponse.
|
|
1071
|
-
expect(resetResponse.
|
|
1072
|
-
|
|
1045
|
+
expect(resetResponse.statusCode).toBe(200);
|
|
1046
|
+
expect(resetResponse.json().version).toBe(
|
|
1047
|
+
cartWithExternalPrice.version + 1,
|
|
1048
|
+
);
|
|
1049
|
+
expect(resetResponse.json().lineItems).toHaveLength(1);
|
|
1073
1050
|
|
|
1074
|
-
const revertedLineItem = resetResponse.
|
|
1051
|
+
const revertedLineItem = resetResponse.json().lineItems[0];
|
|
1075
1052
|
const expectedCentAmount =
|
|
1076
1053
|
product.masterData.current.masterVariant.prices?.[0].value.centAmount;
|
|
1077
1054
|
if (typeof expectedCentAmount !== "number") {
|
|
@@ -1082,73 +1059,65 @@ describe("Cart Update Actions", () => {
|
|
|
1082
1059
|
expect(revertedLineItem.totalPrice.centAmount).toBe(
|
|
1083
1060
|
expectedCentAmount * revertedLineItem.quantity,
|
|
1084
1061
|
);
|
|
1085
|
-
expect(resetResponse.
|
|
1062
|
+
expect(resetResponse.json().totalPrice.centAmount).toBe(
|
|
1086
1063
|
expectedCentAmount * revertedLineItem.quantity,
|
|
1087
1064
|
);
|
|
1088
1065
|
});
|
|
1089
1066
|
|
|
1090
1067
|
test("setLineItemCustomField", async () => {
|
|
1091
|
-
const product = await
|
|
1092
|
-
.post("/dummy/products")
|
|
1093
|
-
.send(productDraft)
|
|
1094
|
-
.then((x) => x.body);
|
|
1068
|
+
const product = await productFactory.create(productDraft);
|
|
1095
1069
|
|
|
1096
1070
|
assert(product, "product not created");
|
|
1097
1071
|
|
|
1098
|
-
const type = await
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
{
|
|
1110
|
-
|
|
1111
|
-
label: {
|
|
1112
|
-
en: "foo",
|
|
1113
|
-
},
|
|
1114
|
-
required: false,
|
|
1115
|
-
type: {
|
|
1116
|
-
name: "String",
|
|
1117
|
-
},
|
|
1118
|
-
inputHint: "SingleLine",
|
|
1072
|
+
const type = await typeFactory.create({
|
|
1073
|
+
key: "my-type",
|
|
1074
|
+
name: {
|
|
1075
|
+
en: "My Type",
|
|
1076
|
+
},
|
|
1077
|
+
description: {
|
|
1078
|
+
en: "My Type Description",
|
|
1079
|
+
},
|
|
1080
|
+
fieldDefinitions: [
|
|
1081
|
+
{
|
|
1082
|
+
name: "foo",
|
|
1083
|
+
label: {
|
|
1084
|
+
en: "foo",
|
|
1119
1085
|
},
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1086
|
+
required: false,
|
|
1087
|
+
type: {
|
|
1088
|
+
name: "String",
|
|
1089
|
+
},
|
|
1090
|
+
inputHint: "SingleLine",
|
|
1091
|
+
},
|
|
1092
|
+
],
|
|
1093
|
+
});
|
|
1123
1094
|
|
|
1124
1095
|
assert(type, "type not created");
|
|
1125
1096
|
|
|
1126
|
-
const myCart = await
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
typeId: "type",
|
|
1137
|
-
key: "my-type",
|
|
1138
|
-
},
|
|
1139
|
-
fields: {},
|
|
1097
|
+
const myCart = await cartFactory.create({
|
|
1098
|
+
currency: "EUR",
|
|
1099
|
+
lineItems: [
|
|
1100
|
+
{
|
|
1101
|
+
sku: product.masterData.current.masterVariant.sku,
|
|
1102
|
+
quantity: 1,
|
|
1103
|
+
custom: {
|
|
1104
|
+
type: {
|
|
1105
|
+
typeId: "type",
|
|
1106
|
+
key: "my-type",
|
|
1140
1107
|
},
|
|
1108
|
+
fields: {},
|
|
1141
1109
|
},
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1110
|
+
},
|
|
1111
|
+
],
|
|
1112
|
+
});
|
|
1145
1113
|
|
|
1146
1114
|
const lineItem = myCart.lineItems[0];
|
|
1147
1115
|
assert(lineItem, "lineItem not created");
|
|
1148
1116
|
|
|
1149
|
-
const response = await
|
|
1150
|
-
|
|
1151
|
-
.
|
|
1117
|
+
const response = await ctMock.app.inject({
|
|
1118
|
+
method: "POST",
|
|
1119
|
+
url: `/dummy/carts/${myCart.id}`,
|
|
1120
|
+
payload: {
|
|
1152
1121
|
version: myCart.version,
|
|
1153
1122
|
actions: [
|
|
1154
1123
|
{
|
|
@@ -1158,11 +1127,12 @@ describe("Cart Update Actions", () => {
|
|
|
1158
1127
|
value: "bar",
|
|
1159
1128
|
},
|
|
1160
1129
|
],
|
|
1161
|
-
}
|
|
1130
|
+
},
|
|
1131
|
+
});
|
|
1162
1132
|
|
|
1163
|
-
expect(response.
|
|
1164
|
-
expect(response.
|
|
1165
|
-
expect(response.
|
|
1133
|
+
expect(response.statusCode).toBe(200);
|
|
1134
|
+
expect(response.json().version).toBe(2);
|
|
1135
|
+
expect(response.json().lineItems).toMatchObject([
|
|
1166
1136
|
{
|
|
1167
1137
|
id: lineItem.id,
|
|
1168
1138
|
custom: {
|
|
@@ -1175,60 +1145,52 @@ describe("Cart Update Actions", () => {
|
|
|
1175
1145
|
});
|
|
1176
1146
|
|
|
1177
1147
|
test("setLineItemCustomType", async () => {
|
|
1178
|
-
const product = await
|
|
1179
|
-
.post("/dummy/products")
|
|
1180
|
-
.send(productDraft)
|
|
1181
|
-
.then((x) => x.body);
|
|
1148
|
+
const product = await productFactory.create(productDraft);
|
|
1182
1149
|
|
|
1183
1150
|
assert(product, "product not created");
|
|
1184
1151
|
|
|
1185
|
-
const type = await
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
{
|
|
1197
|
-
|
|
1198
|
-
label: {
|
|
1199
|
-
en: "foo",
|
|
1200
|
-
},
|
|
1201
|
-
required: false,
|
|
1202
|
-
type: {
|
|
1203
|
-
name: "String",
|
|
1204
|
-
},
|
|
1205
|
-
inputHint: "SingleLine",
|
|
1152
|
+
const type = await typeFactory.create({
|
|
1153
|
+
key: "my-type",
|
|
1154
|
+
name: {
|
|
1155
|
+
en: "My Type",
|
|
1156
|
+
},
|
|
1157
|
+
description: {
|
|
1158
|
+
en: "My Type Description",
|
|
1159
|
+
},
|
|
1160
|
+
fieldDefinitions: [
|
|
1161
|
+
{
|
|
1162
|
+
name: "foo",
|
|
1163
|
+
label: {
|
|
1164
|
+
en: "foo",
|
|
1206
1165
|
},
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1166
|
+
required: false,
|
|
1167
|
+
type: {
|
|
1168
|
+
name: "String",
|
|
1169
|
+
},
|
|
1170
|
+
inputHint: "SingleLine",
|
|
1171
|
+
},
|
|
1172
|
+
],
|
|
1173
|
+
});
|
|
1210
1174
|
|
|
1211
1175
|
assert(type, "type not created");
|
|
1212
1176
|
|
|
1213
|
-
const myCart = await
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
],
|
|
1223
|
-
})
|
|
1224
|
-
.then((x) => x.body);
|
|
1177
|
+
const myCart = await cartFactory.create({
|
|
1178
|
+
currency: "EUR",
|
|
1179
|
+
lineItems: [
|
|
1180
|
+
{
|
|
1181
|
+
sku: product.masterData.current.masterVariant.sku,
|
|
1182
|
+
quantity: 1,
|
|
1183
|
+
},
|
|
1184
|
+
],
|
|
1185
|
+
});
|
|
1225
1186
|
|
|
1226
1187
|
const lineItem = myCart.lineItems[0];
|
|
1227
1188
|
assert(lineItem, "lineItem not created");
|
|
1228
1189
|
|
|
1229
|
-
const response = await
|
|
1230
|
-
|
|
1231
|
-
.
|
|
1190
|
+
const response = await ctMock.app.inject({
|
|
1191
|
+
method: "POST",
|
|
1192
|
+
url: `/dummy/carts/${myCart.id}`,
|
|
1193
|
+
payload: {
|
|
1232
1194
|
version: myCart.version,
|
|
1233
1195
|
actions: [
|
|
1234
1196
|
{
|
|
@@ -1240,11 +1202,12 @@ describe("Cart Update Actions", () => {
|
|
|
1240
1202
|
},
|
|
1241
1203
|
},
|
|
1242
1204
|
],
|
|
1243
|
-
}
|
|
1205
|
+
},
|
|
1206
|
+
});
|
|
1244
1207
|
|
|
1245
|
-
expect(response.
|
|
1246
|
-
expect(response.
|
|
1247
|
-
expect(response.
|
|
1208
|
+
expect(response.statusCode).toBe(200);
|
|
1209
|
+
expect(response.json().version).toBe(2);
|
|
1210
|
+
expect(response.json().lineItems).toMatchObject([
|
|
1248
1211
|
{
|
|
1249
1212
|
id: lineItem.id,
|
|
1250
1213
|
custom: {
|
|
@@ -1260,15 +1223,17 @@ describe("Cart Update Actions", () => {
|
|
|
1260
1223
|
test("setCustomerEmail", async () => {
|
|
1261
1224
|
assert(cart, "cart not created");
|
|
1262
1225
|
|
|
1263
|
-
const response = await
|
|
1264
|
-
|
|
1265
|
-
.
|
|
1226
|
+
const response = await ctMock.app.inject({
|
|
1227
|
+
method: "POST",
|
|
1228
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1229
|
+
payload: {
|
|
1266
1230
|
version: 1,
|
|
1267
1231
|
actions: [{ action: "setCustomerEmail", email: "john@doe.com" }],
|
|
1268
|
-
}
|
|
1269
|
-
|
|
1270
|
-
expect(response.
|
|
1271
|
-
expect(response.
|
|
1232
|
+
},
|
|
1233
|
+
});
|
|
1234
|
+
expect(response.statusCode).toBe(200);
|
|
1235
|
+
expect(response.json().version).toBe(2);
|
|
1236
|
+
expect(response.json().customerEmail).toBe("john@doe.com");
|
|
1272
1237
|
});
|
|
1273
1238
|
|
|
1274
1239
|
test("setShippingAddress", async () => {
|
|
@@ -1280,15 +1245,17 @@ describe("Cart Update Actions", () => {
|
|
|
1280
1245
|
country: "NL",
|
|
1281
1246
|
};
|
|
1282
1247
|
|
|
1283
|
-
const response = await
|
|
1284
|
-
|
|
1285
|
-
.
|
|
1248
|
+
const response = await ctMock.app.inject({
|
|
1249
|
+
method: "POST",
|
|
1250
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1251
|
+
payload: {
|
|
1286
1252
|
version: 1,
|
|
1287
1253
|
actions: [{ action: "setShippingAddress", address }],
|
|
1288
|
-
}
|
|
1289
|
-
|
|
1290
|
-
expect(response.
|
|
1291
|
-
expect(response.
|
|
1254
|
+
},
|
|
1255
|
+
});
|
|
1256
|
+
expect(response.statusCode).toBe(200);
|
|
1257
|
+
expect(response.json().version).toBe(2);
|
|
1258
|
+
expect(response.json().shippingAddress).toEqual(address);
|
|
1292
1259
|
});
|
|
1293
1260
|
|
|
1294
1261
|
test("setBillingAddressCustomType", async () => {
|
|
@@ -1300,37 +1267,35 @@ describe("Cart Update Actions", () => {
|
|
|
1300
1267
|
country: "NL",
|
|
1301
1268
|
};
|
|
1302
1269
|
|
|
1303
|
-
const type = await
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
{
|
|
1315
|
-
|
|
1316
|
-
label: {
|
|
1317
|
-
en: "foo",
|
|
1318
|
-
},
|
|
1319
|
-
required: false,
|
|
1320
|
-
type: {
|
|
1321
|
-
name: "String",
|
|
1322
|
-
},
|
|
1323
|
-
inputHint: "SingleLine",
|
|
1270
|
+
const type = await typeFactory.create({
|
|
1271
|
+
key: "my-type",
|
|
1272
|
+
name: {
|
|
1273
|
+
en: "My Type",
|
|
1274
|
+
},
|
|
1275
|
+
description: {
|
|
1276
|
+
en: "My Type Description",
|
|
1277
|
+
},
|
|
1278
|
+
fieldDefinitions: [
|
|
1279
|
+
{
|
|
1280
|
+
name: "foo",
|
|
1281
|
+
label: {
|
|
1282
|
+
en: "foo",
|
|
1324
1283
|
},
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1284
|
+
required: false,
|
|
1285
|
+
type: {
|
|
1286
|
+
name: "String",
|
|
1287
|
+
},
|
|
1288
|
+
inputHint: "SingleLine",
|
|
1289
|
+
},
|
|
1290
|
+
],
|
|
1291
|
+
});
|
|
1328
1292
|
|
|
1329
1293
|
assert(type, "type not created");
|
|
1330
1294
|
|
|
1331
|
-
const response = await
|
|
1332
|
-
|
|
1333
|
-
.
|
|
1295
|
+
const response = await ctMock.app.inject({
|
|
1296
|
+
method: "POST",
|
|
1297
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1298
|
+
payload: {
|
|
1334
1299
|
version: 1,
|
|
1335
1300
|
actions: [
|
|
1336
1301
|
{ action: "setBillingAddress", address },
|
|
@@ -1346,11 +1311,12 @@ describe("Cart Update Actions", () => {
|
|
|
1346
1311
|
},
|
|
1347
1312
|
},
|
|
1348
1313
|
],
|
|
1349
|
-
}
|
|
1314
|
+
},
|
|
1315
|
+
});
|
|
1350
1316
|
|
|
1351
|
-
expect(response.
|
|
1352
|
-
expect(response.
|
|
1353
|
-
expect(response.
|
|
1317
|
+
expect(response.statusCode).toBe(200);
|
|
1318
|
+
expect(response.json().version).toBe(3);
|
|
1319
|
+
expect(response.json().billingAddress).toEqual({
|
|
1354
1320
|
...address,
|
|
1355
1321
|
id: expect.any(String),
|
|
1356
1322
|
custom: {
|
|
@@ -1369,37 +1335,35 @@ describe("Cart Update Actions", () => {
|
|
|
1369
1335
|
country: "NL",
|
|
1370
1336
|
};
|
|
1371
1337
|
|
|
1372
|
-
const type = await
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
{
|
|
1384
|
-
|
|
1385
|
-
label: {
|
|
1386
|
-
en: "foo",
|
|
1387
|
-
},
|
|
1388
|
-
required: false,
|
|
1389
|
-
type: {
|
|
1390
|
-
name: "String",
|
|
1391
|
-
},
|
|
1392
|
-
inputHint: "SingleLine",
|
|
1338
|
+
const type = await typeFactory.create({
|
|
1339
|
+
key: "my-type",
|
|
1340
|
+
name: {
|
|
1341
|
+
en: "My Type",
|
|
1342
|
+
},
|
|
1343
|
+
description: {
|
|
1344
|
+
en: "My Type Description",
|
|
1345
|
+
},
|
|
1346
|
+
fieldDefinitions: [
|
|
1347
|
+
{
|
|
1348
|
+
name: "foo",
|
|
1349
|
+
label: {
|
|
1350
|
+
en: "foo",
|
|
1393
1351
|
},
|
|
1394
|
-
|
|
1395
|
-
|
|
1396
|
-
|
|
1352
|
+
required: false,
|
|
1353
|
+
type: {
|
|
1354
|
+
name: "String",
|
|
1355
|
+
},
|
|
1356
|
+
inputHint: "SingleLine",
|
|
1357
|
+
},
|
|
1358
|
+
],
|
|
1359
|
+
});
|
|
1397
1360
|
|
|
1398
1361
|
assert(type, "type not created");
|
|
1399
1362
|
|
|
1400
|
-
const response = await
|
|
1401
|
-
|
|
1402
|
-
.
|
|
1363
|
+
const response = await ctMock.app.inject({
|
|
1364
|
+
method: "POST",
|
|
1365
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1366
|
+
payload: {
|
|
1403
1367
|
version: 1,
|
|
1404
1368
|
actions: [
|
|
1405
1369
|
{ action: "setShippingAddress", address },
|
|
@@ -1415,11 +1379,12 @@ describe("Cart Update Actions", () => {
|
|
|
1415
1379
|
},
|
|
1416
1380
|
},
|
|
1417
1381
|
],
|
|
1418
|
-
}
|
|
1382
|
+
},
|
|
1383
|
+
});
|
|
1419
1384
|
|
|
1420
|
-
expect(response.
|
|
1421
|
-
expect(response.
|
|
1422
|
-
expect(response.
|
|
1385
|
+
expect(response.statusCode).toBe(200);
|
|
1386
|
+
expect(response.json().version).toBe(3);
|
|
1387
|
+
expect(response.json().shippingAddress).toEqual({
|
|
1423
1388
|
...address,
|
|
1424
1389
|
custom: {
|
|
1425
1390
|
type: { typeId: "type", id: type.id },
|
|
@@ -1433,9 +1398,15 @@ describe("Cart Update Actions", () => {
|
|
|
1433
1398
|
let standardExcludedShippingMethod: ShippingMethod;
|
|
1434
1399
|
beforeEach(async () => {
|
|
1435
1400
|
assert(cart, "cart not created");
|
|
1436
|
-
const nlZone = await
|
|
1437
|
-
|
|
1438
|
-
|
|
1401
|
+
const nlZone = await zoneFactory.create({
|
|
1402
|
+
name: "NL",
|
|
1403
|
+
locations: [{ country: "NL" }],
|
|
1404
|
+
});
|
|
1405
|
+
const frZone = await zoneFactory.create({
|
|
1406
|
+
name: "FR",
|
|
1407
|
+
locations: [{ country: "FR" }],
|
|
1408
|
+
});
|
|
1409
|
+
const standardTax = await taxCategoryFactory.create({
|
|
1439
1410
|
name: "Standard tax category",
|
|
1440
1411
|
key: "standard",
|
|
1441
1412
|
rates: [
|
|
@@ -1453,7 +1424,7 @@ describe("Cart Update Actions", () => {
|
|
|
1453
1424
|
},
|
|
1454
1425
|
],
|
|
1455
1426
|
});
|
|
1456
|
-
await
|
|
1427
|
+
await taxCategoryFactory.create({
|
|
1457
1428
|
name: "Reduced tax category",
|
|
1458
1429
|
key: "reduced",
|
|
1459
1430
|
rates: [
|
|
@@ -1471,7 +1442,7 @@ describe("Cart Update Actions", () => {
|
|
|
1471
1442
|
},
|
|
1472
1443
|
],
|
|
1473
1444
|
});
|
|
1474
|
-
const standardExcludedTax = await
|
|
1445
|
+
const standardExcludedTax = await taxCategoryFactory.create({
|
|
1475
1446
|
name: "Tax category that is excluded from price",
|
|
1476
1447
|
key: "standard-excluded",
|
|
1477
1448
|
rates: [
|
|
@@ -1489,7 +1460,7 @@ describe("Cart Update Actions", () => {
|
|
|
1489
1460
|
},
|
|
1490
1461
|
],
|
|
1491
1462
|
});
|
|
1492
|
-
standardShippingMethod = await
|
|
1463
|
+
standardShippingMethod = await shippingMethodFactory.create({
|
|
1493
1464
|
isDefault: false,
|
|
1494
1465
|
key: "standard",
|
|
1495
1466
|
name: "Standard shipping",
|
|
@@ -1533,7 +1504,7 @@ describe("Cart Update Actions", () => {
|
|
|
1533
1504
|
],
|
|
1534
1505
|
});
|
|
1535
1506
|
|
|
1536
|
-
standardExcludedShippingMethod = await
|
|
1507
|
+
standardExcludedShippingMethod = await shippingMethodFactory.create({
|
|
1537
1508
|
isDefault: false,
|
|
1538
1509
|
key: "standard-excluded",
|
|
1539
1510
|
name: "Standard shipping with tax excluded from price",
|
|
@@ -1576,7 +1547,7 @@ describe("Cart Update Actions", () => {
|
|
|
1576
1547
|
},
|
|
1577
1548
|
],
|
|
1578
1549
|
});
|
|
1579
|
-
await
|
|
1550
|
+
await shippingMethodFactory.create({
|
|
1580
1551
|
isDefault: false,
|
|
1581
1552
|
key: "express",
|
|
1582
1553
|
name: "Express shipping",
|
|
@@ -1622,9 +1593,10 @@ describe("Cart Update Actions", () => {
|
|
|
1622
1593
|
|
|
1623
1594
|
expect(
|
|
1624
1595
|
(
|
|
1625
|
-
await
|
|
1626
|
-
|
|
1627
|
-
.
|
|
1596
|
+
await ctMock.app.inject({
|
|
1597
|
+
method: "POST",
|
|
1598
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1599
|
+
payload: {
|
|
1628
1600
|
version: 1,
|
|
1629
1601
|
actions: [
|
|
1630
1602
|
{
|
|
@@ -1636,8 +1608,9 @@ describe("Cart Update Actions", () => {
|
|
|
1636
1608
|
},
|
|
1637
1609
|
},
|
|
1638
1610
|
],
|
|
1639
|
-
}
|
|
1640
|
-
|
|
1611
|
+
},
|
|
1612
|
+
})
|
|
1613
|
+
).statusCode,
|
|
1641
1614
|
).toBe(200);
|
|
1642
1615
|
});
|
|
1643
1616
|
|
|
@@ -1649,15 +1622,17 @@ describe("Cart Update Actions", () => {
|
|
|
1649
1622
|
id: standardShippingMethod.id,
|
|
1650
1623
|
};
|
|
1651
1624
|
|
|
1652
|
-
const response = await
|
|
1653
|
-
|
|
1654
|
-
.
|
|
1625
|
+
const response = await ctMock.app.inject({
|
|
1626
|
+
method: "POST",
|
|
1627
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1628
|
+
payload: {
|
|
1655
1629
|
version: 2,
|
|
1656
1630
|
actions: [{ action: "setShippingMethod", shippingMethod }],
|
|
1657
|
-
}
|
|
1658
|
-
|
|
1659
|
-
expect(response.
|
|
1660
|
-
expect(response.
|
|
1631
|
+
},
|
|
1632
|
+
});
|
|
1633
|
+
expect(response.statusCode).toBe(200);
|
|
1634
|
+
expect(response.json().version).toBe(3);
|
|
1635
|
+
expect(response.json().shippingInfo.shippingMethod.id).toEqual(
|
|
1661
1636
|
standardShippingMethod.id,
|
|
1662
1637
|
);
|
|
1663
1638
|
});
|
|
@@ -1670,17 +1645,20 @@ describe("Cart Update Actions", () => {
|
|
|
1670
1645
|
id: standardShippingMethod.id,
|
|
1671
1646
|
};
|
|
1672
1647
|
|
|
1673
|
-
const response = await
|
|
1674
|
-
|
|
1675
|
-
.
|
|
1648
|
+
const response = await ctMock.app.inject({
|
|
1649
|
+
method: "POST",
|
|
1650
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1651
|
+
payload: {
|
|
1676
1652
|
version: 2,
|
|
1677
1653
|
actions: [{ action: "setShippingMethod", shippingMethod }],
|
|
1678
|
-
}
|
|
1679
|
-
|
|
1654
|
+
},
|
|
1655
|
+
});
|
|
1656
|
+
expect(response.statusCode).toBe(200);
|
|
1680
1657
|
|
|
1681
|
-
const removeResponse = await
|
|
1682
|
-
|
|
1683
|
-
.
|
|
1658
|
+
const removeResponse = await ctMock.app.inject({
|
|
1659
|
+
method: "POST",
|
|
1660
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1661
|
+
payload: {
|
|
1684
1662
|
version: 3,
|
|
1685
1663
|
actions: [
|
|
1686
1664
|
{
|
|
@@ -1688,9 +1666,10 @@ describe("Cart Update Actions", () => {
|
|
|
1688
1666
|
shippingKey: standardShippingMethod.key,
|
|
1689
1667
|
},
|
|
1690
1668
|
],
|
|
1691
|
-
}
|
|
1692
|
-
|
|
1693
|
-
expect(removeResponse.
|
|
1669
|
+
},
|
|
1670
|
+
});
|
|
1671
|
+
expect(removeResponse.statusCode).toBe(200);
|
|
1672
|
+
expect(removeResponse.json().shippingInfo).toBeUndefined();
|
|
1694
1673
|
});
|
|
1695
1674
|
|
|
1696
1675
|
test("correctly sets shippingInfo rates + tax when includedInPrice: true", async () => {
|
|
@@ -1702,33 +1681,35 @@ describe("Cart Update Actions", () => {
|
|
|
1702
1681
|
id: standardShippingMethod.id,
|
|
1703
1682
|
};
|
|
1704
1683
|
|
|
1705
|
-
const response = await
|
|
1706
|
-
|
|
1707
|
-
.
|
|
1684
|
+
const response = await ctMock.app.inject({
|
|
1685
|
+
method: "POST",
|
|
1686
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1687
|
+
payload: {
|
|
1708
1688
|
version: 2,
|
|
1709
1689
|
actions: [{ action: "setShippingMethod", shippingMethod }],
|
|
1710
|
-
}
|
|
1711
|
-
|
|
1712
|
-
expect(response.
|
|
1713
|
-
expect(response.
|
|
1690
|
+
},
|
|
1691
|
+
});
|
|
1692
|
+
expect(response.statusCode).toBe(200);
|
|
1693
|
+
expect(response.json().version).toBe(3);
|
|
1694
|
+
expect(response.json().shippingInfo.shippingRate.price).toMatchObject({
|
|
1714
1695
|
centAmount: 499,
|
|
1715
1696
|
currencyCode: "EUR",
|
|
1716
1697
|
fractionDigits: 2,
|
|
1717
1698
|
type: "centPrecision",
|
|
1718
1699
|
});
|
|
1719
|
-
expect(response.
|
|
1700
|
+
expect(response.json().shippingInfo.price).toMatchObject({
|
|
1720
1701
|
centAmount: 499,
|
|
1721
1702
|
currencyCode: "EUR",
|
|
1722
1703
|
fractionDigits: 2,
|
|
1723
1704
|
type: "centPrecision",
|
|
1724
1705
|
});
|
|
1725
|
-
expect(response.
|
|
1706
|
+
expect(response.json().shippingInfo.taxRate).toMatchObject({
|
|
1726
1707
|
name: "NL standard tax rate",
|
|
1727
1708
|
amount: 0.21,
|
|
1728
1709
|
includedInPrice: true,
|
|
1729
1710
|
country: "NL",
|
|
1730
1711
|
});
|
|
1731
|
-
expect(response.
|
|
1712
|
+
expect(response.json().shippingInfo.taxedPrice).toMatchObject({
|
|
1732
1713
|
totalNet: {
|
|
1733
1714
|
type: "centPrecision",
|
|
1734
1715
|
centAmount: 412,
|
|
@@ -1771,34 +1752,36 @@ describe("Cart Update Actions", () => {
|
|
|
1771
1752
|
id: standardExcludedShippingMethod.id,
|
|
1772
1753
|
};
|
|
1773
1754
|
|
|
1774
|
-
const response = await
|
|
1775
|
-
|
|
1776
|
-
.
|
|
1755
|
+
const response = await ctMock.app.inject({
|
|
1756
|
+
method: "POST",
|
|
1757
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1758
|
+
payload: {
|
|
1777
1759
|
version: 2,
|
|
1778
1760
|
actions: [{ action: "setShippingMethod", shippingMethod }],
|
|
1779
|
-
}
|
|
1780
|
-
|
|
1781
|
-
expect(response.
|
|
1782
|
-
expect(response.
|
|
1761
|
+
},
|
|
1762
|
+
});
|
|
1763
|
+
expect(response.statusCode).toBe(200);
|
|
1764
|
+
expect(response.json().version).toBe(3);
|
|
1765
|
+
expect(response.json().shippingInfo.shippingRate.price).toMatchObject({
|
|
1783
1766
|
centAmount: 499,
|
|
1784
1767
|
currencyCode: "EUR",
|
|
1785
1768
|
fractionDigits: 2,
|
|
1786
1769
|
type: "centPrecision",
|
|
1787
1770
|
});
|
|
1788
1771
|
// TODO: should this be gross or net? docs unclear (currently always just returns the shipping rate (tier) price)
|
|
1789
|
-
expect(response.
|
|
1772
|
+
expect(response.json().shippingInfo.price).toMatchObject({
|
|
1790
1773
|
centAmount: 499,
|
|
1791
1774
|
currencyCode: "EUR",
|
|
1792
1775
|
fractionDigits: 2,
|
|
1793
1776
|
type: "centPrecision",
|
|
1794
1777
|
});
|
|
1795
|
-
expect(response.
|
|
1778
|
+
expect(response.json().shippingInfo.taxRate).toMatchObject({
|
|
1796
1779
|
name: "NL standard-excluded tax rate",
|
|
1797
1780
|
amount: 0.21,
|
|
1798
1781
|
includedInPrice: false,
|
|
1799
1782
|
country: "NL",
|
|
1800
1783
|
});
|
|
1801
|
-
expect(response.
|
|
1784
|
+
expect(response.json().shippingInfo.taxedPrice).toMatchObject({
|
|
1802
1785
|
totalNet: {
|
|
1803
1786
|
type: "centPrecision",
|
|
1804
1787
|
centAmount: 499,
|
|
@@ -1834,17 +1817,15 @@ describe("Cart Update Actions", () => {
|
|
|
1834
1817
|
});
|
|
1835
1818
|
|
|
1836
1819
|
test("setLineItemShippingDetails", async () => {
|
|
1837
|
-
const product = await
|
|
1838
|
-
.post("/dummy/products")
|
|
1839
|
-
.send(productDraft)
|
|
1840
|
-
.then((x) => x.body);
|
|
1820
|
+
const product = await productFactory.create(productDraft);
|
|
1841
1821
|
|
|
1842
1822
|
assert(cart, "cart not created");
|
|
1843
1823
|
assert(product, "product not created");
|
|
1844
1824
|
|
|
1845
|
-
const updatedCart = await
|
|
1846
|
-
|
|
1847
|
-
.
|
|
1825
|
+
const updatedCart = await ctMock.app.inject({
|
|
1826
|
+
method: "POST",
|
|
1827
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1828
|
+
payload: {
|
|
1848
1829
|
version: 1,
|
|
1849
1830
|
actions: [
|
|
1850
1831
|
{
|
|
@@ -1853,17 +1834,19 @@ describe("Cart Update Actions", () => {
|
|
|
1853
1834
|
variantId: product.masterData.current.variants[0].id,
|
|
1854
1835
|
},
|
|
1855
1836
|
],
|
|
1856
|
-
}
|
|
1857
|
-
|
|
1837
|
+
},
|
|
1838
|
+
});
|
|
1839
|
+
const lineItem = updatedCart.json().lineItems[0];
|
|
1858
1840
|
assert(lineItem, "lineItem not created");
|
|
1859
1841
|
|
|
1860
|
-
expect(updatedCart.
|
|
1861
|
-
expect(updatedCart.
|
|
1842
|
+
expect(updatedCart.json().version).toBe(2);
|
|
1843
|
+
expect(updatedCart.json().lineItems).toHaveLength(1);
|
|
1862
1844
|
|
|
1863
|
-
const response = await
|
|
1864
|
-
|
|
1865
|
-
.
|
|
1866
|
-
|
|
1845
|
+
const response = await ctMock.app.inject({
|
|
1846
|
+
method: "POST",
|
|
1847
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1848
|
+
payload: {
|
|
1849
|
+
version: updatedCart.json().version,
|
|
1867
1850
|
actions: [
|
|
1868
1851
|
{
|
|
1869
1852
|
action: "setLineItemShippingDetails",
|
|
@@ -1878,40 +1861,39 @@ describe("Cart Update Actions", () => {
|
|
|
1878
1861
|
},
|
|
1879
1862
|
},
|
|
1880
1863
|
],
|
|
1881
|
-
}
|
|
1864
|
+
},
|
|
1865
|
+
});
|
|
1882
1866
|
|
|
1883
|
-
expect(response.
|
|
1884
|
-
expect(response.
|
|
1885
|
-
expect(response.
|
|
1867
|
+
expect(response.statusCode).toBe(200);
|
|
1868
|
+
expect(response.json().version).toBe(3);
|
|
1869
|
+
expect(response.json().lineItems).toHaveLength(1);
|
|
1886
1870
|
|
|
1887
|
-
const updatedLineItem = response.
|
|
1871
|
+
const updatedLineItem = response.json().lineItems[0];
|
|
1888
1872
|
expect(updatedLineItem.shippingDetails).toBeDefined();
|
|
1889
1873
|
expect(updatedLineItem.shippingDetails.targets).toHaveLength(1);
|
|
1890
1874
|
});
|
|
1891
1875
|
|
|
1892
1876
|
test("addCustomLineItem", async () => {
|
|
1893
1877
|
assert(cart, "cart not created");
|
|
1894
|
-
const type = await
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
{
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
],
|
|
1909
|
-
})
|
|
1910
|
-
.then((res) => res.body);
|
|
1878
|
+
const type = await typeFactory.create({
|
|
1879
|
+
key: "custom-line-item-type",
|
|
1880
|
+
name: { en: "Custom Line Item Type" },
|
|
1881
|
+
resourceTypeIds: ["custom-line-item"],
|
|
1882
|
+
fieldDefinitions: [
|
|
1883
|
+
{
|
|
1884
|
+
name: "description",
|
|
1885
|
+
label: { en: "Description" },
|
|
1886
|
+
required: false,
|
|
1887
|
+
type: { name: "String" },
|
|
1888
|
+
inputHint: "SingleLine",
|
|
1889
|
+
},
|
|
1890
|
+
],
|
|
1891
|
+
});
|
|
1911
1892
|
|
|
1912
|
-
const response = await
|
|
1913
|
-
|
|
1914
|
-
.
|
|
1893
|
+
const response = await ctMock.app.inject({
|
|
1894
|
+
method: "POST",
|
|
1895
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1896
|
+
payload: {
|
|
1915
1897
|
version: 1,
|
|
1916
1898
|
actions: [
|
|
1917
1899
|
{
|
|
@@ -1933,13 +1915,14 @@ describe("Cart Update Actions", () => {
|
|
|
1933
1915
|
},
|
|
1934
1916
|
},
|
|
1935
1917
|
],
|
|
1936
|
-
}
|
|
1918
|
+
},
|
|
1919
|
+
});
|
|
1937
1920
|
|
|
1938
|
-
expect(response.
|
|
1939
|
-
expect(response.
|
|
1940
|
-
expect(response.
|
|
1921
|
+
expect(response.statusCode).toBe(200);
|
|
1922
|
+
expect(response.json().version).toBe(2);
|
|
1923
|
+
expect(response.json().customLineItems).toHaveLength(1);
|
|
1941
1924
|
|
|
1942
|
-
const customLineItem = response.
|
|
1925
|
+
const customLineItem = response.json().customLineItems[0];
|
|
1943
1926
|
expect(customLineItem.name).toEqual({ en: "Custom Service Fee" });
|
|
1944
1927
|
expect(customLineItem.slug).toBe("service-fee");
|
|
1945
1928
|
expect(customLineItem.money.centAmount).toBe(1000);
|
|
@@ -1959,9 +1942,10 @@ describe("Cart Update Actions", () => {
|
|
|
1959
1942
|
test("removeCustomLineItem by ID", async () => {
|
|
1960
1943
|
assert(cart, "cart not created");
|
|
1961
1944
|
|
|
1962
|
-
const addResponse = await
|
|
1963
|
-
|
|
1964
|
-
.
|
|
1945
|
+
const addResponse = await ctMock.app.inject({
|
|
1946
|
+
method: "POST",
|
|
1947
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1948
|
+
payload: {
|
|
1965
1949
|
version: 1,
|
|
1966
1950
|
actions: [
|
|
1967
1951
|
{
|
|
@@ -1975,34 +1959,38 @@ describe("Cart Update Actions", () => {
|
|
|
1975
1959
|
quantity: 1,
|
|
1976
1960
|
},
|
|
1977
1961
|
],
|
|
1978
|
-
}
|
|
1962
|
+
},
|
|
1963
|
+
});
|
|
1979
1964
|
|
|
1980
|
-
expect(addResponse.
|
|
1981
|
-
expect(addResponse.
|
|
1965
|
+
expect(addResponse.statusCode).toBe(200);
|
|
1966
|
+
expect(addResponse.json().customLineItems).toHaveLength(1);
|
|
1982
1967
|
|
|
1983
|
-
const customLineItemId = addResponse.
|
|
1984
|
-
const removeResponse = await
|
|
1985
|
-
|
|
1986
|
-
.
|
|
1987
|
-
|
|
1968
|
+
const customLineItemId = addResponse.json().customLineItems[0].id;
|
|
1969
|
+
const removeResponse = await ctMock.app.inject({
|
|
1970
|
+
method: "POST",
|
|
1971
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1972
|
+
payload: {
|
|
1973
|
+
version: addResponse.json().version,
|
|
1988
1974
|
actions: [
|
|
1989
1975
|
{
|
|
1990
1976
|
action: "removeCustomLineItem",
|
|
1991
1977
|
customLineItemId,
|
|
1992
1978
|
},
|
|
1993
1979
|
],
|
|
1994
|
-
}
|
|
1980
|
+
},
|
|
1981
|
+
});
|
|
1995
1982
|
|
|
1996
|
-
expect(removeResponse.
|
|
1997
|
-
expect(removeResponse.
|
|
1983
|
+
expect(removeResponse.statusCode).toBe(200);
|
|
1984
|
+
expect(removeResponse.json().customLineItems).toHaveLength(0);
|
|
1998
1985
|
});
|
|
1999
1986
|
|
|
2000
1987
|
test("removeCustomLineItem by key", async () => {
|
|
2001
1988
|
assert(cart, "cart not created");
|
|
2002
1989
|
|
|
2003
|
-
const addResponse = await
|
|
2004
|
-
|
|
2005
|
-
.
|
|
1990
|
+
const addResponse = await ctMock.app.inject({
|
|
1991
|
+
method: "POST",
|
|
1992
|
+
url: `/dummy/carts/${cart.id}`,
|
|
1993
|
+
payload: {
|
|
2006
1994
|
version: 1,
|
|
2007
1995
|
actions: [
|
|
2008
1996
|
{
|
|
@@ -2017,32 +2005,36 @@ describe("Cart Update Actions", () => {
|
|
|
2017
2005
|
quantity: 1,
|
|
2018
2006
|
},
|
|
2019
2007
|
],
|
|
2020
|
-
}
|
|
2008
|
+
},
|
|
2009
|
+
});
|
|
2021
2010
|
|
|
2022
|
-
expect(addResponse.
|
|
2023
|
-
expect(addResponse.
|
|
2011
|
+
expect(addResponse.statusCode).toBe(200);
|
|
2012
|
+
expect(addResponse.json().customLineItems).toHaveLength(1);
|
|
2024
2013
|
|
|
2025
|
-
const removeResponse = await
|
|
2026
|
-
|
|
2027
|
-
.
|
|
2028
|
-
|
|
2014
|
+
const removeResponse = await ctMock.app.inject({
|
|
2015
|
+
method: "POST",
|
|
2016
|
+
url: `/dummy/carts/${cart.id}`,
|
|
2017
|
+
payload: {
|
|
2018
|
+
version: addResponse.json().version,
|
|
2029
2019
|
actions: [
|
|
2030
2020
|
{
|
|
2031
2021
|
action: "removeCustomLineItem",
|
|
2032
2022
|
customLineItemKey: "custom-service-fee",
|
|
2033
2023
|
},
|
|
2034
2024
|
],
|
|
2035
|
-
}
|
|
2025
|
+
},
|
|
2026
|
+
});
|
|
2036
2027
|
|
|
2037
|
-
expect(removeResponse.
|
|
2038
|
-
expect(removeResponse.
|
|
2028
|
+
expect(removeResponse.statusCode).toBe(200);
|
|
2029
|
+
expect(removeResponse.json().customLineItems).toHaveLength(0);
|
|
2039
2030
|
});
|
|
2040
2031
|
|
|
2041
2032
|
test("changeCustomLineItemQuantity", async () => {
|
|
2042
2033
|
assert(cart, "cart not created");
|
|
2043
|
-
const addResponse = await
|
|
2044
|
-
|
|
2045
|
-
.
|
|
2034
|
+
const addResponse = await ctMock.app.inject({
|
|
2035
|
+
method: "POST",
|
|
2036
|
+
url: `/dummy/carts/${cart.id}`,
|
|
2037
|
+
payload: {
|
|
2046
2038
|
version: 1,
|
|
2047
2039
|
actions: [
|
|
2048
2040
|
{
|
|
@@ -2056,13 +2048,15 @@ describe("Cart Update Actions", () => {
|
|
|
2056
2048
|
quantity: 1,
|
|
2057
2049
|
},
|
|
2058
2050
|
],
|
|
2059
|
-
}
|
|
2051
|
+
},
|
|
2052
|
+
});
|
|
2060
2053
|
|
|
2061
|
-
const customLineItemId = addResponse.
|
|
2062
|
-
const changeResponse = await
|
|
2063
|
-
|
|
2064
|
-
.
|
|
2065
|
-
|
|
2054
|
+
const customLineItemId = addResponse.json().customLineItems[0].id;
|
|
2055
|
+
const changeResponse = await ctMock.app.inject({
|
|
2056
|
+
method: "POST",
|
|
2057
|
+
url: `/dummy/carts/${cart.id}`,
|
|
2058
|
+
payload: {
|
|
2059
|
+
version: addResponse.json().version,
|
|
2066
2060
|
actions: [
|
|
2067
2061
|
{
|
|
2068
2062
|
action: "changeCustomLineItemQuantity",
|
|
@@ -2070,21 +2064,23 @@ describe("Cart Update Actions", () => {
|
|
|
2070
2064
|
quantity: 3,
|
|
2071
2065
|
},
|
|
2072
2066
|
],
|
|
2073
|
-
}
|
|
2067
|
+
},
|
|
2068
|
+
});
|
|
2074
2069
|
|
|
2075
|
-
expect(changeResponse.
|
|
2076
|
-
expect(changeResponse.
|
|
2070
|
+
expect(changeResponse.statusCode).toBe(200);
|
|
2071
|
+
expect(changeResponse.json().customLineItems).toHaveLength(1);
|
|
2077
2072
|
|
|
2078
|
-
const customLineItem = changeResponse.
|
|
2073
|
+
const customLineItem = changeResponse.json().customLineItems[0];
|
|
2079
2074
|
expect(customLineItem.quantity).toBe(3);
|
|
2080
2075
|
expect(customLineItem.totalPrice.centAmount).toBe(3000);
|
|
2081
2076
|
});
|
|
2082
2077
|
|
|
2083
2078
|
test("changeCustomLineItemMoney", async () => {
|
|
2084
2079
|
assert(cart, "cart not created");
|
|
2085
|
-
const addResponse = await
|
|
2086
|
-
|
|
2087
|
-
.
|
|
2080
|
+
const addResponse = await ctMock.app.inject({
|
|
2081
|
+
method: "POST",
|
|
2082
|
+
url: `/dummy/carts/${cart.id}`,
|
|
2083
|
+
payload: {
|
|
2088
2084
|
version: 1,
|
|
2089
2085
|
actions: [
|
|
2090
2086
|
{
|
|
@@ -2098,13 +2094,15 @@ describe("Cart Update Actions", () => {
|
|
|
2098
2094
|
quantity: 2,
|
|
2099
2095
|
},
|
|
2100
2096
|
],
|
|
2101
|
-
}
|
|
2097
|
+
},
|
|
2098
|
+
});
|
|
2102
2099
|
|
|
2103
|
-
const customLineItemId = addResponse.
|
|
2104
|
-
const changeResponse = await
|
|
2105
|
-
|
|
2106
|
-
.
|
|
2107
|
-
|
|
2100
|
+
const customLineItemId = addResponse.json().customLineItems[0].id;
|
|
2101
|
+
const changeResponse = await ctMock.app.inject({
|
|
2102
|
+
method: "POST",
|
|
2103
|
+
url: `/dummy/carts/${cart.id}`,
|
|
2104
|
+
payload: {
|
|
2105
|
+
version: addResponse.json().version,
|
|
2108
2106
|
actions: [
|
|
2109
2107
|
{
|
|
2110
2108
|
action: "changeCustomLineItemMoney",
|
|
@@ -2115,12 +2113,13 @@ describe("Cart Update Actions", () => {
|
|
|
2115
2113
|
},
|
|
2116
2114
|
},
|
|
2117
2115
|
],
|
|
2118
|
-
}
|
|
2116
|
+
},
|
|
2117
|
+
});
|
|
2119
2118
|
|
|
2120
|
-
expect(changeResponse.
|
|
2121
|
-
expect(changeResponse.
|
|
2119
|
+
expect(changeResponse.statusCode).toBe(200);
|
|
2120
|
+
expect(changeResponse.json().customLineItems).toHaveLength(1);
|
|
2122
2121
|
|
|
2123
|
-
const customLineItem = changeResponse.
|
|
2122
|
+
const customLineItem = changeResponse.json().customLineItems[0];
|
|
2124
2123
|
expect(customLineItem.money.centAmount).toBe(1500);
|
|
2125
2124
|
expect(customLineItem.totalPrice.centAmount).toBe(3000);
|
|
2126
2125
|
});
|
|
@@ -2128,9 +2127,10 @@ describe("Cart Update Actions", () => {
|
|
|
2128
2127
|
test("addCustomLineItem with tax calculation", async () => {
|
|
2129
2128
|
assert(cart, "cart not created");
|
|
2130
2129
|
|
|
2131
|
-
const response = await
|
|
2132
|
-
|
|
2133
|
-
.
|
|
2130
|
+
const response = await ctMock.app.inject({
|
|
2131
|
+
method: "POST",
|
|
2132
|
+
url: `/dummy/carts/${cart.id}`,
|
|
2133
|
+
payload: {
|
|
2134
2134
|
version: 1,
|
|
2135
2135
|
actions: [
|
|
2136
2136
|
{
|
|
@@ -2148,10 +2148,11 @@ describe("Cart Update Actions", () => {
|
|
|
2148
2148
|
},
|
|
2149
2149
|
},
|
|
2150
2150
|
],
|
|
2151
|
-
}
|
|
2151
|
+
},
|
|
2152
|
+
});
|
|
2152
2153
|
|
|
2153
|
-
expect(response.
|
|
2154
|
-
const customLineItem = response.
|
|
2154
|
+
expect(response.statusCode).toBe(200);
|
|
2155
|
+
const customLineItem = response.json().customLineItems[0];
|
|
2155
2156
|
|
|
2156
2157
|
expect(customLineItem.taxedPrice).toBeDefined();
|
|
2157
2158
|
expect(customLineItem.taxedPrice.totalNet.centAmount).toBe(1000);
|