@labdigital/commercetools-mock 2.24.0 → 2.26.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
- "version": "2.24.0",
3
+ "version": "2.26.1",
4
4
  "license": "MIT",
5
5
  "author": "Michael van Tellingen",
6
6
  "type": "module",
@@ -5,10 +5,13 @@ import type {
5
5
  CustomerSetAuthenticationModeAction,
6
6
  CustomerSetCompanyNameAction,
7
7
  CustomerSetCustomFieldAction,
8
+ CustomerSetCustomTypeAction,
8
9
  CustomerSetCustomerNumberAction,
10
+ CustomerSetExternalIdAction,
9
11
  CustomerSetFirstNameAction,
10
12
  CustomerSetKeyAction,
11
13
  CustomerSetLastNameAction,
14
+ CustomerSetLocaleAction,
12
15
  CustomerSetSalutationAction,
13
16
  CustomerSetVatIdAction,
14
17
  CustomerUpdateAction,
@@ -23,7 +26,7 @@ import {
23
26
  UpdateHandlerInterface,
24
27
  type RepositoryContext,
25
28
  } from "../abstract";
26
- import { createAddress } from "../helpers";
29
+ import { createAddress, createCustomFields } from "../helpers";
27
30
 
28
31
  export class CustomerUpdateHandler
29
32
  extends AbstractUpdateHandler
@@ -141,6 +144,30 @@ export class CustomerUpdateHandler
141
144
  resource.custom.fields[name] = value;
142
145
  }
143
146
 
147
+ setCustomType(
148
+ context: RepositoryContext,
149
+ resource: Writable<Customer>,
150
+ { type, fields }: CustomerSetCustomTypeAction,
151
+ ) {
152
+ if (type) {
153
+ resource.custom = createCustomFields(
154
+ { type, fields },
155
+ context.projectKey,
156
+ this._storage,
157
+ );
158
+ } else {
159
+ resource.custom = undefined;
160
+ }
161
+ }
162
+
163
+ setExternalId(
164
+ _context: RepositoryContext,
165
+ resource: Writable<Customer>,
166
+ { externalId }: CustomerSetExternalIdAction,
167
+ ) {
168
+ resource.externalId = externalId;
169
+ }
170
+
144
171
  setFirstName(
145
172
  _context: RepositoryContext,
146
173
  resource: Writable<Customer>,
@@ -165,6 +192,14 @@ export class CustomerUpdateHandler
165
192
  resource.lastName = lastName;
166
193
  }
167
194
 
195
+ setLocale(
196
+ _context: RepositoryContext,
197
+ resource: Writable<Customer>,
198
+ { locale }: CustomerSetLocaleAction,
199
+ ) {
200
+ resource.locale = locale;
201
+ }
202
+
168
203
  setSalutation(
169
204
  _context: RepositoryContext,
170
205
  resource: Writable<Customer>,
@@ -177,6 +177,26 @@ describe("Customer Update Actions", () => {
177
177
  expect(response.body.custom.fields.isValidCouponCode).toBe(false);
178
178
  });
179
179
 
180
+ test("setExternalId", async () => {
181
+ assert(customer, "customer not created");
182
+
183
+ customer = {
184
+ ...customer,
185
+ firstName: "John",
186
+ };
187
+ ctMock.project("dummy").add("customer", customer);
188
+
189
+ const response = await supertest(ctMock.app)
190
+ .post(`/dummy/customers/${customer.id}`)
191
+ .send({
192
+ version: 1,
193
+ actions: [{ action: "setExternalId", externalId: "123-xx-123" }],
194
+ });
195
+ expect(response.status).toBe(200);
196
+ expect(response.body.version).toBe(2);
197
+ expect(response.body.externalId).toBe("123-xx-123");
198
+ });
199
+
180
200
  test("setFirstName", async () => {
181
201
  assert(customer, "customer not created");
182
202
 
@@ -217,6 +237,26 @@ describe("Customer Update Actions", () => {
217
237
  expect(response.body.lastName).toBe("Smith");
218
238
  });
219
239
 
240
+ test("setLocale", async () => {
241
+ assert(customer, "customer not created");
242
+
243
+ customer = {
244
+ ...customer,
245
+ salutation: "Mr.",
246
+ };
247
+ ctMock.project("dummy").add("customer", customer);
248
+
249
+ const response = await supertest(ctMock.app)
250
+ .post(`/dummy/customers/${customer.id}`)
251
+ .send({
252
+ version: 1,
253
+ actions: [{ action: "setLocale", locale: "de-DE" }],
254
+ });
255
+ expect(response.status).toBe(200);
256
+ expect(response.body.version).toBe(2);
257
+ expect(response.body.locale).toBe("de-DE");
258
+ });
259
+
220
260
  test("setSalutation", async () => {
221
261
  assert(customer, "customer not created");
222
262