@labdigital/commercetools-mock 2.18.1 → 2.19.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 +6 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ctMock.ts +2 -2
- package/src/repositories/customer/actions.ts +18 -0
- package/src/services/customer.test.ts +36 -0
package/package.json
CHANGED
package/src/ctMock.ts
CHANGED
|
@@ -2,7 +2,7 @@ import express, { NextFunction, Request, Response } from "express";
|
|
|
2
2
|
import inject from "light-my-request";
|
|
3
3
|
import morgan from "morgan";
|
|
4
4
|
import { http, HttpResponse } from "msw";
|
|
5
|
-
import { setupServer, SetupServer } from "msw/node";
|
|
5
|
+
import { setupServer, SetupServer, SetupServerApi } from "msw/node";
|
|
6
6
|
import { DEFAULT_API_HOSTNAME, DEFAULT_AUTH_HOSTNAME } from "./constants";
|
|
7
7
|
import { CommercetoolsError } from "./exceptions";
|
|
8
8
|
import { copyHeaders } from "./lib/proxy";
|
|
@@ -185,7 +185,7 @@ export class CommercetoolsMock {
|
|
|
185
185
|
// registerHandlers is an alternative way to work with commercetools-mock, it
|
|
186
186
|
// allows you to manage msw server yourself and register the handlers needed
|
|
187
187
|
// for commercetools-mock to work.
|
|
188
|
-
public registerHandlers(server:
|
|
188
|
+
public registerHandlers(server: SetupServerApi) {
|
|
189
189
|
const app = this.app;
|
|
190
190
|
server.use(
|
|
191
191
|
http.post(`${this.options.authHost}/oauth/*`, async ({ request }) => {
|
|
@@ -7,7 +7,9 @@ import type {
|
|
|
7
7
|
CustomerSetCustomFieldAction,
|
|
8
8
|
CustomerSetCustomerNumberAction,
|
|
9
9
|
CustomerSetFirstNameAction,
|
|
10
|
+
CustomerSetKeyAction,
|
|
10
11
|
CustomerSetLastNameAction,
|
|
12
|
+
CustomerSetSalutationAction,
|
|
11
13
|
CustomerSetVatIdAction,
|
|
12
14
|
CustomerUpdateAction,
|
|
13
15
|
InvalidInputError,
|
|
@@ -147,6 +149,14 @@ export class CustomerUpdateHandler
|
|
|
147
149
|
resource.firstName = firstName;
|
|
148
150
|
}
|
|
149
151
|
|
|
152
|
+
setKey(
|
|
153
|
+
_context: RepositoryContext,
|
|
154
|
+
resource: Writable<Customer>,
|
|
155
|
+
{ key }: CustomerSetKeyAction,
|
|
156
|
+
) {
|
|
157
|
+
resource.key = key;
|
|
158
|
+
}
|
|
159
|
+
|
|
150
160
|
setLastName(
|
|
151
161
|
_context: RepositoryContext,
|
|
152
162
|
resource: Writable<Customer>,
|
|
@@ -155,6 +165,14 @@ export class CustomerUpdateHandler
|
|
|
155
165
|
resource.lastName = lastName;
|
|
156
166
|
}
|
|
157
167
|
|
|
168
|
+
setSalutation(
|
|
169
|
+
_context: RepositoryContext,
|
|
170
|
+
resource: Writable<Customer>,
|
|
171
|
+
{ salutation }: CustomerSetSalutationAction,
|
|
172
|
+
) {
|
|
173
|
+
resource.salutation = salutation;
|
|
174
|
+
}
|
|
175
|
+
|
|
158
176
|
setVatId(
|
|
159
177
|
_context: RepositoryContext,
|
|
160
178
|
resource: Writable<Customer>,
|
|
@@ -217,6 +217,26 @@ describe("Customer Update Actions", () => {
|
|
|
217
217
|
expect(response.body.lastName).toBe("Smith");
|
|
218
218
|
});
|
|
219
219
|
|
|
220
|
+
test("setSalutation", async () => {
|
|
221
|
+
assert(customer, "customer not created");
|
|
222
|
+
|
|
223
|
+
customer = {
|
|
224
|
+
...customer,
|
|
225
|
+
salutation: "Mr.",
|
|
226
|
+
};
|
|
227
|
+
ctMock.project("dummy").add("customer", customer);
|
|
228
|
+
|
|
229
|
+
const response = await supertest(ctMock.app)
|
|
230
|
+
.post(`/dummy/customers/${customer.id}`)
|
|
231
|
+
.send({
|
|
232
|
+
version: 1,
|
|
233
|
+
actions: [{ action: "setSalutation", salutation: "Mrs." }],
|
|
234
|
+
});
|
|
235
|
+
expect(response.status).toBe(200);
|
|
236
|
+
expect(response.body.version).toBe(2);
|
|
237
|
+
expect(response.body.salutation).toBe("Mrs.");
|
|
238
|
+
});
|
|
239
|
+
|
|
220
240
|
test("setCompanyName", async () => {
|
|
221
241
|
assert(customer, "customer not created");
|
|
222
242
|
|
|
@@ -370,4 +390,20 @@ describe("Customer Update Actions", () => {
|
|
|
370
390
|
"A Customer number already exists and cannot be set again.",
|
|
371
391
|
);
|
|
372
392
|
});
|
|
393
|
+
|
|
394
|
+
test("setKey", async () => {
|
|
395
|
+
assert(customer, "customer not created");
|
|
396
|
+
|
|
397
|
+
ctMock.project("dummy").add("customer", customer);
|
|
398
|
+
|
|
399
|
+
const response = await supertest(ctMock.app)
|
|
400
|
+
.post(`/dummy/customers/${customer.id}`)
|
|
401
|
+
.send({
|
|
402
|
+
version: 1,
|
|
403
|
+
actions: [{ action: "setKey", key: "C001" }],
|
|
404
|
+
});
|
|
405
|
+
expect(response.status).toBe(200);
|
|
406
|
+
expect(response.body.version).toBe(2);
|
|
407
|
+
expect(response.body.key).toBe("C001");
|
|
408
|
+
});
|
|
373
409
|
});
|