@labdigital/commercetools-mock 1.2.0 → 1.3.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.
Files changed (86) hide show
  1. package/dist/index.d.mts +602 -0
  2. package/dist/index.d.ts +43 -26
  3. package/dist/index.global.js +5827 -5596
  4. package/dist/index.global.js.map +1 -1
  5. package/dist/index.js +344 -167
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +344 -171
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +33 -39
  10. package/src/index.test.ts +2 -1
  11. package/src/lib/haversine.test.ts +1 -0
  12. package/src/lib/predicateParser.test.ts +2 -1
  13. package/src/lib/predicateParser.ts +2 -2
  14. package/src/lib/projectionSearchFilter.test.ts +2 -1
  15. package/src/lib/projectionSearchFilter.ts +4 -4
  16. package/src/oauth/server.ts +3 -4
  17. package/src/priceSelector.test.ts +2 -1
  18. package/src/priceSelector.ts +2 -2
  19. package/src/product-projection-search.ts +8 -8
  20. package/src/projectAPI.test.ts +1 -0
  21. package/src/repositories/abstract.ts +1 -1
  22. package/src/repositories/associate-role.ts +11 -0
  23. package/src/repositories/attribute-group.ts +11 -0
  24. package/src/repositories/business-unit.ts +11 -0
  25. package/src/repositories/cart-discount.ts +11 -4
  26. package/src/repositories/cart.ts +90 -13
  27. package/src/repositories/category.ts +3 -3
  28. package/src/repositories/channel.ts +3 -3
  29. package/src/repositories/custom-object.ts +3 -3
  30. package/src/repositories/customer-group.ts +3 -3
  31. package/src/repositories/customer.ts +4 -3
  32. package/src/repositories/discount-code.ts +3 -3
  33. package/src/repositories/errors.ts +1 -1
  34. package/src/repositories/extension.ts +3 -3
  35. package/src/repositories/helpers.ts +49 -6
  36. package/src/repositories/index.ts +6 -0
  37. package/src/repositories/inventory-entry.ts +4 -4
  38. package/src/repositories/my-order.ts +2 -2
  39. package/src/repositories/order-edit.ts +2 -2
  40. package/src/repositories/order.test.ts +10 -39
  41. package/src/repositories/order.ts +31 -16
  42. package/src/repositories/payment.ts +8 -7
  43. package/src/repositories/product-discount.ts +2 -2
  44. package/src/repositories/product-projection.ts +5 -5
  45. package/src/repositories/product-selection.ts +3 -2
  46. package/src/repositories/product-type.ts +2 -2
  47. package/src/repositories/product.ts +4 -9
  48. package/src/repositories/project.ts +2 -2
  49. package/src/repositories/quote-request.ts +2 -2
  50. package/src/repositories/quote.ts +2 -2
  51. package/src/repositories/review.ts +2 -2
  52. package/src/repositories/shipping-method.ts +2 -2
  53. package/src/repositories/shopping-list.ts +19 -13
  54. package/src/repositories/staged-quote.ts +2 -2
  55. package/src/repositories/standalone-price.ts +3 -3
  56. package/src/repositories/state.ts +2 -2
  57. package/src/repositories/store.ts +3 -2
  58. package/src/repositories/subscription.ts +1 -1
  59. package/src/repositories/tax-category.ts +2 -2
  60. package/src/repositories/type.ts +2 -2
  61. package/src/repositories/zone.ts +2 -2
  62. package/src/services/abstract.ts +2 -2
  63. package/src/services/cart.test.ts +2 -1
  64. package/src/services/cart.ts +4 -4
  65. package/src/services/category.test.ts +2 -1
  66. package/src/services/custom-object.test.ts +2 -1
  67. package/src/services/custom-object.ts +3 -3
  68. package/src/services/customer.test.ts +1 -0
  69. package/src/services/inventory-entry.test.ts +2 -1
  70. package/src/services/my-cart.test.ts +7 -3
  71. package/src/services/my-customer.test.ts +4 -2
  72. package/src/services/my-payment.test.ts +2 -1
  73. package/src/services/order.test.ts +2 -1
  74. package/src/services/payment.test.ts +2 -1
  75. package/src/services/product-projection.test.ts +3 -2
  76. package/src/services/product-type.test.ts +2 -1
  77. package/src/services/product.test.ts +2 -1
  78. package/src/services/project.ts +1 -1
  79. package/src/services/shipping-method.test.ts +2 -1
  80. package/src/services/standalone-price.test.ts +255 -244
  81. package/src/services/state.test.ts +2 -1
  82. package/src/services/store.test.ts +6 -1
  83. package/src/services/tax-category.test.ts +2 -1
  84. package/src/storage/abstract.ts +1 -1
  85. package/src/storage/in-memory.ts +7 -1
  86. package/src/types.ts +7 -1
