@labdigital/commercetools-mock 2.15.0 → 2.16.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,7 +1,7 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
3
  "author": "Michael van Tellingen",
4
- "version": "2.15.0",
4
+ "version": "2.16.1",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
@@ -9,6 +9,7 @@ import type {
9
9
  CustomerSetFirstNameAction,
10
10
  CustomerSetLastNameAction,
11
11
  CustomerSetVatIdAction,
12
+ CustomerSetCustomerNumberAction,
12
13
  DuplicateFieldError,
13
14
  InvalidInputError,
14
15
  InvalidJsonInputError,
@@ -211,5 +212,17 @@ export class CustomerRepository extends AbstractResourceRepository<'customer'> {
211
212
  }
212
213
  resource.custom.fields[name] = value
213
214
  },
215
+ setCustomerNumber: (
216
+ _context: RepositoryContext,
217
+ resource: Writable<Customer>,
218
+ { customerNumber }: CustomerSetCustomerNumberAction
219
+ ) => {
220
+ if (resource.customerNumber) {
221
+ throw new Error(
222
+ 'A Customer number already exists and cannot be set again.'
223
+ )
224
+ }
225
+ resource.customerNumber = customerNumber
226
+ },
214
227
  }
215
228
  }
@@ -345,7 +345,7 @@ export class ShoppingListRepository extends AbstractResourceRepository<'shopping
345
345
  ),
346
346
  }
347
347
 
348
- if (variantId) {
348
+ if (productId && variantId) {
349
349
  return lineItem
350
350
  }
351
351
 
@@ -367,6 +367,7 @@ export class ShoppingListRepository extends AbstractResourceRepository<'shopping
367
367
  ]
368
368
  const variantId = allVariants.find((e) => e.sku === sku)?.id
369
369
  lineItem.variantId = variantId
370
+ lineItem.productId = product.id
370
371
  return lineItem
371
372
  }
372
373
 
@@ -330,4 +330,44 @@ describe('Customer Update Actions', () => {
330
330
  },
331
331
  ])
332
332
  })
333
+
334
+ test('setCustomerNumber', async () => {
335
+ assert(customer, 'customer not created')
336
+
337
+ ctMock.project('dummy').add('customer', customer)
338
+
339
+ const response = await supertest(ctMock.app)
340
+ .post(`/dummy/customers/${customer.id}`)
341
+ .send({
342
+ version: 1,
343
+ actions: [
344
+ { action: 'setCustomerNumber', customerNumber: 'CUSTOMER-001' },
345
+ ],
346
+ })
347
+ expect(response.status).toBe(200)
348
+ expect(response.body.version).toBe(2)
349
+ expect(response.body.customerNumber).toBe('CUSTOMER-001')
350
+ })
351
+
352
+ test('setCustomerNumber error when already have a customer number', async () => {
353
+ assert(customer, 'customer not created')
354
+
355
+ ctMock.project('dummy').add('customer', {
356
+ ...customer,
357
+ customerNumber: 'CUSTOMER-002',
358
+ })
359
+
360
+ const response = await supertest(ctMock.app)
361
+ .post(`/dummy/customers/${customer.id}`)
362
+ .send({
363
+ version: 1,
364
+ actions: [
365
+ { action: 'setCustomerNumber', customerNumber: 'CUSTOMER-001' },
366
+ ],
367
+ })
368
+ expect(response.status).toBe(500)
369
+ expect(response.body.error).toBe(
370
+ 'A Customer number already exists and cannot be set again.'
371
+ )
372
+ })
333
373
  })
@@ -93,7 +93,7 @@ describe('Shopping List', () => {
93
93
  expect(response.body.lineItems[0].variantId).toBe(2)
94
94
  })
95
95
 
96
- test('Expands variant on lineItems', async () => {
96
+ test('Expands variant on lineItems when getting', async () => {
97
97
  const response = await supertest(ctMock.app)
98
98
  .get(`/dummy/shopping-lists/${shoppingList.id}`)
99
99
  .query({ expand: 'lineItems[*].variant' })
@@ -104,6 +104,23 @@ describe('Shopping List', () => {
104
104
  sku: '22241940260',
105
105
  })
106
106
  })
107
+
108
+ test('Expands variant on lineItems when creating', async () => {
109
+ const draft: ShoppingListDraft = {
110
+ name: {},
111
+ lineItems: [{ sku: '22241940260' }],
112
+ }
113
+ const response = await supertest(ctMock.app)
114
+ .post('/dummy/shopping-lists')
115
+ .query({ expand: 'lineItems[*].variant' })
116
+ .send(draft)
117
+
118
+ expect(response.status).toBe(201)
119
+ expect(response.body.lineItems[0].variant).toEqual({
120
+ id: 2,
121
+ sku: '22241940260',
122
+ })
123
+ })
107
124
  })
108
125
 
109
126
  describe('Shopping List Update Actions', () => {