@labdigital/commercetools-mock 2.17.1 → 2.18.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +4186 -3974
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +266 -413
- package/dist/index.d.ts +266 -413
- package/dist/index.js +4186 -3974
- package/dist/index.js.map +1 -1
- package/package.json +44 -46
- package/src/constants.ts +2 -2
- package/src/ctMock.test.ts +11 -11
- package/src/ctMock.ts +141 -127
- package/src/deprecation.ts +8 -0
- package/src/exceptions.ts +17 -15
- package/src/helpers.ts +32 -32
- package/src/index.test.ts +128 -128
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +13 -13
- package/src/lib/haversine.test.ts +9 -9
- package/src/lib/haversine.ts +11 -11
- package/src/lib/masking.ts +11 -11
- package/src/lib/parser.ts +2 -2
- package/src/lib/password.ts +23 -3
- package/src/lib/predicateParser.test.ts +185 -183
- package/src/lib/predicateParser.ts +234 -234
- package/src/lib/projectionSearchFilter.test.ts +103 -101
- package/src/lib/projectionSearchFilter.ts +152 -150
- package/src/lib/proxy.ts +5 -5
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.test.ts +86 -86
- package/src/oauth/server.ts +158 -144
- package/src/oauth/store.ts +44 -43
- package/src/priceSelector.test.ts +35 -35
- package/src/priceSelector.ts +30 -30
- package/src/product-projection-search.ts +136 -134
- package/src/projectAPI.test.ts +7 -7
- package/src/projectAPI.ts +24 -22
- package/src/repositories/abstract.ts +168 -116
- package/src/repositories/associate-role.ts +90 -77
- package/src/repositories/attribute-group.ts +51 -40
- package/src/repositories/business-unit.ts +168 -148
- package/src/repositories/cart/actions.ts +489 -0
- package/src/repositories/cart/helpers.ts +30 -0
- package/src/repositories/cart/index.ts +180 -0
- package/src/repositories/cart-discount/actions.ts +148 -0
- package/src/repositories/cart-discount/index.ts +86 -0
- package/src/repositories/category/actions.ts +231 -0
- package/src/repositories/category/index.ts +52 -0
- package/src/repositories/channel.ts +88 -90
- package/src/repositories/custom-object.ts +46 -45
- package/src/repositories/customer/actions.ts +165 -0
- package/src/repositories/customer/index.ts +79 -0
- package/src/repositories/customer-group.ts +66 -55
- package/src/repositories/discount-code/actions.ts +149 -0
- package/src/repositories/discount-code/index.ts +50 -0
- package/src/repositories/errors.ts +10 -10
- package/src/repositories/extension.ts +64 -62
- package/src/repositories/helpers.ts +117 -118
- package/src/repositories/index.ts +80 -79
- package/src/repositories/inventory-entry/actions.ts +84 -0
- package/src/repositories/inventory-entry/index.ts +44 -0
- package/src/repositories/my-customer.ts +114 -0
- package/src/repositories/my-order.ts +8 -8
- package/src/repositories/order/actions.ts +281 -0
- package/src/repositories/{order.test.ts → order/index.test.ts} +77 -77
- package/src/repositories/order/index.ts +260 -0
- package/src/repositories/order-edit.ts +10 -23
- package/src/repositories/payment/actions.ts +305 -0
- package/src/repositories/payment/helpers.ts +17 -0
- package/src/repositories/payment/index.ts +56 -0
- package/src/repositories/product/actions.ts +943 -0
- package/src/repositories/product/helpers.ts +98 -0
- package/src/repositories/product/index.ts +130 -0
- package/src/repositories/product-discount.ts +127 -117
- package/src/repositories/product-projection.ts +56 -62
- package/src/repositories/product-selection.ts +31 -28
- package/src/repositories/product-type.ts +136 -134
- package/src/repositories/project.ts +133 -118
- package/src/repositories/quote-request.ts +7 -19
- package/src/repositories/quote.ts +7 -22
- package/src/repositories/review.ts +13 -26
- package/src/repositories/shipping-method/actions.ts +198 -0
- package/src/repositories/shipping-method/helpers.ts +10 -0
- package/src/repositories/shipping-method/index.ts +138 -0
- package/src/repositories/shopping-list/actions.ts +295 -0
- package/src/repositories/shopping-list/index.ts +122 -0
- package/src/repositories/staged-quote.ts +7 -20
- package/src/repositories/standalone-price.ts +57 -44
- package/src/repositories/state.ts +113 -68
- package/src/repositories/store.ts +106 -94
- package/src/repositories/subscription.ts +46 -22
- package/src/repositories/tax-category/actions.ts +94 -0
- package/src/repositories/tax-category/helpers.ts +8 -0
- package/src/repositories/tax-category/index.ts +25 -0
- package/src/repositories/type/actions.ts +162 -0
- package/src/repositories/type/index.ts +24 -0
- package/src/repositories/zone.ts +62 -58
- package/src/server.ts +9 -9
- package/src/services/abstract.ts +75 -72
- package/src/services/associate-roles.test.ts +27 -27
- package/src/services/associate-roles.ts +7 -7
- package/src/services/attribute-group.ts +7 -7
- package/src/services/business-units.test.ts +28 -28
- package/src/services/business-units.ts +7 -7
- package/src/services/cart-discount.test.ts +199 -199
- package/src/services/cart-discount.ts +7 -7
- package/src/services/cart.test.ts +261 -261
- package/src/services/cart.ts +22 -21
- package/src/services/category.test.ts +121 -121
- package/src/services/category.ts +7 -7
- package/src/services/channel.ts +7 -7
- package/src/services/custom-object.test.ts +130 -130
- package/src/services/custom-object.ts +34 -31
- package/src/services/customer-group.ts +7 -7
- package/src/services/customer.test.ts +205 -205
- package/src/services/customer.ts +23 -36
- package/src/services/discount-code.ts +7 -7
- package/src/services/extension.ts +7 -7
- package/src/services/index.ts +85 -81
- package/src/services/inventory-entry.test.ts +106 -106
- package/src/services/inventory-entry.ts +7 -7
- package/src/services/my-cart.test.ts +56 -56
- package/src/services/my-cart.ts +20 -20
- package/src/services/my-customer.test.ts +155 -104
- package/src/services/my-customer.ts +61 -75
- package/src/services/my-order.ts +16 -16
- package/src/services/my-payment.test.ts +40 -40
- package/src/services/my-payment.ts +7 -7
- package/src/services/my-shopping-list.ts +7 -7
- package/src/services/order.test.ts +243 -243
- package/src/services/order.ts +23 -18
- package/src/services/payment.test.ts +40 -40
- package/src/services/payment.ts +7 -7
- package/src/services/product-discount.ts +7 -7
- package/src/services/product-projection.test.ts +190 -190
- package/src/services/product-projection.ts +34 -32
- package/src/services/product-selection.test.ts +19 -19
- package/src/services/product-selection.ts +7 -7
- package/src/services/product-type.test.ts +38 -38
- package/src/services/product-type.ts +7 -7
- package/src/services/product.test.ts +658 -656
- package/src/services/product.ts +7 -7
- package/src/services/project.test.ts +24 -24
- package/src/services/project.ts +17 -17
- package/src/services/reviews.ts +7 -7
- package/src/services/shipping-method.test.ts +78 -78
- package/src/services/shipping-method.ts +16 -16
- package/src/services/shopping-list.test.ts +170 -170
- package/src/services/shopping-list.ts +7 -7
- package/src/services/standalone-price.test.ts +112 -112
- package/src/services/standalone-price.ts +7 -7
- package/src/services/state.test.ts +30 -30
- package/src/services/state.ts +7 -7
- package/src/services/store.test.ts +40 -40
- package/src/services/store.ts +7 -7
- package/src/services/subscription.ts +7 -7
- package/src/services/tax-category.test.ts +43 -43
- package/src/services/tax-category.ts +7 -7
- package/src/services/type.ts +7 -7
- package/src/services/zone.ts +7 -7
- package/src/shippingCalculator.test.ts +43 -43
- package/src/shippingCalculator.ts +23 -23
- package/src/storage/abstract.ts +36 -34
- package/src/storage/in-memory.ts +237 -233
- package/src/storage/index.ts +2 -2
- package/src/types.ts +91 -91
- package/src/repositories/cart-discount.ts +0 -219
- package/src/repositories/cart.ts +0 -659
- package/src/repositories/category.ts +0 -256
- package/src/repositories/customer.ts +0 -228
- package/src/repositories/discount-code.ts +0 -181
- package/src/repositories/inventory-entry.ts +0 -109
- package/src/repositories/order.ts +0 -514
- package/src/repositories/payment.ts +0 -342
- package/src/repositories/product.ts +0 -1106
- package/src/repositories/shipping-method.ts +0 -312
- package/src/repositories/shopping-list.ts +0 -392
- package/src/repositories/tax-category.ts +0 -111
- package/src/repositories/type.ts +0 -172
|
@@ -1,107 +1,107 @@
|
|
|
1
|
-
import { Customer } from
|
|
2
|
-
import assert from
|
|
3
|
-
import supertest from
|
|
4
|
-
import { afterEach, beforeEach, describe, expect, test } from
|
|
5
|
-
import { CommercetoolsMock, getBaseResourceProperties } from
|
|
1
|
+
import { Customer } from "@commercetools/platform-sdk";
|
|
2
|
+
import assert from "assert";
|
|
3
|
+
import supertest from "supertest";
|
|
4
|
+
import { afterEach, beforeEach, describe, expect, test } from "vitest";
|
|
5
|
+
import { CommercetoolsMock, getBaseResourceProperties } from "../index";
|
|
6
6
|
|
|
7
|
-
describe(
|
|
8
|
-
const ctMock = new CommercetoolsMock()
|
|
9
|
-
let customer: Customer | undefined
|
|
7
|
+
describe("Customer Update Actions", () => {
|
|
8
|
+
const ctMock = new CommercetoolsMock();
|
|
9
|
+
let customer: Customer | undefined;
|
|
10
10
|
|
|
11
11
|
beforeEach(async () => {
|
|
12
12
|
customer = {
|
|
13
13
|
...getBaseResourceProperties(),
|
|
14
|
-
id:
|
|
15
|
-
email:
|
|
16
|
-
password:
|
|
14
|
+
id: "customer-uuid",
|
|
15
|
+
email: "user@example.com",
|
|
16
|
+
password: "supersecret",
|
|
17
17
|
addresses: [],
|
|
18
18
|
isEmailVerified: true,
|
|
19
|
-
authenticationMode:
|
|
19
|
+
authenticationMode: "Password", //default in Commercetools
|
|
20
20
|
version: 1,
|
|
21
|
-
}
|
|
22
|
-
ctMock.project(
|
|
23
|
-
})
|
|
21
|
+
};
|
|
22
|
+
ctMock.project("dummy").add("customer", customer);
|
|
23
|
+
});
|
|
24
24
|
|
|
25
25
|
afterEach(() => {
|
|
26
|
-
ctMock.clear()
|
|
27
|
-
})
|
|
26
|
+
ctMock.clear();
|
|
27
|
+
});
|
|
28
28
|
|
|
29
|
-
test(
|
|
30
|
-
assert(customer,
|
|
29
|
+
test("exists", async () => {
|
|
30
|
+
assert(customer, "customer not created");
|
|
31
31
|
|
|
32
32
|
const response = await supertest(ctMock.app)
|
|
33
33
|
.head(`/dummy/customers/${customer.id}`)
|
|
34
|
-
.send()
|
|
34
|
+
.send();
|
|
35
35
|
|
|
36
|
-
expect(response.status).toBe(200)
|
|
37
|
-
})
|
|
36
|
+
expect(response.status).toBe(200);
|
|
37
|
+
});
|
|
38
38
|
|
|
39
|
-
test(
|
|
40
|
-
assert(customer,
|
|
39
|
+
test("non-existent", async () => {
|
|
40
|
+
assert(customer, "customer not created");
|
|
41
41
|
|
|
42
42
|
const response = await supertest(ctMock.app)
|
|
43
43
|
.head(`/dummy/customers/invalid-id`)
|
|
44
|
-
.send()
|
|
44
|
+
.send();
|
|
45
45
|
|
|
46
|
-
expect(response.status).toBe(404)
|
|
47
|
-
})
|
|
46
|
+
expect(response.status).toBe(404);
|
|
47
|
+
});
|
|
48
48
|
|
|
49
|
-
test(
|
|
50
|
-
assert(customer,
|
|
49
|
+
test("changeEmail", async () => {
|
|
50
|
+
assert(customer, "customer not created");
|
|
51
51
|
|
|
52
52
|
const response = await supertest(ctMock.app)
|
|
53
53
|
.post(`/dummy/customers/${customer.id}`)
|
|
54
54
|
.send({
|
|
55
55
|
version: 1,
|
|
56
|
-
actions: [{ action:
|
|
57
|
-
})
|
|
58
|
-
expect(response.status).toBe(200)
|
|
59
|
-
expect(response.body.version).toBe(2)
|
|
60
|
-
expect(response.body.email).toBe(
|
|
61
|
-
})
|
|
56
|
+
actions: [{ action: "changeEmail", email: "new@example.com" }],
|
|
57
|
+
});
|
|
58
|
+
expect(response.status).toBe(200);
|
|
59
|
+
expect(response.body.version).toBe(2);
|
|
60
|
+
expect(response.body.email).toBe("new@example.com");
|
|
61
|
+
});
|
|
62
62
|
|
|
63
|
-
test(
|
|
64
|
-
assert(customer,
|
|
63
|
+
test("setAuthenticationMode to an invalid mode", async () => {
|
|
64
|
+
assert(customer, "customer not created");
|
|
65
65
|
|
|
66
66
|
const response = await supertest(ctMock.app)
|
|
67
67
|
.post(`/dummy/customers/${customer.id}`)
|
|
68
68
|
.send({
|
|
69
69
|
version: 1,
|
|
70
|
-
actions: [{ action:
|
|
71
|
-
})
|
|
72
|
-
expect(response.status).toBe(400)
|
|
70
|
+
actions: [{ action: "setAuthenticationMode", authMode: "invalid" }],
|
|
71
|
+
});
|
|
72
|
+
expect(response.status).toBe(400);
|
|
73
73
|
expect(response.body.message).toBe(
|
|
74
|
-
|
|
75
|
-
)
|
|
76
|
-
expect(response.body.errors[0].code).toBe(
|
|
74
|
+
"Request body does not contain valid JSON.",
|
|
75
|
+
);
|
|
76
|
+
expect(response.body.errors[0].code).toBe("InvalidJsonInput");
|
|
77
77
|
expect(response.body.errors[0].detailedErrorMessage).toBe(
|
|
78
|
-
"actions -> authMode: Invalid enum value: 'invalid'. Expected one of: 'Password','ExternalAuth'"
|
|
79
|
-
)
|
|
80
|
-
})
|
|
78
|
+
"actions -> authMode: Invalid enum value: 'invalid'. Expected one of: 'Password','ExternalAuth'",
|
|
79
|
+
);
|
|
80
|
+
});
|
|
81
81
|
|
|
82
|
-
test(
|
|
83
|
-
assert(customer,
|
|
82
|
+
test("setAuthenticationMode to ExternalAuth", async () => {
|
|
83
|
+
assert(customer, "customer not created");
|
|
84
84
|
|
|
85
85
|
const response = await supertest(ctMock.app)
|
|
86
86
|
.post(`/dummy/customers/${customer.id}`)
|
|
87
87
|
.send({
|
|
88
88
|
version: 1,
|
|
89
89
|
actions: [
|
|
90
|
-
{ action:
|
|
90
|
+
{ action: "setAuthenticationMode", authMode: "ExternalAuth" },
|
|
91
91
|
],
|
|
92
|
-
})
|
|
93
|
-
expect(response.status).toBe(200)
|
|
94
|
-
expect(response.body.version).toBe(2)
|
|
95
|
-
expect(response.body.authenticationMode).toBe(
|
|
96
|
-
expect(response.body.password).toBe(undefined)
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
test(
|
|
100
|
-
assert(customer,
|
|
92
|
+
});
|
|
93
|
+
expect(response.status).toBe(200);
|
|
94
|
+
expect(response.body.version).toBe(2);
|
|
95
|
+
expect(response.body.authenticationMode).toBe("ExternalAuth");
|
|
96
|
+
expect(response.body.password).toBe(undefined);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test("setAuthenticationMode error when setting current authMode", async () => {
|
|
100
|
+
assert(customer, "customer not created");
|
|
101
101
|
assert(
|
|
102
|
-
customer.authenticationMode ==
|
|
103
|
-
|
|
104
|
-
)
|
|
102
|
+
customer.authenticationMode == "Password",
|
|
103
|
+
"customer not in default state",
|
|
104
|
+
);
|
|
105
105
|
|
|
106
106
|
const response = await supertest(ctMock.app)
|
|
107
107
|
.post(`/dummy/customers/${customer.id}`)
|
|
@@ -109,20 +109,20 @@ describe('Customer Update Actions', () => {
|
|
|
109
109
|
version: 1,
|
|
110
110
|
actions: [
|
|
111
111
|
{
|
|
112
|
-
action:
|
|
113
|
-
authMode:
|
|
114
|
-
password:
|
|
112
|
+
action: "setAuthenticationMode",
|
|
113
|
+
authMode: "Password",
|
|
114
|
+
password: "newpass",
|
|
115
115
|
},
|
|
116
116
|
],
|
|
117
|
-
})
|
|
118
|
-
expect(response.status).toBe(400)
|
|
117
|
+
});
|
|
118
|
+
expect(response.status).toBe(400);
|
|
119
119
|
expect(response.body.message).toBe(
|
|
120
|
-
"The customer is already using the 'Password' authentication mode."
|
|
121
|
-
)
|
|
122
|
-
})
|
|
120
|
+
"The customer is already using the 'Password' authentication mode.",
|
|
121
|
+
);
|
|
122
|
+
});
|
|
123
123
|
|
|
124
|
-
test(
|
|
125
|
-
assert(customer,
|
|
124
|
+
test("setAuthenticationMode to Password", async () => {
|
|
125
|
+
assert(customer, "customer not created");
|
|
126
126
|
|
|
127
127
|
//change *away from* Password authMode (to be able to test changing *to* Password authMode)
|
|
128
128
|
await supertest(ctMock.app)
|
|
@@ -130,9 +130,9 @@ describe('Customer Update Actions', () => {
|
|
|
130
130
|
.send({
|
|
131
131
|
version: 1,
|
|
132
132
|
actions: [
|
|
133
|
-
{ action:
|
|
133
|
+
{ action: "setAuthenticationMode", authMode: "ExternalAuth" },
|
|
134
134
|
],
|
|
135
|
-
})
|
|
135
|
+
});
|
|
136
136
|
|
|
137
137
|
//change to Password authMode
|
|
138
138
|
const response = await supertest(ctMock.app)
|
|
@@ -141,152 +141,152 @@ describe('Customer Update Actions', () => {
|
|
|
141
141
|
version: 2,
|
|
142
142
|
actions: [
|
|
143
143
|
{
|
|
144
|
-
action:
|
|
145
|
-
authMode:
|
|
146
|
-
password:
|
|
144
|
+
action: "setAuthenticationMode",
|
|
145
|
+
authMode: "Password",
|
|
146
|
+
password: "newpass",
|
|
147
147
|
},
|
|
148
148
|
],
|
|
149
|
-
})
|
|
150
|
-
expect(response.status).toBe(200)
|
|
151
|
-
expect(response.body.version).toBe(3)
|
|
152
|
-
expect(response.body.authenticationMode).toBe(
|
|
149
|
+
});
|
|
150
|
+
expect(response.status).toBe(200);
|
|
151
|
+
expect(response.body.version).toBe(3);
|
|
152
|
+
expect(response.body.authenticationMode).toBe("Password");
|
|
153
153
|
expect(response.body.password).toBe(
|
|
154
|
-
Buffer.from(
|
|
155
|
-
)
|
|
156
|
-
})
|
|
154
|
+
Buffer.from("newpass").toString("base64"),
|
|
155
|
+
);
|
|
156
|
+
});
|
|
157
157
|
|
|
158
|
-
test(
|
|
159
|
-
assert(customer,
|
|
158
|
+
test("setCustomField", async () => {
|
|
159
|
+
assert(customer, "customer not created");
|
|
160
160
|
|
|
161
161
|
customer = {
|
|
162
162
|
...customer,
|
|
163
|
-
custom: { type: { typeId:
|
|
164
|
-
}
|
|
165
|
-
ctMock.project(
|
|
163
|
+
custom: { type: { typeId: "type", id: "" }, fields: {} },
|
|
164
|
+
};
|
|
165
|
+
ctMock.project("dummy").add("customer", customer);
|
|
166
166
|
|
|
167
167
|
const response = await supertest(ctMock.app)
|
|
168
168
|
.post(`/dummy/customers/${customer.id}`)
|
|
169
169
|
.send({
|
|
170
170
|
version: 1,
|
|
171
171
|
actions: [
|
|
172
|
-
{ action:
|
|
172
|
+
{ action: "setCustomField", name: "isValidCouponCode", value: false },
|
|
173
173
|
],
|
|
174
|
-
})
|
|
175
|
-
expect(response.status).toBe(200)
|
|
176
|
-
expect(response.body.version).toBe(2)
|
|
177
|
-
expect(response.body.custom.fields.isValidCouponCode).toBe(false)
|
|
178
|
-
})
|
|
174
|
+
});
|
|
175
|
+
expect(response.status).toBe(200);
|
|
176
|
+
expect(response.body.version).toBe(2);
|
|
177
|
+
expect(response.body.custom.fields.isValidCouponCode).toBe(false);
|
|
178
|
+
});
|
|
179
179
|
|
|
180
|
-
test(
|
|
181
|
-
assert(customer,
|
|
180
|
+
test("setFirstName", async () => {
|
|
181
|
+
assert(customer, "customer not created");
|
|
182
182
|
|
|
183
183
|
customer = {
|
|
184
184
|
...customer,
|
|
185
|
-
firstName:
|
|
186
|
-
}
|
|
187
|
-
ctMock.project(
|
|
185
|
+
firstName: "John",
|
|
186
|
+
};
|
|
187
|
+
ctMock.project("dummy").add("customer", customer);
|
|
188
188
|
|
|
189
189
|
const response = await supertest(ctMock.app)
|
|
190
190
|
.post(`/dummy/customers/${customer.id}`)
|
|
191
191
|
.send({
|
|
192
192
|
version: 1,
|
|
193
|
-
actions: [{ action:
|
|
194
|
-
})
|
|
195
|
-
expect(response.status).toBe(200)
|
|
196
|
-
expect(response.body.version).toBe(2)
|
|
197
|
-
expect(response.body.firstName).toBe(
|
|
198
|
-
})
|
|
193
|
+
actions: [{ action: "setFirstName", firstName: "Mary" }],
|
|
194
|
+
});
|
|
195
|
+
expect(response.status).toBe(200);
|
|
196
|
+
expect(response.body.version).toBe(2);
|
|
197
|
+
expect(response.body.firstName).toBe("Mary");
|
|
198
|
+
});
|
|
199
199
|
|
|
200
|
-
test(
|
|
201
|
-
assert(customer,
|
|
200
|
+
test("setLastName", async () => {
|
|
201
|
+
assert(customer, "customer not created");
|
|
202
202
|
|
|
203
203
|
customer = {
|
|
204
204
|
...customer,
|
|
205
|
-
lastName:
|
|
206
|
-
}
|
|
207
|
-
ctMock.project(
|
|
205
|
+
lastName: "Doe",
|
|
206
|
+
};
|
|
207
|
+
ctMock.project("dummy").add("customer", customer);
|
|
208
208
|
|
|
209
209
|
const response = await supertest(ctMock.app)
|
|
210
210
|
.post(`/dummy/customers/${customer.id}`)
|
|
211
211
|
.send({
|
|
212
212
|
version: 1,
|
|
213
|
-
actions: [{ action:
|
|
214
|
-
})
|
|
215
|
-
expect(response.status).toBe(200)
|
|
216
|
-
expect(response.body.version).toBe(2)
|
|
217
|
-
expect(response.body.lastName).toBe(
|
|
218
|
-
})
|
|
213
|
+
actions: [{ action: "setLastName", lastName: "Smith" }],
|
|
214
|
+
});
|
|
215
|
+
expect(response.status).toBe(200);
|
|
216
|
+
expect(response.body.version).toBe(2);
|
|
217
|
+
expect(response.body.lastName).toBe("Smith");
|
|
218
|
+
});
|
|
219
219
|
|
|
220
|
-
test(
|
|
221
|
-
assert(customer,
|
|
220
|
+
test("setCompanyName", async () => {
|
|
221
|
+
assert(customer, "customer not created");
|
|
222
222
|
|
|
223
223
|
customer = {
|
|
224
224
|
...customer,
|
|
225
|
-
companyName:
|
|
226
|
-
}
|
|
227
|
-
ctMock.project(
|
|
225
|
+
companyName: "Acme",
|
|
226
|
+
};
|
|
227
|
+
ctMock.project("dummy").add("customer", customer);
|
|
228
228
|
|
|
229
229
|
const response = await supertest(ctMock.app)
|
|
230
230
|
.post(`/dummy/customers/${customer.id}`)
|
|
231
231
|
.send({
|
|
232
232
|
version: 1,
|
|
233
|
-
actions: [{ action:
|
|
234
|
-
})
|
|
235
|
-
expect(response.status).toBe(200)
|
|
236
|
-
expect(response.body.version).toBe(2)
|
|
237
|
-
expect(response.body.companyName).toBe(
|
|
238
|
-
})
|
|
233
|
+
actions: [{ action: "setCompanyName", companyName: "Acme Inc." }],
|
|
234
|
+
});
|
|
235
|
+
expect(response.status).toBe(200);
|
|
236
|
+
expect(response.body.version).toBe(2);
|
|
237
|
+
expect(response.body.companyName).toBe("Acme Inc.");
|
|
238
|
+
});
|
|
239
239
|
|
|
240
|
-
test(
|
|
241
|
-
assert(customer,
|
|
240
|
+
test("setVatId", async () => {
|
|
241
|
+
assert(customer, "customer not created");
|
|
242
242
|
|
|
243
243
|
customer = {
|
|
244
244
|
...customer,
|
|
245
|
-
vatId:
|
|
246
|
-
}
|
|
247
|
-
ctMock.project(
|
|
245
|
+
vatId: "123456789",
|
|
246
|
+
};
|
|
247
|
+
ctMock.project("dummy").add("customer", customer);
|
|
248
248
|
|
|
249
249
|
const response = await supertest(ctMock.app)
|
|
250
250
|
.post(`/dummy/customers/${customer.id}`)
|
|
251
251
|
.send({
|
|
252
252
|
version: 1,
|
|
253
|
-
actions: [{ action:
|
|
254
|
-
})
|
|
255
|
-
expect(response.status).toBe(200)
|
|
256
|
-
expect(response.body.version).toBe(2)
|
|
257
|
-
expect(response.body.vatId).toBe(
|
|
258
|
-
})
|
|
253
|
+
actions: [{ action: "setVatId", vatId: "ABCD" }],
|
|
254
|
+
});
|
|
255
|
+
expect(response.status).toBe(200);
|
|
256
|
+
expect(response.body.version).toBe(2);
|
|
257
|
+
expect(response.body.vatId).toBe("ABCD");
|
|
258
|
+
});
|
|
259
259
|
|
|
260
|
-
test(
|
|
261
|
-
assert(customer,
|
|
260
|
+
test("changeAddress", async () => {
|
|
261
|
+
assert(customer, "customer not created");
|
|
262
262
|
|
|
263
263
|
customer = {
|
|
264
264
|
...customer,
|
|
265
265
|
addresses: [
|
|
266
266
|
{
|
|
267
267
|
...getBaseResourceProperties(),
|
|
268
|
-
id:
|
|
269
|
-
firstName:
|
|
270
|
-
lastName:
|
|
271
|
-
streetName:
|
|
272
|
-
streetNumber:
|
|
273
|
-
postalCode:
|
|
274
|
-
country:
|
|
268
|
+
id: "other-address-uid",
|
|
269
|
+
firstName: "Foo",
|
|
270
|
+
lastName: "Bar",
|
|
271
|
+
streetName: "Baz Street",
|
|
272
|
+
streetNumber: "99",
|
|
273
|
+
postalCode: "12ab",
|
|
274
|
+
country: "NL",
|
|
275
275
|
},
|
|
276
276
|
{
|
|
277
277
|
...getBaseResourceProperties(),
|
|
278
|
-
id:
|
|
279
|
-
firstName:
|
|
280
|
-
lastName:
|
|
281
|
-
streetName:
|
|
282
|
-
streetNumber:
|
|
283
|
-
postalCode:
|
|
284
|
-
country:
|
|
278
|
+
id: "address-uuid",
|
|
279
|
+
firstName: "John",
|
|
280
|
+
lastName: "Doe",
|
|
281
|
+
streetName: "Main Street",
|
|
282
|
+
streetNumber: "1",
|
|
283
|
+
postalCode: "12345",
|
|
284
|
+
country: "DE",
|
|
285
285
|
},
|
|
286
286
|
],
|
|
287
|
-
defaultBillingAddressId:
|
|
288
|
-
}
|
|
289
|
-
ctMock.project(
|
|
287
|
+
defaultBillingAddressId: "address-uuid",
|
|
288
|
+
};
|
|
289
|
+
ctMock.project("dummy").add("customer", customer);
|
|
290
290
|
|
|
291
291
|
const response = await supertest(ctMock.app)
|
|
292
292
|
.post(`/dummy/customers/${customer.id}`)
|
|
@@ -294,80 +294,80 @@ describe('Customer Update Actions', () => {
|
|
|
294
294
|
version: 1,
|
|
295
295
|
actions: [
|
|
296
296
|
{
|
|
297
|
-
action:
|
|
298
|
-
addressId:
|
|
297
|
+
action: "changeAddress",
|
|
298
|
+
addressId: "address-uuid",
|
|
299
299
|
address: {
|
|
300
|
-
firstName:
|
|
301
|
-
lastName:
|
|
302
|
-
streetName:
|
|
303
|
-
streetNumber:
|
|
304
|
-
postalCode:
|
|
305
|
-
country:
|
|
300
|
+
firstName: "Marie",
|
|
301
|
+
lastName: "Johnson",
|
|
302
|
+
streetName: "Last Street",
|
|
303
|
+
streetNumber: "2",
|
|
304
|
+
postalCode: "ABCS",
|
|
305
|
+
country: "US",
|
|
306
306
|
},
|
|
307
307
|
},
|
|
308
308
|
],
|
|
309
|
-
})
|
|
310
|
-
expect(response.status).toBe(200)
|
|
311
|
-
expect(response.body.version).toBe(2)
|
|
309
|
+
});
|
|
310
|
+
expect(response.status).toBe(200);
|
|
311
|
+
expect(response.body.version).toBe(2);
|
|
312
312
|
expect(response.body.addresses).toMatchObject([
|
|
313
313
|
{
|
|
314
|
-
id:
|
|
315
|
-
firstName:
|
|
316
|
-
lastName:
|
|
317
|
-
streetName:
|
|
318
|
-
streetNumber:
|
|
319
|
-
postalCode:
|
|
320
|
-
country:
|
|
314
|
+
id: "other-address-uid",
|
|
315
|
+
firstName: "Foo",
|
|
316
|
+
lastName: "Bar",
|
|
317
|
+
streetName: "Baz Street",
|
|
318
|
+
streetNumber: "99",
|
|
319
|
+
postalCode: "12ab",
|
|
320
|
+
country: "NL",
|
|
321
321
|
},
|
|
322
322
|
{
|
|
323
|
-
id:
|
|
324
|
-
firstName:
|
|
325
|
-
lastName:
|
|
326
|
-
streetName:
|
|
327
|
-
streetNumber:
|
|
328
|
-
postalCode:
|
|
329
|
-
country:
|
|
323
|
+
id: "address-uuid",
|
|
324
|
+
firstName: "Marie",
|
|
325
|
+
lastName: "Johnson",
|
|
326
|
+
streetName: "Last Street",
|
|
327
|
+
streetNumber: "2",
|
|
328
|
+
postalCode: "ABCS",
|
|
329
|
+
country: "US",
|
|
330
330
|
},
|
|
331
|
-
])
|
|
332
|
-
})
|
|
331
|
+
]);
|
|
332
|
+
});
|
|
333
333
|
|
|
334
|
-
test(
|
|
335
|
-
assert(customer,
|
|
334
|
+
test("setCustomerNumber", async () => {
|
|
335
|
+
assert(customer, "customer not created");
|
|
336
336
|
|
|
337
|
-
ctMock.project(
|
|
337
|
+
ctMock.project("dummy").add("customer", customer);
|
|
338
338
|
|
|
339
339
|
const response = await supertest(ctMock.app)
|
|
340
340
|
.post(`/dummy/customers/${customer.id}`)
|
|
341
341
|
.send({
|
|
342
342
|
version: 1,
|
|
343
343
|
actions: [
|
|
344
|
-
{ action:
|
|
344
|
+
{ action: "setCustomerNumber", customerNumber: "CUSTOMER-001" },
|
|
345
345
|
],
|
|
346
|
-
})
|
|
347
|
-
expect(response.status).toBe(200)
|
|
348
|
-
expect(response.body.version).toBe(2)
|
|
349
|
-
expect(response.body.customerNumber).toBe(
|
|
350
|
-
})
|
|
346
|
+
});
|
|
347
|
+
expect(response.status).toBe(200);
|
|
348
|
+
expect(response.body.version).toBe(2);
|
|
349
|
+
expect(response.body.customerNumber).toBe("CUSTOMER-001");
|
|
350
|
+
});
|
|
351
351
|
|
|
352
|
-
test(
|
|
353
|
-
assert(customer,
|
|
352
|
+
test("setCustomerNumber error when already have a customer number", async () => {
|
|
353
|
+
assert(customer, "customer not created");
|
|
354
354
|
|
|
355
|
-
ctMock.project(
|
|
355
|
+
ctMock.project("dummy").add("customer", {
|
|
356
356
|
...customer,
|
|
357
|
-
customerNumber:
|
|
358
|
-
})
|
|
357
|
+
customerNumber: "CUSTOMER-002",
|
|
358
|
+
});
|
|
359
359
|
|
|
360
360
|
const response = await supertest(ctMock.app)
|
|
361
361
|
.post(`/dummy/customers/${customer.id}`)
|
|
362
362
|
.send({
|
|
363
363
|
version: 1,
|
|
364
364
|
actions: [
|
|
365
|
-
{ action:
|
|
365
|
+
{ action: "setCustomerNumber", customerNumber: "CUSTOMER-001" },
|
|
366
366
|
],
|
|
367
|
-
})
|
|
368
|
-
expect(response.status).toBe(500)
|
|
367
|
+
});
|
|
368
|
+
expect(response.status).toBe(500);
|
|
369
369
|
expect(response.body.error).toBe(
|
|
370
|
-
|
|
371
|
-
)
|
|
372
|
-
})
|
|
373
|
-
})
|
|
370
|
+
"A Customer number already exists and cannot be set again.",
|
|
371
|
+
);
|
|
372
|
+
});
|
|
373
|
+
});
|
package/src/services/customer.ts
CHANGED
|
@@ -1,56 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import AbstractService from './abstract.js'
|
|
7
|
-
import { CustomerSignInResult } from '@commercetools/platform-sdk'
|
|
1
|
+
import { CustomerSignInResult } from "@commercetools/platform-sdk";
|
|
2
|
+
import { Router, type Request, type Response } from "express";
|
|
3
|
+
import { CustomerRepository } from "../repositories/customer";
|
|
4
|
+
import { getRepositoryContext } from "../repositories/helpers";
|
|
5
|
+
import AbstractService from "./abstract";
|
|
8
6
|
|
|
9
7
|
export class CustomerService extends AbstractService {
|
|
10
|
-
public repository: CustomerRepository
|
|
8
|
+
public repository: CustomerRepository;
|
|
11
9
|
|
|
12
10
|
constructor(parent: Router, repository: CustomerRepository) {
|
|
13
|
-
super(parent)
|
|
14
|
-
this.repository = repository
|
|
11
|
+
super(parent);
|
|
12
|
+
this.repository = repository;
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
getBasePath() {
|
|
18
|
-
return
|
|
16
|
+
return "customers";
|
|
19
17
|
}
|
|
20
18
|
|
|
21
19
|
post(request: Request, response: Response) {
|
|
22
|
-
const draft = request.body
|
|
20
|
+
const draft = request.body;
|
|
23
21
|
const resource = this.repository.create(
|
|
24
22
|
getRepositoryContext(request),
|
|
25
|
-
draft
|
|
26
|
-
)
|
|
27
|
-
const expanded = this._expandWithId(request, resource.id)
|
|
23
|
+
draft,
|
|
24
|
+
);
|
|
25
|
+
const expanded = this._expandWithId(request, resource.id);
|
|
28
26
|
|
|
29
27
|
const result: CustomerSignInResult = {
|
|
30
28
|
customer: expanded,
|
|
31
|
-
}
|
|
32
|
-
return response.status(this.createStatusCode).send(result)
|
|
29
|
+
};
|
|
30
|
+
return response.status(this.createStatusCode).send(result);
|
|
33
31
|
}
|
|
34
32
|
|
|
35
33
|
extraRoutes(parent: Router) {
|
|
36
|
-
parent.post(
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
: 34560
|
|
45
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
46
|
-
const { version, ...rest } = getBaseResourceProperties()
|
|
47
|
-
|
|
48
|
-
return response.status(200).send({
|
|
49
|
-
...rest,
|
|
50
|
-
customerId: customer.results[0].id,
|
|
51
|
-
expiresAt: new Date(Date.now() + ttlMinutes * 60).toISOString(),
|
|
52
|
-
value: uuidv4(),
|
|
53
|
-
})
|
|
54
|
-
})
|
|
34
|
+
parent.post("/password-token", (request, response) => {
|
|
35
|
+
const email = request.body.email;
|
|
36
|
+
const token = this.repository.passwordResetToken(
|
|
37
|
+
getRepositoryContext(request),
|
|
38
|
+
email,
|
|
39
|
+
);
|
|
40
|
+
return response.status(200).send(token);
|
|
41
|
+
});
|
|
55
42
|
}
|
|
56
43
|
}
|