@@ -1,275 +1,286 @@
1
- import { StandalonePriceDraft } from '@commercetools/platform-sdk'
1
+ import type { StandalonePriceDraft } from '@commercetools/platform-sdk'
2
2
  import supertest from 'supertest'
3
+ import {
4
+ afterAll,
5
+ afterEach,
6
+ beforeAll,
7
+ beforeEach,
8
+ describe,
9
+ expect,
10
+ test,
11
+ } from 'vitest'
3
12
  import { CommercetoolsMock } from '../index'
4
13
 
5
14
  const ctMock = new CommercetoolsMock()
6
15
 
7
16
  describe('Standalone price Query', () => {
8
- beforeAll(async () => {
9
- const draft: StandalonePriceDraft = {
10
- value: {
11
- centAmount: 100,
12
- currencyCode: 'EUR',
13
- },
14
- country: 'DE',
15
- sku: 'foo',
16
- active: true,
17
- channel: {
18
- typeId: 'channel',
19
- id: 'bar',
20
- },
21
- discounted: {
22
- value: {
23
- centAmount: 80,
24
- currencyCode: 'EUR',
25
- },
26
- discount: {
27
- typeId: 'product-discount',
28
- id: 'baz',
29
- },
30
- },
31
- }
32
- const createResponse = await supertest(ctMock.app)
33
- .post('/dummy/standalone-prices')
34
- .send(draft)
35
- expect(createResponse.status).toEqual(201)
36
- })
17
+ beforeAll(async () => {
18
+ const draft: StandalonePriceDraft = {
19
+ value: {
20
+ centAmount: 100,
21
+ currencyCode: 'EUR',
22
+ },
23
+ country: 'DE',
24
+ sku: 'foo',
25
+ active: true,
26
+ channel: {
27
+ typeId: 'channel',
28
+ id: 'bar',
29
+ },
30
+ discounted: {
31
+ value: {
32
+ centAmount: 80,
33
+ currencyCode: 'EUR',
34
+ },
35
+ discount: {
36
+ typeId: 'product-discount',
37
+ id: 'baz',
38
+ },
39
+ },
40
+ }
41
+ const createResponse = await supertest(ctMock.app)
42
+ .post('/dummy/standalone-prices')
43
+ .send(draft)
44
+ expect(createResponse.status).toEqual(201)
45
+ })
37
46
 
38
- afterAll(async () => {
39
- ctMock.clear()
40
- })
47
+ afterAll(async () => {
48
+ ctMock.clear()
49
+ })
41
50
 
42
- test('Get standalone price', async () => {
43
- const response = await supertest(ctMock.app).get('/dummy/standalone-prices?sku=foo')
51
+ test('Get standalone price', async () => {
52
+ const response = await supertest(ctMock.app).get(
53
+ '/dummy/standalone-prices?sku=foo'
54
+ )
44
55
 
45
- expect(response.status).toBe(200)
56
+ expect(response.status).toBe(200)
46
57
 
47
- expect(response.body.results).toEqual([
48
- {
49
- active: true,
50
- channel: {
51
- id: 'bar',
52
- typeId: 'channel',
53
- },
54
- country: 'DE',
55
- createdAt: expect.anything(),
56
- discounted: {
57
- discount: {
58
- id: 'baz',
59
- typeId: 'product-discount',
60
- },
61
- value: {
62
- centAmount: 80,
63
- currencyCode: 'EUR',
64
- fractionDigits: 2,
65
- type: 'centPrecision',
66
- },
67
- },
68
- id: expect.anything(),
69
- lastModifiedAt: expect.anything(),
70
- sku: 'foo',
71
- value: {
72
- centAmount: 100,
73
- currencyCode: 'EUR',
74
- fractionDigits: 2,
75
- type: 'centPrecision',
76
- },
77
- version: 1,
78
- },
79
- ])
80
- })
58
+ expect(response.body.results).toEqual([
59
+ {
60
+ active: true,
61
+ channel: {
62
+ id: 'bar',
63
+ typeId: 'channel',
64
+ },
65
+ country: 'DE',
66
+ createdAt: expect.anything(),
67
+ discounted: {
68
+ discount: {
69
+ id: 'baz',
70
+ typeId: 'product-discount',
71
+ },
72
+ value: {
73
+ centAmount: 80,
74
+ currencyCode: 'EUR',
75
+ fractionDigits: 2,
76
+ type: 'centPrecision',
77
+ },
78
+ },
79
+ id: expect.anything(),
80
+ lastModifiedAt: expect.anything(),
81
+ sku: 'foo',
82
+ value: {
83
+ centAmount: 100,
84
+ currencyCode: 'EUR',
85
+ fractionDigits: 2,
86
+ type: 'centPrecision',
87
+ },
88
+ version: 1,
89
+ },
90
+ ])
91
+ })
81
92
  })
