@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
|
@@ -1,31 +1,22 @@
|
|
|
1
1
|
import assert from "node:assert";
|
|
2
|
-
import type {
|
|
3
|
-
Customer,
|
|
4
|
-
CustomerDraft,
|
|
5
|
-
CustomerToken,
|
|
6
|
-
} from "@commercetools/platform-sdk";
|
|
7
|
-
import supertest from "supertest";
|
|
2
|
+
import type { Customer, CustomerToken } from "@commercetools/platform-sdk";
|
|
8
3
|
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
9
4
|
import { hashPassword } from "#src/lib/password.ts";
|
|
10
|
-
import { customerDraftFactory } from "#src/testing/
|
|
5
|
+
import { customerDraftFactory } from "#src/testing/index.ts";
|
|
11
6
|
import { CommercetoolsMock, getBaseResourceProperties } from "../index.ts";
|
|
12
7
|
|
|
13
8
|
const ctMock = new CommercetoolsMock();
|
|
14
9
|
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
ctMock.clear();
|
|
10
|
+
afterEach(async () => {
|
|
11
|
+
await ctMock.clear();
|
|
17
12
|
});
|
|
18
13
|
|
|
19
14
|
describe("Customer create", () => {
|
|
20
|
-
|
|
21
|
-
const draft = customerDraftFactory(ctMock).build();
|
|
15
|
+
const factory = customerDraftFactory(ctMock);
|
|
22
16
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
.send(draft);
|
|
17
|
+
test("create new customer", async () => {
|
|
18
|
+
const customer = await factory.create();
|
|
26
19
|
|
|
27
|
-
const customer = response.body.customer as Customer;
|
|
28
|
-
expect(response.status, JSON.stringify(customer)).toBe(201);
|
|
29
20
|
expect(customer.version).toBe(1);
|
|
30
21
|
expect(customer.defaultBillingAddressId).toBeUndefined();
|
|
31
22
|
expect(customer.defaultShippingAddressId).toBeUndefined();
|
|
@@ -34,7 +25,7 @@ describe("Customer create", () => {
|
|
|
34
25
|
});
|
|
35
26
|
|
|
36
27
|
test("create new customer with default billing & shipping address", async () => {
|
|
37
|
-
const
|
|
28
|
+
const customer = await factory.create({
|
|
38
29
|
email: "new-user@example.com",
|
|
39
30
|
password: "supersecret",
|
|
40
31
|
authenticationMode: "Password",
|
|
@@ -52,14 +43,8 @@ describe("Customer create", () => {
|
|
|
52
43
|
],
|
|
53
44
|
defaultBillingAddress: 0,
|
|
54
45
|
defaultShippingAddress: 0,
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const response = await supertest(ctMock.app)
|
|
58
|
-
.post("/dummy/customers")
|
|
59
|
-
.send(draft);
|
|
46
|
+
});
|
|
60
47
|
|
|
61
|
-
const customer = response.body.customer as Customer;
|
|
62
|
-
expect(response.status, JSON.stringify(customer)).toBe(201);
|
|
63
48
|
expect(customer.version).toBe(1);
|
|
64
49
|
expect(customer.defaultBillingAddressId).toBeDefined();
|
|
65
50
|
expect(customer.defaultShippingAddressId).toBeDefined();
|
|
@@ -69,11 +54,14 @@ describe("Customer create", () => {
|
|
|
69
54
|
});
|
|
70
55
|
|
|
71
56
|
describe("Customer Update Actions", () => {
|
|
57
|
+
const factory = customerDraftFactory(ctMock);
|
|
58
|
+
|
|
72
59
|
test("addAddress", async () => {
|
|
73
|
-
const customer = await
|
|
74
|
-
const response = await
|
|
75
|
-
|
|
76
|
-
.
|
|
60
|
+
const customer = await factory.create();
|
|
61
|
+
const response = await ctMock.app.inject({
|
|
62
|
+
method: "POST",
|
|
63
|
+
url: `/dummy/customers/${customer.id}`,
|
|
64
|
+
payload: {
|
|
77
65
|
version: 1,
|
|
78
66
|
actions: [
|
|
79
67
|
{
|
|
@@ -88,14 +76,15 @@ describe("Customer Update Actions", () => {
|
|
|
88
76
|
},
|
|
89
77
|
},
|
|
90
78
|
],
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
expect(response.
|
|
94
|
-
expect(response.
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
expect(response.statusCode).toBe(200);
|
|
82
|
+
expect(response.json().version).toBe(2);
|
|
83
|
+
expect(response.json().addresses).toHaveLength(2);
|
|
95
84
|
});
|
|
96
85
|
|
|
97
86
|
test("removeAddress by ID", async () => {
|
|
98
|
-
const customer = await
|
|
87
|
+
const customer = await factory.create({
|
|
99
88
|
addresses: [
|
|
100
89
|
{
|
|
101
90
|
key: "address-key",
|
|
@@ -109,9 +98,10 @@ describe("Customer Update Actions", () => {
|
|
|
109
98
|
],
|
|
110
99
|
});
|
|
111
100
|
|
|
112
|
-
const response = await
|
|
113
|
-
|
|
114
|
-
.
|
|
101
|
+
const response = await ctMock.app.inject({
|
|
102
|
+
method: "POST",
|
|
103
|
+
url: `/dummy/customers/${customer.id}`,
|
|
104
|
+
payload: {
|
|
115
105
|
version: 1,
|
|
116
106
|
actions: [
|
|
117
107
|
{
|
|
@@ -119,14 +109,15 @@ describe("Customer Update Actions", () => {
|
|
|
119
109
|
addressId: customer.addresses[0].id,
|
|
120
110
|
},
|
|
121
111
|
],
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
expect(response.
|
|
125
|
-
expect(response.
|
|
112
|
+
},
|
|
113
|
+
});
|
|
114
|
+
expect(response.statusCode, JSON.stringify(response.json())).toBe(200);
|
|
115
|
+
expect(response.json().version).toBe(2);
|
|
116
|
+
expect(response.json().addresses).toHaveLength(0);
|
|
126
117
|
});
|
|
127
118
|
|
|
128
119
|
test("removeAddress by Key", async () => {
|
|
129
|
-
const customer = await
|
|
120
|
+
const customer = await factory.create({
|
|
130
121
|
addresses: [
|
|
131
122
|
{
|
|
132
123
|
key: "address-key",
|
|
@@ -140,9 +131,10 @@ describe("Customer Update Actions", () => {
|
|
|
140
131
|
],
|
|
141
132
|
});
|
|
142
133
|
|
|
143
|
-
const response = await
|
|
144
|
-
|
|
145
|
-
.
|
|
134
|
+
const response = await ctMock.app.inject({
|
|
135
|
+
method: "POST",
|
|
136
|
+
url: `/dummy/customers/${customer.id}`,
|
|
137
|
+
payload: {
|
|
146
138
|
version: 1,
|
|
147
139
|
actions: [
|
|
148
140
|
{
|
|
@@ -150,14 +142,15 @@ describe("Customer Update Actions", () => {
|
|
|
150
142
|
addressKey: customer.addresses[0].key,
|
|
151
143
|
},
|
|
152
144
|
],
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
expect(response.
|
|
156
|
-
expect(response.
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
expect(response.statusCode, JSON.stringify(response.json())).toBe(200);
|
|
148
|
+
expect(response.json().version).toBe(2);
|
|
149
|
+
expect(response.json().addresses).toHaveLength(0);
|
|
157
150
|
});
|
|
158
151
|
|
|
159
152
|
test("changeAddress by ID", async () => {
|
|
160
|
-
const customer = await
|
|
153
|
+
const customer = await factory.create({
|
|
161
154
|
addresses: [
|
|
162
155
|
{
|
|
163
156
|
key: "address-key",
|
|
@@ -172,9 +165,10 @@ describe("Customer Update Actions", () => {
|
|
|
172
165
|
});
|
|
173
166
|
const addressId = customer.addresses[0].id;
|
|
174
167
|
|
|
175
|
-
const response = await
|
|
176
|
-
|
|
177
|
-
.
|
|
168
|
+
const response = await ctMock.app.inject({
|
|
169
|
+
method: "POST",
|
|
170
|
+
url: `/dummy/customers/${customer.id}`,
|
|
171
|
+
payload: {
|
|
178
172
|
version: 1,
|
|
179
173
|
actions: [
|
|
180
174
|
{
|
|
@@ -190,9 +184,10 @@ describe("Customer Update Actions", () => {
|
|
|
190
184
|
},
|
|
191
185
|
},
|
|
192
186
|
],
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
expect(response.statusCode, JSON.stringify(response.json())).toBe(200);
|
|
190
|
+
const result = response.json() as Customer;
|
|
196
191
|
expect(result.version).toBe(2);
|
|
197
192
|
expect(result.addresses).toHaveLength(1);
|
|
198
193
|
expect(result.addresses).toStrictEqual([
|
|
@@ -209,7 +204,7 @@ describe("Customer Update Actions", () => {
|
|
|
209
204
|
});
|
|
210
205
|
|
|
211
206
|
test("addBillingAddressId", async () => {
|
|
212
|
-
const customer = await
|
|
207
|
+
const customer = await factory.create({
|
|
213
208
|
addresses: [
|
|
214
209
|
{
|
|
215
210
|
key: "address-key",
|
|
@@ -223,9 +218,10 @@ describe("Customer Update Actions", () => {
|
|
|
223
218
|
],
|
|
224
219
|
});
|
|
225
220
|
|
|
226
|
-
const response = await
|
|
227
|
-
|
|
228
|
-
.
|
|
221
|
+
const response = await ctMock.app.inject({
|
|
222
|
+
method: "POST",
|
|
223
|
+
url: `/dummy/customers/${customer.id}`,
|
|
224
|
+
payload: {
|
|
229
225
|
version: 1,
|
|
230
226
|
actions: [
|
|
231
227
|
{
|
|
@@ -233,15 +229,16 @@ describe("Customer Update Actions", () => {
|
|
|
233
229
|
addressId: customer.addresses[0].id,
|
|
234
230
|
},
|
|
235
231
|
],
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
expect(response.
|
|
239
|
-
expect(response.
|
|
240
|
-
expect(response.
|
|
232
|
+
},
|
|
233
|
+
});
|
|
234
|
+
expect(response.statusCode).toBe(200);
|
|
235
|
+
expect(response.json().version).toBe(2);
|
|
236
|
+
expect(response.json().shippingAddressIds).toHaveLength(0);
|
|
237
|
+
expect(response.json().billingAddressIds).toHaveLength(1);
|
|
241
238
|
});
|
|
242
239
|
|
|
243
240
|
test("removeBillingAddressId", async () => {
|
|
244
|
-
const customer = await
|
|
241
|
+
const customer = await factory.create({
|
|
245
242
|
addresses: [
|
|
246
243
|
{
|
|
247
244
|
key: "address-key",
|
|
@@ -260,9 +257,10 @@ describe("Customer Update Actions", () => {
|
|
|
260
257
|
expect(customer.defaultBillingAddressId).toBeDefined();
|
|
261
258
|
|
|
262
259
|
const addressId = customer.addresses[0].id;
|
|
263
|
-
const response = await
|
|
264
|
-
|
|
265
|
-
.
|
|
260
|
+
const response = await ctMock.app.inject({
|
|
261
|
+
method: "POST",
|
|
262
|
+
url: `/dummy/customers/${customer.id}`,
|
|
263
|
+
payload: {
|
|
266
264
|
version: 1,
|
|
267
265
|
actions: [
|
|
268
266
|
{
|
|
@@ -270,16 +268,17 @@ describe("Customer Update Actions", () => {
|
|
|
270
268
|
addressId: addressId,
|
|
271
269
|
},
|
|
272
270
|
],
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
expect(response.statusCode).toBe(200);
|
|
274
|
+
const result = response.json() as Customer;
|
|
276
275
|
expect(result.version).toBe(2);
|
|
277
276
|
expect(result.billingAddressIds).toHaveLength(0);
|
|
278
277
|
expect(result.defaultBillingAddressId).toBeUndefined();
|
|
279
278
|
});
|
|
280
279
|
|
|
281
280
|
test("setDefaultBillingAddress by ID", async () => {
|
|
282
|
-
const customer = await
|
|
281
|
+
const customer = await factory.create({
|
|
283
282
|
defaultBillingAddress: undefined,
|
|
284
283
|
defaultShippingAddress: undefined,
|
|
285
284
|
addresses: [
|
|
@@ -298,9 +297,10 @@ describe("Customer Update Actions", () => {
|
|
|
298
297
|
});
|
|
299
298
|
const addressId = customer.addresses[0].id;
|
|
300
299
|
|
|
301
|
-
const response = await
|
|
302
|
-
|
|
303
|
-
.
|
|
300
|
+
const response = await ctMock.app.inject({
|
|
301
|
+
method: "POST",
|
|
302
|
+
url: `/dummy/customers/${customer.id}`,
|
|
303
|
+
payload: {
|
|
304
304
|
version: customer.version,
|
|
305
305
|
actions: [
|
|
306
306
|
{
|
|
@@ -308,16 +308,17 @@ describe("Customer Update Actions", () => {
|
|
|
308
308
|
addressId: addressId,
|
|
309
309
|
},
|
|
310
310
|
],
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
expect(response.
|
|
314
|
-
expect(response.
|
|
315
|
-
expect(response.
|
|
316
|
-
expect(response.
|
|
311
|
+
},
|
|
312
|
+
});
|
|
313
|
+
expect(response.statusCode, JSON.stringify(response.json())).toBe(200);
|
|
314
|
+
expect(response.json().version).toBe(2);
|
|
315
|
+
expect(response.json().defaultBillingAddressId).toBe(addressId);
|
|
316
|
+
expect(response.json().addresses).toHaveLength(1);
|
|
317
|
+
expect(response.json().billingAddressIds).toContain(addressId);
|
|
317
318
|
});
|
|
318
319
|
|
|
319
320
|
test("addShippingAddressId", async () => {
|
|
320
|
-
const customer = await
|
|
321
|
+
const customer = await factory.create({
|
|
321
322
|
addresses: [
|
|
322
323
|
{
|
|
323
324
|
key: "address-key",
|
|
@@ -331,9 +332,10 @@ describe("Customer Update Actions", () => {
|
|
|
331
332
|
],
|
|
332
333
|
});
|
|
333
334
|
|
|
334
|
-
const response = await
|
|
335
|
-
|
|
336
|
-
.
|
|
335
|
+
const response = await ctMock.app.inject({
|
|
336
|
+
method: "POST",
|
|
337
|
+
url: `/dummy/customers/${customer.id}`,
|
|
338
|
+
payload: {
|
|
337
339
|
version: 1,
|
|
338
340
|
actions: [
|
|
339
341
|
{
|
|
@@ -341,14 +343,15 @@ describe("Customer Update Actions", () => {
|
|
|
341
343
|
addressId: customer.addresses[0].id,
|
|
342
344
|
},
|
|
343
345
|
],
|
|
344
|
-
}
|
|
345
|
-
|
|
346
|
-
expect(response.
|
|
347
|
-
expect(response.
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
expect(response.statusCode).toBe(200);
|
|
349
|
+
expect(response.json().version).toBe(2);
|
|
350
|
+
expect(response.json().shippingAddressIds).toHaveLength(1);
|
|
348
351
|
});
|
|
349
352
|
|
|
350
353
|
test("removeShippingAddressId", async () => {
|
|
351
|
-
const customer = await
|
|
354
|
+
const customer = await factory.create({
|
|
352
355
|
addresses: [
|
|
353
356
|
{
|
|
354
357
|
key: "address-key",
|
|
@@ -367,9 +370,10 @@ describe("Customer Update Actions", () => {
|
|
|
367
370
|
expect(customer.defaultShippingAddressId).toBeDefined();
|
|
368
371
|
|
|
369
372
|
const addressId = customer.addresses[0].id;
|
|
370
|
-
const response = await
|
|
371
|
-
|
|
372
|
-
.
|
|
373
|
+
const response = await ctMock.app.inject({
|
|
374
|
+
method: "POST",
|
|
375
|
+
url: `/dummy/customers/${customer.id}`,
|
|
376
|
+
payload: {
|
|
373
377
|
version: 1,
|
|
374
378
|
actions: [
|
|
375
379
|
{
|
|
@@ -377,16 +381,17 @@ describe("Customer Update Actions", () => {
|
|
|
377
381
|
addressId: addressId,
|
|
378
382
|
},
|
|
379
383
|
],
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
|
|
384
|
+
},
|
|
385
|
+
});
|
|
386
|
+
expect(response.statusCode).toBe(200);
|
|
387
|
+
const result = response.json() as Customer;
|
|
383
388
|
expect(result.version).toBe(2);
|
|
384
389
|
expect(result.shippingAddressIds).toHaveLength(0);
|
|
385
390
|
expect(result.defaultShippingAddressId).toBeUndefined();
|
|
386
391
|
});
|
|
387
392
|
|
|
388
393
|
test("setDefaultShippingAddress by ID", async () => {
|
|
389
|
-
const customer = await
|
|
394
|
+
const customer = await factory.create({
|
|
390
395
|
defaultBillingAddress: undefined,
|
|
391
396
|
defaultShippingAddress: undefined,
|
|
392
397
|
addresses: [
|
|
@@ -405,9 +410,10 @@ describe("Customer Update Actions", () => {
|
|
|
405
410
|
});
|
|
406
411
|
const addressId = customer.addresses[0].id;
|
|
407
412
|
|
|
408
|
-
const response = await
|
|
409
|
-
|
|
410
|
-
.
|
|
413
|
+
const response = await ctMock.app.inject({
|
|
414
|
+
method: "POST",
|
|
415
|
+
url: `/dummy/customers/${customer.id}`,
|
|
416
|
+
payload: {
|
|
411
417
|
version: customer.version,
|
|
412
418
|
actions: [
|
|
413
419
|
{
|
|
@@ -415,9 +421,10 @@ describe("Customer Update Actions", () => {
|
|
|
415
421
|
addressId: addressId,
|
|
416
422
|
},
|
|
417
423
|
],
|
|
418
|
-
}
|
|
419
|
-
|
|
420
|
-
|
|
424
|
+
},
|
|
425
|
+
});
|
|
426
|
+
expect(response.statusCode, JSON.stringify(response.json())).toBe(200);
|
|
427
|
+
const result = response.json() as Customer;
|
|
421
428
|
expect(result.version).toBe(2);
|
|
422
429
|
expect(result.defaultShippingAddressId).toBe(addressId);
|
|
423
430
|
expect(result.addresses).toHaveLength(1);
|
|
@@ -425,7 +432,7 @@ describe("Customer Update Actions", () => {
|
|
|
425
432
|
});
|
|
426
433
|
});
|
|
427
434
|
|
|
428
|
-
// These tests use ctMock.project().
|
|
435
|
+
// These tests use ctMock.project().unsafeAdd(), which we want to move away from.
|
|
429
436
|
// Please add new test to the previous section.
|
|
430
437
|
describe("Customer Update Actions (old-style)", () => {
|
|
431
438
|
let customer: Customer | undefined;
|
|
@@ -441,59 +448,68 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
441
448
|
authenticationMode: "Password", //default in Commercetools
|
|
442
449
|
version: 1,
|
|
443
450
|
stores: [],
|
|
451
|
+
shippingAddressIds: [],
|
|
452
|
+
billingAddressIds: [],
|
|
453
|
+
customerGroupAssignments: [],
|
|
444
454
|
};
|
|
445
|
-
ctMock.project("dummy").
|
|
455
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
446
456
|
});
|
|
447
457
|
|
|
448
458
|
test("exists", async () => {
|
|
449
459
|
assert(customer, "customer not created");
|
|
450
460
|
|
|
451
|
-
const response = await
|
|
452
|
-
|
|
453
|
-
.
|
|
461
|
+
const response = await ctMock.app.inject({
|
|
462
|
+
method: "HEAD",
|
|
463
|
+
url: `/dummy/customers/${customer.id}`,
|
|
464
|
+
});
|
|
454
465
|
|
|
455
|
-
expect(response.
|
|
466
|
+
expect(response.statusCode).toBe(200);
|
|
456
467
|
});
|
|
457
468
|
|
|
458
469
|
test("non-existent", async () => {
|
|
459
470
|
assert(customer, "customer not created");
|
|
460
471
|
|
|
461
|
-
const response = await
|
|
462
|
-
|
|
463
|
-
|
|
472
|
+
const response = await ctMock.app.inject({
|
|
473
|
+
method: "HEAD",
|
|
474
|
+
url: "/dummy/customers/invalid-id",
|
|
475
|
+
});
|
|
464
476
|
|
|
465
|
-
expect(response.
|
|
477
|
+
expect(response.statusCode).toBe(404);
|
|
466
478
|
});
|
|
467
479
|
|
|
468
480
|
test("changeEmail", async () => {
|
|
469
481
|
assert(customer, "customer not created");
|
|
470
482
|
|
|
471
|
-
const response = await
|
|
472
|
-
|
|
473
|
-
.
|
|
483
|
+
const response = await ctMock.app.inject({
|
|
484
|
+
method: "POST",
|
|
485
|
+
url: `/dummy/customers/${customer.id}`,
|
|
486
|
+
payload: {
|
|
474
487
|
version: 1,
|
|
475
488
|
actions: [{ action: "changeEmail", email: "new@example.com" }],
|
|
476
|
-
}
|
|
477
|
-
|
|
478
|
-
expect(response.
|
|
479
|
-
expect(response.
|
|
489
|
+
},
|
|
490
|
+
});
|
|
491
|
+
expect(response.statusCode).toBe(200);
|
|
492
|
+
expect(response.json().version).toBe(2);
|
|
493
|
+
expect(response.json().email).toBe("new@example.com");
|
|
480
494
|
});
|
|
481
495
|
|
|
482
496
|
test("setAuthenticationMode to an invalid mode", async () => {
|
|
483
497
|
assert(customer, "customer not created");
|
|
484
498
|
|
|
485
|
-
const response = await
|
|
486
|
-
|
|
487
|
-
.
|
|
499
|
+
const response = await ctMock.app.inject({
|
|
500
|
+
method: "POST",
|
|
501
|
+
url: `/dummy/customers/${customer.id}`,
|
|
502
|
+
payload: {
|
|
488
503
|
version: 1,
|
|
489
504
|
actions: [{ action: "setAuthenticationMode", authMode: "invalid" }],
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
expect(response.
|
|
505
|
+
},
|
|
506
|
+
});
|
|
507
|
+
expect(response.statusCode).toBe(400);
|
|
508
|
+
expect(response.json().message).toBe(
|
|
493
509
|
"Request body does not contain valid JSON.",
|
|
494
510
|
);
|
|
495
|
-
expect(response.
|
|
496
|
-
expect(response.
|
|
511
|
+
expect(response.json().errors[0].code).toBe("InvalidJsonInput");
|
|
512
|
+
expect(response.json().errors[0].detailedErrorMessage).toBe(
|
|
497
513
|
"actions -> authMode: Invalid enum value: 'invalid'. Expected one of: 'Password','ExternalAuth'",
|
|
498
514
|
);
|
|
499
515
|
});
|
|
@@ -501,18 +517,20 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
501
517
|
test("setAuthenticationMode to ExternalAuth", async () => {
|
|
502
518
|
assert(customer, "customer not created");
|
|
503
519
|
|
|
504
|
-
const response = await
|
|
505
|
-
|
|
506
|
-
.
|
|
520
|
+
const response = await ctMock.app.inject({
|
|
521
|
+
method: "POST",
|
|
522
|
+
url: `/dummy/customers/${customer.id}`,
|
|
523
|
+
payload: {
|
|
507
524
|
version: 1,
|
|
508
525
|
actions: [
|
|
509
526
|
{ action: "setAuthenticationMode", authMode: "ExternalAuth" },
|
|
510
527
|
],
|
|
511
|
-
}
|
|
512
|
-
|
|
513
|
-
expect(response.
|
|
514
|
-
expect(response.
|
|
515
|
-
expect(response.
|
|
528
|
+
},
|
|
529
|
+
});
|
|
530
|
+
expect(response.statusCode).toBe(200);
|
|
531
|
+
expect(response.json().version).toBe(2);
|
|
532
|
+
expect(response.json().authenticationMode).toBe("ExternalAuth");
|
|
533
|
+
expect(response.json().password).toBe(undefined);
|
|
516
534
|
});
|
|
517
535
|
|
|
518
536
|
test("setAuthenticationMode error when setting current authMode", async () => {
|
|
@@ -522,9 +540,10 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
522
540
|
"customer not in default state",
|
|
523
541
|
);
|
|
524
542
|
|
|
525
|
-
const response = await
|
|
526
|
-
|
|
527
|
-
.
|
|
543
|
+
const response = await ctMock.app.inject({
|
|
544
|
+
method: "POST",
|
|
545
|
+
url: `/dummy/customers/${customer.id}`,
|
|
546
|
+
payload: {
|
|
528
547
|
version: 1,
|
|
529
548
|
actions: [
|
|
530
549
|
{
|
|
@@ -533,9 +552,10 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
533
552
|
password: "newpass",
|
|
534
553
|
},
|
|
535
554
|
],
|
|
536
|
-
}
|
|
537
|
-
|
|
538
|
-
expect(response.
|
|
555
|
+
},
|
|
556
|
+
});
|
|
557
|
+
expect(response.statusCode).toBe(400);
|
|
558
|
+
expect(response.json().message).toBe(
|
|
539
559
|
"The customer is already using the 'Password' authentication mode.",
|
|
540
560
|
);
|
|
541
561
|
});
|
|
@@ -544,19 +564,22 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
544
564
|
assert(customer, "customer not created");
|
|
545
565
|
|
|
546
566
|
//change *away from* Password authMode (to be able to test changing *to* Password authMode)
|
|
547
|
-
await
|
|
548
|
-
|
|
549
|
-
.
|
|
567
|
+
await ctMock.app.inject({
|
|
568
|
+
method: "POST",
|
|
569
|
+
url: `/dummy/customers/${customer.id}`,
|
|
570
|
+
payload: {
|
|
550
571
|
version: 1,
|
|
551
572
|
actions: [
|
|
552
573
|
{ action: "setAuthenticationMode", authMode: "ExternalAuth" },
|
|
553
574
|
],
|
|
554
|
-
}
|
|
575
|
+
},
|
|
576
|
+
});
|
|
555
577
|
|
|
556
578
|
//change to Password authMode
|
|
557
|
-
const response = await
|
|
558
|
-
|
|
559
|
-
.
|
|
579
|
+
const response = await ctMock.app.inject({
|
|
580
|
+
method: "POST",
|
|
581
|
+
url: `/dummy/customers/${customer.id}`,
|
|
582
|
+
payload: {
|
|
560
583
|
version: 2,
|
|
561
584
|
actions: [
|
|
562
585
|
{
|
|
@@ -565,11 +588,12 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
565
588
|
password: "newpass",
|
|
566
589
|
},
|
|
567
590
|
],
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
expect(response.
|
|
571
|
-
expect(response.
|
|
572
|
-
expect(response.
|
|
591
|
+
},
|
|
592
|
+
});
|
|
593
|
+
expect(response.statusCode).toBe(200);
|
|
594
|
+
expect(response.json().version).toBe(3);
|
|
595
|
+
expect(response.json().authenticationMode).toBe("Password");
|
|
596
|
+
expect(response.json().password).toBe(
|
|
573
597
|
Buffer.from("newpass").toString("base64"),
|
|
574
598
|
);
|
|
575
599
|
});
|
|
@@ -581,19 +605,21 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
581
605
|
...customer,
|
|
582
606
|
custom: { type: { typeId: "type", id: "" }, fields: {} },
|
|
583
607
|
};
|
|
584
|
-
ctMock.project("dummy").
|
|
608
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
585
609
|
|
|
586
|
-
const response = await
|
|
587
|
-
|
|
588
|
-
.
|
|
610
|
+
const response = await ctMock.app.inject({
|
|
611
|
+
method: "POST",
|
|
612
|
+
url: `/dummy/customers/${customer.id}`,
|
|
613
|
+
payload: {
|
|
589
614
|
version: 1,
|
|
590
615
|
actions: [
|
|
591
616
|
{ action: "setCustomField", name: "isValidCouponCode", value: false },
|
|
592
617
|
],
|
|
593
|
-
}
|
|
594
|
-
|
|
595
|
-
expect(response.
|
|
596
|
-
expect(response.
|
|
618
|
+
},
|
|
619
|
+
});
|
|
620
|
+
expect(response.statusCode).toBe(200);
|
|
621
|
+
expect(response.json().version).toBe(2);
|
|
622
|
+
expect(response.json().custom.fields.isValidCouponCode).toBe(false);
|
|
597
623
|
});
|
|
598
624
|
|
|
599
625
|
test("setExternalId", async () => {
|
|
@@ -603,17 +629,19 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
603
629
|
...customer,
|
|
604
630
|
firstName: "John",
|
|
605
631
|
};
|
|
606
|
-
ctMock.project("dummy").
|
|
632
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
607
633
|
|
|
608
|
-
const response = await
|
|
609
|
-
|
|
610
|
-
.
|
|
634
|
+
const response = await ctMock.app.inject({
|
|
635
|
+
method: "POST",
|
|
636
|
+
url: `/dummy/customers/${customer.id}`,
|
|
637
|
+
payload: {
|
|
611
638
|
version: 1,
|
|
612
639
|
actions: [{ action: "setExternalId", externalId: "123-xx-123" }],
|
|
613
|
-
}
|
|
614
|
-
|
|
615
|
-
expect(response.
|
|
616
|
-
expect(response.
|
|
640
|
+
},
|
|
641
|
+
});
|
|
642
|
+
expect(response.statusCode).toBe(200);
|
|
643
|
+
expect(response.json().version).toBe(2);
|
|
644
|
+
expect(response.json().externalId).toBe("123-xx-123");
|
|
617
645
|
});
|
|
618
646
|
|
|
619
647
|
test("setFirstName", async () => {
|
|
@@ -623,17 +651,19 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
623
651
|
...customer,
|
|
624
652
|
firstName: "John",
|
|
625
653
|
};
|
|
626
|
-
ctMock.project("dummy").
|
|
654
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
627
655
|
|
|
628
|
-
const response = await
|
|
629
|
-
|
|
630
|
-
.
|
|
656
|
+
const response = await ctMock.app.inject({
|
|
657
|
+
method: "POST",
|
|
658
|
+
url: `/dummy/customers/${customer.id}`,
|
|
659
|
+
payload: {
|
|
631
660
|
version: 1,
|
|
632
661
|
actions: [{ action: "setFirstName", firstName: "Mary" }],
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
expect(response.
|
|
636
|
-
expect(response.
|
|
662
|
+
},
|
|
663
|
+
});
|
|
664
|
+
expect(response.statusCode).toBe(200);
|
|
665
|
+
expect(response.json().version).toBe(2);
|
|
666
|
+
expect(response.json().firstName).toBe("Mary");
|
|
637
667
|
});
|
|
638
668
|
|
|
639
669
|
test("setLastName", async () => {
|
|
@@ -643,17 +673,19 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
643
673
|
...customer,
|
|
644
674
|
lastName: "Doe",
|
|
645
675
|
};
|
|
646
|
-
ctMock.project("dummy").
|
|
676
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
647
677
|
|
|
648
|
-
const response = await
|
|
649
|
-
|
|
650
|
-
.
|
|
678
|
+
const response = await ctMock.app.inject({
|
|
679
|
+
method: "POST",
|
|
680
|
+
url: `/dummy/customers/${customer.id}`,
|
|
681
|
+
payload: {
|
|
651
682
|
version: 1,
|
|
652
683
|
actions: [{ action: "setLastName", lastName: "Smith" }],
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
expect(response.
|
|
656
|
-
expect(response.
|
|
684
|
+
},
|
|
685
|
+
});
|
|
686
|
+
expect(response.statusCode).toBe(200);
|
|
687
|
+
expect(response.json().version).toBe(2);
|
|
688
|
+
expect(response.json().lastName).toBe("Smith");
|
|
657
689
|
});
|
|
658
690
|
|
|
659
691
|
test("setLocale", async () => {
|
|
@@ -663,17 +695,19 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
663
695
|
...customer,
|
|
664
696
|
salutation: "Mr.",
|
|
665
697
|
};
|
|
666
|
-
ctMock.project("dummy").
|
|
698
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
667
699
|
|
|
668
|
-
const response = await
|
|
669
|
-
|
|
670
|
-
.
|
|
700
|
+
const response = await ctMock.app.inject({
|
|
701
|
+
method: "POST",
|
|
702
|
+
url: `/dummy/customers/${customer.id}`,
|
|
703
|
+
payload: {
|
|
671
704
|
version: 1,
|
|
672
705
|
actions: [{ action: "setLocale", locale: "de-DE" }],
|
|
673
|
-
}
|
|
674
|
-
|
|
675
|
-
expect(response.
|
|
676
|
-
expect(response.
|
|
706
|
+
},
|
|
707
|
+
});
|
|
708
|
+
expect(response.statusCode).toBe(200);
|
|
709
|
+
expect(response.json().version).toBe(2);
|
|
710
|
+
expect(response.json().locale).toBe("de-DE");
|
|
677
711
|
});
|
|
678
712
|
|
|
679
713
|
test("setSalutation", async () => {
|
|
@@ -683,17 +717,19 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
683
717
|
...customer,
|
|
684
718
|
salutation: "Mr.",
|
|
685
719
|
};
|
|
686
|
-
ctMock.project("dummy").
|
|
720
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
687
721
|
|
|
688
|
-
const response = await
|
|
689
|
-
|
|
690
|
-
.
|
|
722
|
+
const response = await ctMock.app.inject({
|
|
723
|
+
method: "POST",
|
|
724
|
+
url: `/dummy/customers/${customer.id}`,
|
|
725
|
+
payload: {
|
|
691
726
|
version: 1,
|
|
692
727
|
actions: [{ action: "setSalutation", salutation: "Mrs." }],
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
expect(response.
|
|
696
|
-
expect(response.
|
|
728
|
+
},
|
|
729
|
+
});
|
|
730
|
+
expect(response.statusCode).toBe(200);
|
|
731
|
+
expect(response.json().version).toBe(2);
|
|
732
|
+
expect(response.json().salutation).toBe("Mrs.");
|
|
697
733
|
});
|
|
698
734
|
|
|
699
735
|
test("setCompanyName", async () => {
|
|
@@ -703,17 +739,19 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
703
739
|
...customer,
|
|
704
740
|
companyName: "Acme",
|
|
705
741
|
};
|
|
706
|
-
ctMock.project("dummy").
|
|
742
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
707
743
|
|
|
708
|
-
const response = await
|
|
709
|
-
|
|
710
|
-
.
|
|
744
|
+
const response = await ctMock.app.inject({
|
|
745
|
+
method: "POST",
|
|
746
|
+
url: `/dummy/customers/${customer.id}`,
|
|
747
|
+
payload: {
|
|
711
748
|
version: 1,
|
|
712
749
|
actions: [{ action: "setCompanyName", companyName: "Acme Inc." }],
|
|
713
|
-
}
|
|
714
|
-
|
|
715
|
-
expect(response.
|
|
716
|
-
expect(response.
|
|
750
|
+
},
|
|
751
|
+
});
|
|
752
|
+
expect(response.statusCode).toBe(200);
|
|
753
|
+
expect(response.json().version).toBe(2);
|
|
754
|
+
expect(response.json().companyName).toBe("Acme Inc.");
|
|
717
755
|
});
|
|
718
756
|
|
|
719
757
|
test("setVatId", async () => {
|
|
@@ -723,17 +761,19 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
723
761
|
...customer,
|
|
724
762
|
vatId: "123456789",
|
|
725
763
|
};
|
|
726
|
-
ctMock.project("dummy").
|
|
764
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
727
765
|
|
|
728
|
-
const response = await
|
|
729
|
-
|
|
730
|
-
.
|
|
766
|
+
const response = await ctMock.app.inject({
|
|
767
|
+
method: "POST",
|
|
768
|
+
url: `/dummy/customers/${customer.id}`,
|
|
769
|
+
payload: {
|
|
731
770
|
version: 1,
|
|
732
771
|
actions: [{ action: "setVatId", vatId: "ABCD" }],
|
|
733
|
-
}
|
|
734
|
-
|
|
735
|
-
expect(response.
|
|
736
|
-
expect(response.
|
|
772
|
+
},
|
|
773
|
+
});
|
|
774
|
+
expect(response.statusCode).toBe(200);
|
|
775
|
+
expect(response.json().version).toBe(2);
|
|
776
|
+
expect(response.json().vatId).toBe("ABCD");
|
|
737
777
|
});
|
|
738
778
|
|
|
739
779
|
test("changeAddress", async () => {
|
|
@@ -765,11 +805,12 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
765
805
|
],
|
|
766
806
|
defaultBillingAddressId: "address-uuid",
|
|
767
807
|
};
|
|
768
|
-
ctMock.project("dummy").
|
|
808
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
769
809
|
|
|
770
|
-
const response = await
|
|
771
|
-
|
|
772
|
-
.
|
|
810
|
+
const response = await ctMock.app.inject({
|
|
811
|
+
method: "POST",
|
|
812
|
+
url: `/dummy/customers/${customer.id}`,
|
|
813
|
+
payload: {
|
|
773
814
|
version: 1,
|
|
774
815
|
actions: [
|
|
775
816
|
{
|
|
@@ -785,10 +826,11 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
785
826
|
},
|
|
786
827
|
},
|
|
787
828
|
],
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
expect(response.
|
|
791
|
-
expect(response.
|
|
829
|
+
},
|
|
830
|
+
});
|
|
831
|
+
expect(response.statusCode).toBe(200);
|
|
832
|
+
expect(response.json().version).toBe(2);
|
|
833
|
+
expect(response.json().addresses).toMatchObject([
|
|
792
834
|
{
|
|
793
835
|
id: "other-address-uid",
|
|
794
836
|
firstName: "Foo",
|
|
@@ -813,39 +855,43 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
813
855
|
test("setCustomerNumber", async () => {
|
|
814
856
|
assert(customer, "customer not created");
|
|
815
857
|
|
|
816
|
-
ctMock.project("dummy").
|
|
858
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
817
859
|
|
|
818
|
-
const response = await
|
|
819
|
-
|
|
820
|
-
.
|
|
860
|
+
const response = await ctMock.app.inject({
|
|
861
|
+
method: "POST",
|
|
862
|
+
url: `/dummy/customers/${customer.id}`,
|
|
863
|
+
payload: {
|
|
821
864
|
version: 1,
|
|
822
865
|
actions: [
|
|
823
866
|
{ action: "setCustomerNumber", customerNumber: "CUSTOMER-001" },
|
|
824
867
|
],
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
expect(response.
|
|
828
|
-
expect(response.
|
|
868
|
+
},
|
|
869
|
+
});
|
|
870
|
+
expect(response.statusCode).toBe(200);
|
|
871
|
+
expect(response.json().version).toBe(2);
|
|
872
|
+
expect(response.json().customerNumber).toBe("CUSTOMER-001");
|
|
829
873
|
});
|
|
830
874
|
|
|
831
875
|
test("setCustomerNumber error when already have a customer number", async () => {
|
|
832
876
|
assert(customer, "customer not created");
|
|
833
877
|
|
|
834
|
-
ctMock.project("dummy").
|
|
878
|
+
await ctMock.project("dummy").unsafeAdd("customer", {
|
|
835
879
|
...customer,
|
|
836
880
|
customerNumber: "CUSTOMER-002",
|
|
837
881
|
});
|
|
838
882
|
|
|
839
|
-
const response = await
|
|
840
|
-
|
|
841
|
-
.
|
|
883
|
+
const response = await ctMock.app.inject({
|
|
884
|
+
method: "POST",
|
|
885
|
+
url: `/dummy/customers/${customer.id}`,
|
|
886
|
+
payload: {
|
|
842
887
|
version: 1,
|
|
843
888
|
actions: [
|
|
844
889
|
{ action: "setCustomerNumber", customerNumber: "CUSTOMER-001" },
|
|
845
890
|
],
|
|
846
|
-
}
|
|
847
|
-
|
|
848
|
-
expect(response.
|
|
891
|
+
},
|
|
892
|
+
});
|
|
893
|
+
expect(response.statusCode).toBe(400);
|
|
894
|
+
expect(response.json().message).toBe(
|
|
849
895
|
"A Customer number already exists and cannot be set again.",
|
|
850
896
|
);
|
|
851
897
|
});
|
|
@@ -853,27 +899,29 @@ describe("Customer Update Actions (old-style)", () => {
|
|
|
853
899
|
test("setKey", async () => {
|
|
854
900
|
assert(customer, "customer not created");
|
|
855
901
|
|
|
856
|
-
ctMock.project("dummy").
|
|
902
|
+
await ctMock.project("dummy").unsafeAdd("customer", customer);
|
|
857
903
|
|
|
858
|
-
const response = await
|
|
859
|
-
|
|
860
|
-
.
|
|
904
|
+
const response = await ctMock.app.inject({
|
|
905
|
+
method: "POST",
|
|
906
|
+
url: `/dummy/customers/${customer.id}`,
|
|
907
|
+
payload: {
|
|
861
908
|
version: 1,
|
|
862
909
|
actions: [{ action: "setKey", key: "C001" }],
|
|
863
|
-
}
|
|
864
|
-
|
|
865
|
-
expect(response.
|
|
866
|
-
expect(response.
|
|
910
|
+
},
|
|
911
|
+
});
|
|
912
|
+
expect(response.statusCode).toBe(200);
|
|
913
|
+
expect(response.json().version).toBe(2);
|
|
914
|
+
expect(response.json().key).toBe("C001");
|
|
867
915
|
});
|
|
868
916
|
});
|
|
869
917
|
|
|
870
918
|
describe("Customer Password Reset", () => {
|
|
871
|
-
afterEach(() => {
|
|
872
|
-
ctMock.clear();
|
|
919
|
+
afterEach(async () => {
|
|
920
|
+
await ctMock.clear();
|
|
873
921
|
});
|
|
874
922
|
|
|
875
|
-
beforeEach(() => {
|
|
876
|
-
ctMock.project("dummy").
|
|
923
|
+
beforeEach(async () => {
|
|
924
|
+
await ctMock.project("dummy").unsafeAdd("customer", {
|
|
877
925
|
id: "123",
|
|
878
926
|
createdAt: "2021-03-18T14:00:00.000Z",
|
|
879
927
|
version: 2,
|
|
@@ -885,35 +933,44 @@ describe("Customer Password Reset", () => {
|
|
|
885
933
|
authenticationMode: "password",
|
|
886
934
|
custom: { type: { typeId: "type", id: "" }, fields: {} },
|
|
887
935
|
stores: [],
|
|
936
|
+
shippingAddressIds: [],
|
|
937
|
+
billingAddressIds: [],
|
|
938
|
+
customerGroupAssignments: [],
|
|
888
939
|
});
|
|
889
940
|
});
|
|
890
941
|
|
|
891
942
|
test("reset password flow", async () => {
|
|
892
|
-
const
|
|
893
|
-
|
|
894
|
-
|
|
943
|
+
const tokenResponse = await ctMock.app.inject({
|
|
944
|
+
method: "POST",
|
|
945
|
+
url: "/dummy/customers/password-token",
|
|
946
|
+
payload: {
|
|
895
947
|
email: "foo@example.org",
|
|
896
|
-
}
|
|
897
|
-
|
|
948
|
+
},
|
|
949
|
+
});
|
|
950
|
+
const token = tokenResponse.json() as CustomerToken;
|
|
898
951
|
|
|
899
|
-
const response = await
|
|
900
|
-
|
|
901
|
-
|
|
952
|
+
const response = await ctMock.app.inject({
|
|
953
|
+
method: "POST",
|
|
954
|
+
url: "/dummy/customers/password/reset",
|
|
955
|
+
payload: {
|
|
902
956
|
tokenValue: token.value,
|
|
903
957
|
newPassword: "somethingNew",
|
|
904
|
-
}
|
|
905
|
-
|
|
958
|
+
},
|
|
959
|
+
});
|
|
960
|
+
expect(response.statusCode).toBe(200);
|
|
906
961
|
});
|
|
907
962
|
|
|
908
963
|
test("fail reset password flow", async () => {
|
|
909
|
-
const response = await
|
|
910
|
-
|
|
911
|
-
|
|
964
|
+
const response = await ctMock.app.inject({
|
|
965
|
+
method: "POST",
|
|
966
|
+
url: "/dummy/customers/password/reset",
|
|
967
|
+
payload: {
|
|
912
968
|
tokenValue: "invalid-token",
|
|
913
969
|
newPassword: "somethingNew",
|
|
914
|
-
}
|
|
915
|
-
|
|
916
|
-
expect(response.
|
|
970
|
+
},
|
|
971
|
+
});
|
|
972
|
+
expect(response.statusCode).toBe(400);
|
|
973
|
+
expect(response.json()).toEqual({
|
|
917
974
|
message: `The Customer with ID 'Token(invalid-token)' was not found.`,
|
|
918
975
|
statusCode: 400,
|
|
919
976
|
errors: [
|
|
@@ -927,18 +984,22 @@ describe("Customer Password Reset", () => {
|
|
|
927
984
|
});
|
|
928
985
|
|
|
929
986
|
describe("Customer email verification", () => {
|
|
987
|
+
const factory = customerDraftFactory(ctMock);
|
|
988
|
+
|
|
930
989
|
test("creates an email token", async () => {
|
|
931
|
-
const customer = await
|
|
990
|
+
const customer = await factory.create();
|
|
932
991
|
|
|
933
|
-
const response = await
|
|
934
|
-
|
|
935
|
-
|
|
992
|
+
const response = await ctMock.app.inject({
|
|
993
|
+
method: "POST",
|
|
994
|
+
url: `/dummy/customers/email-token`,
|
|
995
|
+
payload: {
|
|
936
996
|
id: customer.id,
|
|
937
997
|
ttlMinutes: 60,
|
|
938
|
-
}
|
|
998
|
+
},
|
|
999
|
+
});
|
|
939
1000
|
|
|
940
|
-
expect(response.
|
|
941
|
-
expect(response.
|
|
1001
|
+
expect(response.statusCode, JSON.stringify(response.json())).toBe(200);
|
|
1002
|
+
expect(response.json()).toMatchObject({
|
|
942
1003
|
customerId: customer.id,
|
|
943
1004
|
invalidateOlderTokens: false,
|
|
944
1005
|
id: expect.any(String),
|
|
@@ -946,32 +1007,36 @@ describe("Customer email verification", () => {
|
|
|
946
1007
|
});
|
|
947
1008
|
|
|
948
1009
|
const dateTime = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
|
|
949
|
-
expect(response.
|
|
950
|
-
expect(response.
|
|
951
|
-
expect(response.
|
|
1010
|
+
expect(response.json().createdAt).toMatch(dateTime);
|
|
1011
|
+
expect(response.json().lastModifiedAt).toMatch(dateTime);
|
|
1012
|
+
expect(response.json().expiresAt).toMatch(dateTime);
|
|
952
1013
|
});
|
|
953
1014
|
|
|
954
1015
|
test("validates an email token", async () => {
|
|
955
|
-
const customer = await
|
|
1016
|
+
const customer = await factory.create({
|
|
956
1017
|
isEmailVerified: false,
|
|
957
1018
|
});
|
|
958
1019
|
|
|
959
|
-
const tokenResponse = await
|
|
960
|
-
|
|
961
|
-
|
|
1020
|
+
const tokenResponse = await ctMock.app.inject({
|
|
1021
|
+
method: "POST",
|
|
1022
|
+
url: `/dummy/customers/email-token`,
|
|
1023
|
+
payload: {
|
|
962
1024
|
id: customer.id,
|
|
963
1025
|
ttlMinutes: 60,
|
|
964
|
-
}
|
|
1026
|
+
},
|
|
1027
|
+
});
|
|
965
1028
|
|
|
966
|
-
const response = await
|
|
967
|
-
|
|
968
|
-
|
|
1029
|
+
const response = await ctMock.app.inject({
|
|
1030
|
+
method: "POST",
|
|
1031
|
+
url: `/dummy/customers/email/confirm`,
|
|
1032
|
+
payload: {
|
|
969
1033
|
id: customer.id,
|
|
970
|
-
tokenValue: tokenResponse.
|
|
971
|
-
}
|
|
1034
|
+
tokenValue: tokenResponse.json().value,
|
|
1035
|
+
},
|
|
1036
|
+
});
|
|
972
1037
|
|
|
973
|
-
expect(response.
|
|
974
|
-
expect(response.
|
|
975
|
-
expect(response.
|
|
1038
|
+
expect(response.statusCode, JSON.stringify(response.json())).toBe(200);
|
|
1039
|
+
expect(response.json().id).toEqual(customer.id);
|
|
1040
|
+
expect(response.json().isEmailVerified).toEqual(true);
|
|
976
1041
|
});
|
|
977
1042
|
});
|