@labdigital/commercetools-mock 1.4.0 → 1.5.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
3
  "author": "Michael van Tellingen",
4
- "version": "1.4.0",
4
+ "version": "1.5.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
package/src/lib/parser.ts CHANGED
@@ -1,2 +1,2 @@
1
- export { Lexer } from '../../vendor/perplex/lexer.js';
2
- export { Parser, type ITokenPosition } from '../../vendor/pratt/index.js';
1
+ export { Lexer } from '~vendor/perplex/lexer.js';
2
+ export { Parser, type ITokenPosition } from '~vendor/pratt/index.js';
@@ -3,13 +3,17 @@ import type {
3
3
  CustomerChangeEmailAction,
4
4
  CustomerDraft,
5
5
  CustomerSetAuthenticationModeAction,
6
+ CustomerSetCustomFieldAction,
6
7
  InvalidInputError,
7
8
  InvalidJsonInputError,
8
9
  } from '@commercetools/platform-sdk'
9
- import type { Writable } from '../types.js'
10
10
  import { CommercetoolsError } from '../exceptions.js'
11
11
  import { getBaseResourceProperties } from '../helpers.js'
12
- import { AbstractResourceRepository, type RepositoryContext } from './abstract.js'
12
+ import type { Writable } from '../types.js'
13
+ import {
14
+ AbstractResourceRepository,
15
+ type RepositoryContext,
16
+ } from './abstract.js'
13
17
 
14
18
  export class CustomerRepository extends AbstractResourceRepository<'customer'> {
15
19
  getTypeId() {
@@ -86,5 +90,15 @@ export class CustomerRepository extends AbstractResourceRepository<'customer'> {
86
90
  400
87
91
  )
88
92
  },
93
+ setCustomField: (
94
+ _context: RepositoryContext,
95
+ resource: Writable<Customer>,
96
+ { name, value }: CustomerSetCustomFieldAction
97
+ ) => {
98
+ if (!resource.custom) {
99
+ throw new Error('Resource has no custom field')
100
+ }
101
+ resource.custom.fields[name] = value
102
+ },
89
103
  }
90
104
  }
@@ -326,7 +326,11 @@ export class OrderRepository extends AbstractResourceRepository<'order'> {
326
326
  )
327
327
  }
328
328
 
329
- resource.state = { typeId: 'state', id: resolvedType.id }
329
+ resource.state = {
330
+ typeId: 'state',
331
+ id: resolvedType.id,
332
+ obj: { ...resolvedType, key: state.key ?? '' },
333
+ }
330
334
  },
331
335
  setBillingAddress: (
332
336
  context: RepositoryContext,
@@ -134,4 +134,26 @@ describe('Customer Update Actions', () => {
134
134
  Buffer.from('newpass').toString('base64')
135
135
  )
136
136
  })
137
+
138
+ test('setCustomField', async () => {
139
+ assert(customer, 'customer not created')
140
+
141
+ customer = {
142
+ ...customer,
143
+ custom: { type: { typeId: 'type', id: '' }, fields: {} },
144
+ }
145
+ ctMock.project('dummy').add('customer', customer)
146
+
147
+ const response = await supertest(ctMock.app)
148
+ .post(`/dummy/customers/${customer.id}`)
149
+ .send({
150
+ version: 1,
151
+ actions: [
152
+ { action: 'setCustomField', name: 'isValidCouponCode', value: false },
153
+ ],
154
+ })
155
+ expect(response.status).toBe(200)
156
+ expect(response.body.version).toBe(2)
157
+ expect(response.body.custom.fields.isValidCouponCode).toBe(false)
158
+ })
137
159
  })