82
93
 
83
94
  describe('Standalone price Actions', () => {
84
- let id: string | undefined
85
- beforeEach(async () => {
86
- const draft: StandalonePriceDraft = {
87
- value: {
88
- centAmount: 100,
89
- currencyCode: 'EUR',
90
- },
91
- country: 'DE',
92
- sku: 'foo',
93
- active: true,
94
- channel: {
95
- typeId: 'channel',
96
- id: 'bar',
97
- },
98
- }
99
- const createResponse = await supertest(ctMock.app)
100
- .post('/dummy/standalone-prices')
101
- .send(draft)
102
- expect(createResponse.status).toEqual(201)
103
- id = createResponse.body.id
104
- })
95
+ let id: string | undefined
96
+ beforeEach(async () => {
97
+ const draft: StandalonePriceDraft = {
98
+ value: {
99
+ centAmount: 100,
100
+ currencyCode: 'EUR',
101
+ },
102
+ country: 'DE',
103
+ sku: 'foo',
104
+ active: true,
105
+ channel: {
106
+ typeId: 'channel',
107
+ id: 'bar',
108
+ },
109
+ }
110
+ const createResponse = await supertest(ctMock.app)
111
+ .post('/dummy/standalone-prices')
112
+ .send(draft)
113
+ expect(createResponse.status).toEqual(201)
114
+ id = createResponse.body.id
115
+ })
105
116
 
106
- afterEach(async () => {
107
- ctMock.clear()
108
- })
109
-
110
- test('changeValue', async () => {
111
- const response = await supertest(ctMock.app)
112
- .post('/dummy/standalone-prices/' + id)
113
- .send({
114
- version: 1,
115
- actions: [
116
- {
117
- action: 'changeValue',
118
- value: {
119
- centAmount: 200,
120
- currencyCode: 'EUR',
121
- },
122
- },
123
- ],
124
- })
125
-
126
- expect(response.status).toBe(200)
117
+ afterEach(async () => {
118
+ ctMock.clear()
119
+ })
127
120
 
128
- expect(response.body).toEqual({
129
- active: true,
130
- channel: {
131
- id: 'bar',
132
- typeId: 'channel',
133
- },
134
- country: 'DE',
135
- createdAt: expect.anything(),
136
- id: id,
137
- lastModifiedAt: expect.anything(),
138
- sku: 'foo',
121
+ test('changeValue', async () => {
122
+ const response = await supertest(ctMock.app)
123
+ .post('/dummy/standalone-prices/' + id)
124
+ .send({
125
+ version: 1,
126
+ actions: [
127
+ {
128
+ action: 'changeValue',
139
129
  value: {
140
- centAmount: 200,
141
- currencyCode: 'EUR',
142
- fractionDigits: 2,
143
- type: 'centPrecision',
130
+ centAmount: 200,
131
+ currencyCode: 'EUR',
144
132
  },
145
- version: 2,
146
- })
147
- })
133
+ },
134
+ ],
135
+ })
148
136
 
149
- test('setActive', async () => {
150
- const response = await supertest(ctMock.app)
151
- .post('/dummy/standalone-prices/' + id)
152
- .send({
153
- version: 1,
154
- actions: [
155
- {
156
- action: 'setActive',
157
- active: false,
158
- },
159
- ],
160
- })
137
+ expect(response.status).toBe(200)
161
138
 
162
- expect(response.status).toBe(200)
139
+ expect(response.body).toEqual({
140
+ active: true,
141
+ channel: {
142
+ id: 'bar',
143
+ typeId: 'channel',
144
+ },
145
+ country: 'DE',
146
+ createdAt: expect.anything(),
147
+ id: id,
148
+ lastModifiedAt: expect.anything(),
149
+ sku: 'foo',
150
+ value: {
151
+ centAmount: 200,
152
+ currencyCode: 'EUR',
153
+ fractionDigits: 2,
154
+ type: 'centPrecision',
155
+ },
156
+ version: 2,
157
+ })
158
+ })
163
159
 
164
- expect(response.body).toEqual({
160
+ test('setActive', async () => {
161
+ const response = await supertest(ctMock.app)
162
+ .post('/dummy/standalone-prices/' + id)
163
+ .send({
164
+ version: 1,
165
+ actions: [
166
+ {
167
+ action: 'setActive',
165
168
  active: false,
166
- channel: {
167
- id: 'bar',
168
- typeId: 'channel',
169
- },
170
- country: 'DE',
171
- createdAt: expect.anything(),
172
- id: id,
173
- lastModifiedAt: expect.anything(),
174
- sku: 'foo',
175
- value: {
176
- centAmount: 100,
177
- currencyCode: 'EUR',
178
- fractionDigits: 2,
179
- type: 'centPrecision',
180
- },
181
- version: 2,
182
- })
183
- })
169
+ },
170
+ ],
171
+ })
184
172
 
185
- test('setDiscounted', async () => {
186
- const response = await supertest(ctMock.app)
187
- .post('/dummy/standalone-prices/' + id)
188
- .send({
189
- version: 1,
190
- actions: [
191
- {
192
- action: 'setDiscountedPrice',
193
- discounted: {
194
- value: {
195
- centAmount: 80,
196
- currencyCode: 'EUR',
197
- },
198
- discount: {
199
- typeId: 'product-discount',
200
- id: 'baz',
201
- },
202
- },
203
- },
204
- ],
205
- })
173
+ expect(response.status).toBe(200)
206
174
 
207
- expect(response.status).toBe(200)
175
+ expect(response.body).toEqual({
176
+ active: false,
177
+ channel: {
178
+ id: 'bar',
179
+ typeId: 'channel',
180
+ },
181
+ country: 'DE',
182
+ createdAt: expect.anything(),
183
+ id: id,
184
+ lastModifiedAt: expect.anything(),
185
+ sku: 'foo',
186
+ value: {
187
+ centAmount: 100,
188
+ currencyCode: 'EUR',
189
+ fractionDigits: 2,
190
+ type: 'centPrecision',
191
+ },
192
+ version: 2,
193
+ })
194
+ })
208
195
 
209
- expect(response.body).toEqual({
210
- active: true,
211
- channel: {
212
- id: 'bar',
213
- typeId: 'channel',
214
- },
215
- country: 'DE',
216
- createdAt: expect.anything(),
196
+ test('setDiscounted', async () => {
197
+ const response = await supertest(ctMock.app)
198
+ .post('/dummy/standalone-prices/' + id)
199
+ .send({
200
+ version: 1,
201
+ actions: [
202
+ {
203
+ action: 'setDiscountedPrice',
217
204
  discounted: {
218
- discount: {
219
- id: 'baz',
220
- typeId: 'product-discount',
221
- },
222
- value: {
223
- centAmount: 80,
224
- currencyCode: 'EUR',
225
- fractionDigits: 2,
226
- type: 'centPrecision',
227
- },
228
- },
229
- id: id,
230
- lastModifiedAt: expect.anything(),
231
- sku: 'foo',
232
- value: {
233
- centAmount: 100,
205
+ value: {
206
+ centAmount: 80,
234
207
  currencyCode: 'EUR',
235
- fractionDigits: 2,
236
- type: 'centPrecision',
208
+ },
209
+ discount: {
210
+ typeId: 'product-discount',
211
+ id: 'baz',
212
+ },
237
213
  },
238
- version: 2,
239
- })
214
+ },
215
+ ],
216
+ })
240
217
 
241
- const response2 = await supertest(ctMock.app)
242
- .post('/dummy/standalone-prices/' + id)
243
- .send({
244
- version: 2,
245
- actions: [
246
- {
247
- action: 'setDiscountedPrice',
248
- discounted: null,
249
- },
250
- ],
251
- })
218
+ expect(response.status).toBe(200)
252
219
 
253
- expect(response2.status).toBe(200)
220
+ expect(response.body).toEqual({
221
+ active: true,
222
+ channel: {
223
+ id: 'bar',
224
+ typeId: 'channel',
225
+ },
226
+ country: 'DE',
227
+ createdAt: expect.anything(),
228
+ discounted: {
229
+ discount: {
230
+ id: 'baz',
231
+ typeId: 'product-discount',
232
+ },
233
+ value: {
234
+ centAmount: 80,
235
+ currencyCode: 'EUR',
236
+ fractionDigits: 2,
237
+ type: 'centPrecision',
238
+ },
239
+ },
240
+ id: id,
241
+ lastModifiedAt: expect.anything(),
242
+ sku: 'foo',
243
+ value: {
244
+ centAmount: 100,
245
+ currencyCode: 'EUR',
246
+ fractionDigits: 2,
247
+ type: 'centPrecision',
248
+ },
249
+ version: 2,
250
+ })
254
251
 
255
- expect(response2.body).toEqual({
256
- active: true,
257
- channel: {
258
- id: 'bar',
259
- typeId: 'channel',
260
- },
261
- country: 'DE',
262
- createdAt: expect.anything(),
263
- id: id,
264
- lastModifiedAt: expect.anything(),
265
- sku: 'foo',
266
- value: {
267
- centAmount: 100,
268
- currencyCode: 'EUR',
269
- fractionDigits: 2,
270
- type: 'centPrecision',
271
- },
272
- version: 3,
273
- })
252
+ const response2 = await supertest(ctMock.app)
253
+ .post('/dummy/standalone-prices/' + id)
254
+ .send({
255
+ version: 2,
256
+ actions: [
257
+ {
258
+ action: 'setDiscountedPrice',
259
+ discounted: null,
260
+ },
261
+ ],
262
+ })
263
+
264
+ expect(response2.status).toBe(200)
265
+
266
+ expect(response2.body).toEqual({
267
+ active: true,
268
+ channel: {
269
+ id: 'bar',
270
+ typeId: 'channel',
271
+ },
272
+ country: 'DE',
273
+ createdAt: expect.anything(),
274
+ id: id,
275
+ lastModifiedAt: expect.anything(),
276
+ sku: 'foo',
277
+ value: {
278
+ centAmount: 100,
279
+ currencyCode: 'EUR',
280
+ fractionDigits: 2,
281
+ type: 'centPrecision',
282
+ },
283
+ version: 3,
274
284
  })
275
- })
285
+ })
286
+ })
@@ -1,5 +1,6 @@
1
- import { StateDraft } from '@commercetools/platform-sdk'
1
+ import { type StateDraft } from '@commercetools/platform-sdk'
2
2
  import supertest from 'supertest'
3
+ import { describe, expect, test } from 'vitest'
3
4
  import { CommercetoolsMock } from '../index'
4
5
 
5
6
  const ctMock = new CommercetoolsMock()
@@ -1,4 +1,6 @@
1
+ import type { Store } from '@commercetools/platform-sdk'
1
2
  import supertest from 'supertest'
3
+ import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest'
2
4
  import { CommercetoolsMock } from '../index'
3
5
 
4
6
  const ctMock = new CommercetoolsMock()
@@ -23,6 +25,7 @@ describe('Store', () => {
23
25
  createdAt: '',
24
26
  lastModifiedAt: '',
25
27
  key: 'STOREKEY',
28
+ countries: [],
26
29
  languages: [],
27
30
  distributionChannels: [],
28
31
  supplyChannels: [],
@@ -40,11 +43,12 @@ describe('Store', () => {
40
43
  id: 'fake-store',
41
44
  key: 'STOREKEY',
42
45
  lastModifiedAt: '',
46
+ countries: [],
43
47
  languages: [],
44
48
  distributionChannels: [],
45
49
  supplyChannels: [],
46
50
  productSelections: [],
47
- })
51
+ } as Store)
48
52
  })
49
53
 
50
54
  test('Get store by 404 when not found by key', async () => {
@@ -54,6 +58,7 @@ describe('Store', () => {
54
58
  createdAt: '',
55
59
  lastModifiedAt: '',
56
60
  key: 'STOREKEY',
61
+ countries: [],
57
62
  languages: [],
58
63
  distributionChannels: [],
59
64
  supplyChannels: [],
@@ -1,5 +1,6 @@
1
- import { TaxCategoryDraft } from '@commercetools/platform-sdk'
1
+ import type { TaxCategoryDraft } from '@commercetools/platform-sdk'
2
2
  import supertest from 'supertest'
3
+ import { afterEach, describe, expect, test } from 'vitest'
3
4
  import { CommercetoolsMock } from '../index'
4
5
 
5
6
  const ctMock = new CommercetoolsMock()
@@ -1,4 +1,4 @@
1
- import {
1
+ import type {
2
2
  BaseResource,
3
3
  Project,
4
4
  QueryParam,
@@ -1,4 +1,7 @@
1
- import {
1
+ import type {
2
+ AssociateRole,
3
+ AttributeGroup,
4
+ BusinessUnit,
2
5
  Cart,
3
6
  CartDiscount,
4
7
  Category,
@@ -65,6 +68,9 @@ export class InMemoryStorage extends AbstractStorage {
65
68
  let projectStorage = this.resources[projectKey]
66
69
  if (!projectStorage) {
67
70
  projectStorage = this.resources[projectKey] = {
71
+ 'associate-role': new Map<string, AssociateRole>(),
72
+ 'attribute-group': new Map<string, AttributeGroup>(),
73
+ 'business-unit': new Map<string, BusinessUnit>(),
68
74
  cart: new Map<string, Cart>(),
69
75
  'cart-discount': new Map<string, CartDiscount>(),
70
76
  category: new Map<string, Category>(),
package/src/types.ts CHANGED
@@ -1,4 +1,4 @@
1
- import * as ctp from '@commercetools/platform-sdk'
1
+ import type * as ctp from '@commercetools/platform-sdk'
2
2
  import { RepositoryMap } from './repositories'
3
3
  import AbstractService from './services/abstract'
4
4
 
@@ -21,6 +21,9 @@ export type Services = Partial<{
21
21
  export type ResourceType = keyof ResourceMap & keyof RepositoryMap
22
22
 
23
23
  export type ResourceMap = {
24
+ 'attribute-group': ctp.AttributeGroup
25
+ 'associate-role': ctp.AssociateRole
26
+ 'business-unit': ctp.BusinessUnit
24
27
  'cart-discount': ctp.CartDiscount
25
28
  cart: ctp.Cart
26
29
  category: ctp.Category
@@ -58,6 +61,9 @@ export type ResourceMap = {
58
61
  }
59
62
 
60
63
  export type PagedQueryResponseMap = {
64
+ 'attribute-group': ctp.AttributeGroupPagedQueryResponse
65
+ 'associate-role': ctp.AssociateRolePagedQueryResponse
66
+ 'business-unit': ctp.BusinessUnitPagedQueryResponse
61
67
  'cart-discount': ctp.CartDiscountPagedQueryResponse
62
68
  cart: ctp.CartPagedQueryResponse
63
69
  category: ctp.CategoryPagedQueryResponse