@labdigital/commercetools-mock 0.5.13 → 0.5.16
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/README.md +6 -2
- package/dist/commercetools-mock.cjs.development.js +3087 -1642
- package/dist/commercetools-mock.cjs.development.js.map +1 -1
- package/dist/commercetools-mock.cjs.production.min.js +1 -1
- package/dist/commercetools-mock.cjs.production.min.js.map +1 -1
- package/dist/commercetools-mock.esm.js +3087 -1642
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/ctMock.d.ts +1 -0
- package/dist/lib/masking.d.ts +1 -0
- package/dist/repositories/abstract.d.ts +9 -7
- package/dist/repositories/cart-discount.d.ts +9 -0
- package/dist/repositories/cart.d.ts +16 -3
- package/dist/repositories/category.d.ts +18 -0
- package/dist/repositories/channel.d.ts +6 -0
- package/dist/repositories/custom-object.d.ts +2 -2
- package/dist/repositories/customer-group.d.ts +11 -0
- package/dist/repositories/customer.d.ts +2 -2
- package/dist/repositories/discount-code.d.ts +8 -0
- package/dist/repositories/errors.d.ts +2 -2
- package/dist/repositories/extension.d.ts +8 -0
- package/dist/repositories/inventory-entry.d.ts +2 -2
- package/dist/repositories/order.d.ts +2 -2
- package/dist/repositories/payment.d.ts +4 -3
- package/dist/repositories/product-projection.d.ts +2 -2
- package/dist/repositories/product-type.d.ts +5 -4
- package/dist/repositories/product.d.ts +2 -2
- package/dist/repositories/project.d.ts +8 -0
- package/dist/repositories/shipping-method.d.ts +7 -5
- package/dist/repositories/shopping-list.d.ts +2 -2
- package/dist/repositories/state.d.ts +5 -4
- package/dist/repositories/store.d.ts +6 -3
- package/dist/repositories/subscription.d.ts +6 -0
- package/dist/repositories/tax-category.d.ts +6 -5
- package/dist/repositories/type.d.ts +5 -3
- package/dist/repositories/zone.d.ts +8 -0
- package/dist/services/abstract.d.ts +4 -3
- package/dist/services/cart-discount.d.ts +9 -0
- package/dist/services/category.d.ts +9 -0
- package/dist/services/channel.d.ts +9 -0
- package/dist/services/customer-group.d.ts +9 -0
- package/dist/services/discount-code.d.ts +9 -0
- package/dist/services/extension.d.ts +9 -0
- package/dist/services/my-cart.d.ts +11 -0
- package/dist/services/project.d.ts +11 -0
- package/dist/services/subscription.d.ts +9 -0
- package/dist/services/zone.d.ts +9 -0
- package/dist/storage.d.ts +10 -1
- package/dist/types.d.ts +2 -1
- package/package.json +20 -20
- package/src/ctMock.ts +44 -17
- package/src/lib/masking.ts +22 -0
- package/src/oauth/server.ts +3 -1
- package/src/repositories/abstract.ts +39 -33
- package/src/repositories/cart-discount.ts +140 -0
- package/src/repositories/cart.ts +247 -3
- package/src/repositories/category.ts +140 -0
- package/src/repositories/channel.ts +23 -0
- package/src/repositories/custom-object.ts +2 -2
- package/src/repositories/customer-group.ts +42 -0
- package/src/repositories/customer.ts +2 -2
- package/src/repositories/discount-code.ts +143 -0
- package/src/repositories/errors.ts +7 -2
- package/src/repositories/extension.ts +65 -0
- package/src/repositories/inventory-entry.ts +2 -2
- package/src/repositories/order.ts +2 -2
- package/src/repositories/payment.ts +10 -6
- package/src/repositories/product-projection.ts +4 -3
- package/src/repositories/product-type.ts +57 -4
- package/src/repositories/product.ts +4 -2
- package/src/repositories/project.ts +156 -0
- package/src/repositories/shipping-method.ts +149 -13
- package/src/repositories/shopping-list.ts +2 -2
- package/src/repositories/state.ts +48 -4
- package/src/repositories/store.ts +69 -4
- package/src/repositories/subscription.ts +50 -0
- package/src/repositories/tax-category.ts +80 -6
- package/src/repositories/type.ts +133 -3
- package/src/repositories/zone.ts +77 -0
- package/src/server.ts +6 -1
- package/src/services/abstract.ts +16 -15
- package/src/services/cart-discount.ts +17 -0
- package/src/services/cart.test.ts +314 -3
- package/src/services/category.test.ts +37 -0
- package/src/services/category.ts +17 -0
- package/src/services/channel.ts +17 -0
- package/src/services/custom-object.test.ts +3 -3
- package/src/services/customer-group.ts +17 -0
- package/src/services/discount-code.ts +17 -0
- package/src/services/extension.ts +17 -0
- package/src/services/inventory-entry.test.ts +3 -3
- package/src/services/my-cart.test.ts +93 -0
- package/src/services/my-cart.ts +44 -0
- package/src/services/my-payment.test.ts +2 -2
- package/src/services/order.test.ts +4 -4
- package/src/services/payment.test.ts +2 -2
- package/src/services/product-projection.test.ts +44 -6
- package/src/services/product-type.test.ts +2 -2
- package/src/services/product.test.ts +6 -2
- package/src/services/project.ts +42 -0
- package/src/services/shipping-method.test.ts +3 -3
- package/src/services/state.test.ts +2 -2
- package/src/services/subscription.ts +17 -0
- package/src/services/tax-category.test.ts +3 -3
- package/src/services/zone.ts +17 -0
- package/src/storage.ts +77 -3
- package/src/types.ts +2 -1
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Address,
|
|
3
|
+
Cart,
|
|
4
|
+
CentPrecisionMoney,
|
|
5
|
+
ProductDraft,
|
|
6
|
+
} from '@commercetools/platform-sdk'
|
|
2
7
|
import supertest from 'supertest'
|
|
3
8
|
import { CommercetoolsMock } from '../index'
|
|
9
|
+
import assert from 'assert'
|
|
4
10
|
|
|
5
11
|
describe('Carts Query', () => {
|
|
6
12
|
const ctMock = new CommercetoolsMock()
|
|
@@ -32,7 +38,7 @@ describe('Carts Query', () => {
|
|
|
32
38
|
},
|
|
33
39
|
],
|
|
34
40
|
})
|
|
35
|
-
expect(response.status).toBe(
|
|
41
|
+
expect(response.status).toBe(201)
|
|
36
42
|
|
|
37
43
|
response = await supertest(ctMock.app)
|
|
38
44
|
.post('/dummy/carts')
|
|
@@ -48,7 +54,7 @@ describe('Carts Query', () => {
|
|
|
48
54
|
},
|
|
49
55
|
},
|
|
50
56
|
})
|
|
51
|
-
expect(response.status).toBe(
|
|
57
|
+
expect(response.status).toBe(201)
|
|
52
58
|
})
|
|
53
59
|
|
|
54
60
|
test('no filter', async () => {
|
|
@@ -69,3 +75,308 @@ describe('Carts Query', () => {
|
|
|
69
75
|
expect(myCart.custom?.type.obj?.description?.en).toBe('Test Type')
|
|
70
76
|
})
|
|
71
77
|
})
|
|
78
|
+
|
|
79
|
+
describe('Order Update Actions', () => {
|
|
80
|
+
const ctMock = new CommercetoolsMock()
|
|
81
|
+
let cart: Cart | undefined
|
|
82
|
+
const productDraft: ProductDraft = {
|
|
83
|
+
name: {
|
|
84
|
+
'nl-NL': 'test product',
|
|
85
|
+
},
|
|
86
|
+
productType: {
|
|
87
|
+
typeId: 'product-type',
|
|
88
|
+
id: 'some-uuid',
|
|
89
|
+
},
|
|
90
|
+
masterVariant: {
|
|
91
|
+
sku: '1337',
|
|
92
|
+
prices: [
|
|
93
|
+
{
|
|
94
|
+
value: {
|
|
95
|
+
type: 'centPrecision',
|
|
96
|
+
currencyCode: 'EUR',
|
|
97
|
+
centAmount: 14900,
|
|
98
|
+
fractionDigits: 2,
|
|
99
|
+
} as CentPrecisionMoney,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
|
|
103
|
+
attributes: [
|
|
104
|
+
{
|
|
105
|
+
name: 'test',
|
|
106
|
+
value: 'test',
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
variants: [
|
|
111
|
+
{
|
|
112
|
+
sku: '1338',
|
|
113
|
+
prices: [
|
|
114
|
+
{
|
|
115
|
+
value: {
|
|
116
|
+
type: 'centPrecision',
|
|
117
|
+
currencyCode: 'EUR',
|
|
118
|
+
centAmount: 14900,
|
|
119
|
+
fractionDigits: 2,
|
|
120
|
+
} as CentPrecisionMoney,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
attributes: [
|
|
124
|
+
{
|
|
125
|
+
name: 'test2',
|
|
126
|
+
value: 'test2',
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
slug: {
|
|
132
|
+
'nl-NL': 'test-product',
|
|
133
|
+
},
|
|
134
|
+
publish: true,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
beforeEach(async () => {
|
|
138
|
+
let response = await supertest(ctMock.app)
|
|
139
|
+
.post('/dummy/carts')
|
|
140
|
+
.send({
|
|
141
|
+
currency: 'EUR',
|
|
142
|
+
})
|
|
143
|
+
expect(response.status).toBe(201)
|
|
144
|
+
cart = response.body
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
afterEach(() => {
|
|
148
|
+
ctMock.clear()
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('no update', async () => {
|
|
152
|
+
assert(cart, 'cart not created')
|
|
153
|
+
|
|
154
|
+
const response = await supertest(ctMock.app)
|
|
155
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
156
|
+
.send({
|
|
157
|
+
version: 1,
|
|
158
|
+
actions: [{ action: 'setLocale', locale: 'nl-NL' }],
|
|
159
|
+
})
|
|
160
|
+
expect(response.status).toBe(200)
|
|
161
|
+
expect(response.body.version).toBe(2)
|
|
162
|
+
expect(response.body.locale).toBe('nl-NL')
|
|
163
|
+
|
|
164
|
+
const responseAgain = await supertest(ctMock.app)
|
|
165
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
166
|
+
.send({
|
|
167
|
+
version: 2,
|
|
168
|
+
actions: [{ action: 'setLocale', locale: 'nl-NL' }],
|
|
169
|
+
})
|
|
170
|
+
expect(responseAgain.status).toBe(200)
|
|
171
|
+
expect(responseAgain.body.version).toBe(2)
|
|
172
|
+
expect(responseAgain.body.locale).toBe('nl-NL')
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('addLineItem', async () => {
|
|
176
|
+
const product = await supertest(ctMock.app)
|
|
177
|
+
.post(`/dummy/products`)
|
|
178
|
+
.send(productDraft)
|
|
179
|
+
.then(x => x.body)
|
|
180
|
+
|
|
181
|
+
assert(cart, 'cart not created')
|
|
182
|
+
assert(product, 'product not created')
|
|
183
|
+
|
|
184
|
+
const response = await supertest(ctMock.app)
|
|
185
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
186
|
+
.send({
|
|
187
|
+
version: 1,
|
|
188
|
+
actions: [
|
|
189
|
+
{
|
|
190
|
+
action: 'addLineItem',
|
|
191
|
+
productId: product.id,
|
|
192
|
+
variantId: product.masterData.current.variants[0].id,
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
})
|
|
196
|
+
expect(response.status).toBe(200)
|
|
197
|
+
expect(response.body.version).toBe(2)
|
|
198
|
+
expect(response.body.lineItems).toHaveLength(1)
|
|
199
|
+
expect(response.body.totalPrice.centAmount).toEqual(14900)
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test('addLineItem by SKU', async () => {
|
|
203
|
+
const product = await supertest(ctMock.app)
|
|
204
|
+
.post(`/dummy/products`)
|
|
205
|
+
.send(productDraft)
|
|
206
|
+
.then(x => x.body)
|
|
207
|
+
|
|
208
|
+
assert(cart, 'cart not created')
|
|
209
|
+
assert(product, 'product not created')
|
|
210
|
+
|
|
211
|
+
const response = await supertest(ctMock.app)
|
|
212
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
213
|
+
.send({
|
|
214
|
+
version: 1,
|
|
215
|
+
actions: [{ action: 'addLineItem', sku: '1337', quantity: 2 }],
|
|
216
|
+
})
|
|
217
|
+
expect(response.status).toBe(200)
|
|
218
|
+
expect(response.body.version).toBe(2)
|
|
219
|
+
expect(response.body.lineItems).toHaveLength(1)
|
|
220
|
+
expect(response.body.totalPrice.centAmount).toEqual(29800)
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
test('addLineItem unknown product', async () => {
|
|
224
|
+
assert(cart, 'cart not created')
|
|
225
|
+
|
|
226
|
+
const response = await supertest(ctMock.app)
|
|
227
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
228
|
+
.send({
|
|
229
|
+
version: 1,
|
|
230
|
+
actions: [{ action: 'addLineItem', productId: '123', variantId: 1 }],
|
|
231
|
+
})
|
|
232
|
+
expect(response.status).toBe(400)
|
|
233
|
+
expect(response.body.message).toBe("A product with ID '123' not found.")
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('removeLineItem', async () => {
|
|
237
|
+
const product = await supertest(ctMock.app)
|
|
238
|
+
.post(`/dummy/products`)
|
|
239
|
+
.send(productDraft)
|
|
240
|
+
.then(x => x.body)
|
|
241
|
+
|
|
242
|
+
assert(cart, 'cart not created')
|
|
243
|
+
assert(product, 'product not created')
|
|
244
|
+
|
|
245
|
+
const updatedCart = await supertest(ctMock.app)
|
|
246
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
247
|
+
.send({
|
|
248
|
+
version: 1,
|
|
249
|
+
actions: [
|
|
250
|
+
{
|
|
251
|
+
action: 'addLineItem',
|
|
252
|
+
productId: product.id,
|
|
253
|
+
variantId: product.masterData.current.variants[0].id,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
})
|
|
257
|
+
const lineItem = updatedCart.body.lineItems[0]
|
|
258
|
+
assert(lineItem, 'lineItem not created')
|
|
259
|
+
|
|
260
|
+
expect(updatedCart.body.lineItems).toHaveLength(1)
|
|
261
|
+
|
|
262
|
+
const response = await supertest(ctMock.app)
|
|
263
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
264
|
+
.send({
|
|
265
|
+
version: updatedCart.body.version,
|
|
266
|
+
actions: [{ action: 'removeLineItem', lineItemId: lineItem.id }],
|
|
267
|
+
})
|
|
268
|
+
expect(response.status).toBe(200)
|
|
269
|
+
expect(response.body.version).toBe(3)
|
|
270
|
+
expect(response.body.lineItems).toHaveLength(0)
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
test('removeLineItem decrease quantity', async () => {
|
|
274
|
+
const product = await supertest(ctMock.app)
|
|
275
|
+
.post(`/dummy/products`)
|
|
276
|
+
.send(productDraft)
|
|
277
|
+
.then(x => x.body)
|
|
278
|
+
|
|
279
|
+
assert(cart, 'cart not created')
|
|
280
|
+
assert(product, 'product not created')
|
|
281
|
+
|
|
282
|
+
const updatedCart = await supertest(ctMock.app)
|
|
283
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
284
|
+
.send({
|
|
285
|
+
version: 1,
|
|
286
|
+
actions: [
|
|
287
|
+
{
|
|
288
|
+
action: 'addLineItem',
|
|
289
|
+
productId: product.id,
|
|
290
|
+
variantId: product.masterData.current.variants[0].id,
|
|
291
|
+
quantity: 2,
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
})
|
|
295
|
+
const lineItem = updatedCart.body.lineItems[0]
|
|
296
|
+
assert(lineItem, 'lineItem not created')
|
|
297
|
+
|
|
298
|
+
expect(updatedCart.body.lineItems).toHaveLength(1)
|
|
299
|
+
expect(updatedCart.body.lineItems[0].quantity).toBe(2)
|
|
300
|
+
|
|
301
|
+
const response = await supertest(ctMock.app)
|
|
302
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
303
|
+
.send({
|
|
304
|
+
version: updatedCart.body.version,
|
|
305
|
+
actions: [
|
|
306
|
+
{ action: 'removeLineItem', lineItemId: lineItem.id, quantity: 1 },
|
|
307
|
+
],
|
|
308
|
+
})
|
|
309
|
+
expect(response.status).toBe(200)
|
|
310
|
+
expect(response.body.version).toBe(3)
|
|
311
|
+
expect(response.body.lineItems).toHaveLength(1)
|
|
312
|
+
expect(response.body.lineItems[0].quantity).toBe(1)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test('setBillingAddress', async () => {
|
|
316
|
+
assert(cart, 'cart not created')
|
|
317
|
+
|
|
318
|
+
const address: Address = {
|
|
319
|
+
streetName: 'Street name',
|
|
320
|
+
city: 'Utrecht',
|
|
321
|
+
country: 'NL',
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const response = await supertest(ctMock.app)
|
|
325
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
326
|
+
.send({
|
|
327
|
+
version: 1,
|
|
328
|
+
actions: [{ action: 'setBillingAddress', address }],
|
|
329
|
+
})
|
|
330
|
+
expect(response.status).toBe(200)
|
|
331
|
+
expect(response.body.version).toBe(2)
|
|
332
|
+
expect(response.body.billingAddress).toEqual(address)
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
test('setCountry', async () => {
|
|
336
|
+
assert(cart, 'cart not created')
|
|
337
|
+
|
|
338
|
+
const response = await supertest(ctMock.app)
|
|
339
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
340
|
+
.send({
|
|
341
|
+
version: 1,
|
|
342
|
+
actions: [{ action: 'setCountry', country: 'NL' }],
|
|
343
|
+
})
|
|
344
|
+
expect(response.status).toBe(200)
|
|
345
|
+
expect(response.body.version).toBe(2)
|
|
346
|
+
expect(response.body.country).toBe('NL')
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
test('setCustomerEmail', async () => {
|
|
350
|
+
assert(cart, 'cart not created')
|
|
351
|
+
|
|
352
|
+
const response = await supertest(ctMock.app)
|
|
353
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
354
|
+
.send({
|
|
355
|
+
version: 1,
|
|
356
|
+
actions: [{ action: 'setCustomerEmail', email: 'john@doe.com' }],
|
|
357
|
+
})
|
|
358
|
+
expect(response.status).toBe(200)
|
|
359
|
+
expect(response.body.version).toBe(2)
|
|
360
|
+
expect(response.body.customerEmail).toBe('john@doe.com')
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
test('setShippingAddress', async () => {
|
|
364
|
+
assert(cart, 'cart not created')
|
|
365
|
+
|
|
366
|
+
const address: Address = {
|
|
367
|
+
streetName: 'Street name',
|
|
368
|
+
city: 'Utrecht',
|
|
369
|
+
country: 'NL',
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const response = await supertest(ctMock.app)
|
|
373
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
374
|
+
.send({
|
|
375
|
+
version: 1,
|
|
376
|
+
actions: [{ action: 'setShippingAddress', address }],
|
|
377
|
+
})
|
|
378
|
+
expect(response.status).toBe(200)
|
|
379
|
+
expect(response.body.version).toBe(2)
|
|
380
|
+
expect(response.body.shippingAddress).toEqual(address)
|
|
381
|
+
})
|
|
382
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Category } from '@commercetools/platform-sdk'
|
|
2
|
+
import supertest from 'supertest'
|
|
3
|
+
import { CommercetoolsMock } from '../index'
|
|
4
|
+
|
|
5
|
+
describe('Categories Query', () => {
|
|
6
|
+
const ctMock = new CommercetoolsMock()
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
let response
|
|
10
|
+
response = await supertest(ctMock.app)
|
|
11
|
+
.post('/dummy/categories')
|
|
12
|
+
.send({
|
|
13
|
+
name: {
|
|
14
|
+
en: 'Top hat',
|
|
15
|
+
},
|
|
16
|
+
slug: {
|
|
17
|
+
en: 'top-hat',
|
|
18
|
+
},
|
|
19
|
+
orderHint: '0.1',
|
|
20
|
+
})
|
|
21
|
+
expect(response.status).toBe(201)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('no filter', async () => {
|
|
25
|
+
const response = await supertest(ctMock.app)
|
|
26
|
+
.get('/dummy/categories')
|
|
27
|
+
.query({})
|
|
28
|
+
.send()
|
|
29
|
+
|
|
30
|
+
expect(response.status).toBe(200)
|
|
31
|
+
expect(response.body.count).toBe(1)
|
|
32
|
+
|
|
33
|
+
const category = response.body.results[0] as Category
|
|
34
|
+
|
|
35
|
+
expect(category.name.en).toBe('Top hat')
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Router } from 'express'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { CategoryRepository } from '../repositories/category'
|
|
5
|
+
|
|
6
|
+
export class CategoryServices extends AbstractService {
|
|
7
|
+
public repository: CategoryRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new CategoryRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'categories'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Router } from 'express'
|
|
3
|
+
import { ChannelRepository } from '../repositories/channel'
|
|
4
|
+
import { AbstractStorage } from '../storage'
|
|
5
|
+
|
|
6
|
+
export class ChannelService extends AbstractService {
|
|
7
|
+
public repository: ChannelRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new ChannelRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'channels'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -15,7 +15,7 @@ describe('CustomObject create', () => {
|
|
|
15
15
|
value: 'my-value',
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
expect(response.status).toBe(
|
|
18
|
+
expect(response.status).toBe(201)
|
|
19
19
|
const customObject = response.body
|
|
20
20
|
expect(customObject.container).toBe('my-container')
|
|
21
21
|
expect(customObject.key).toBe('my-key')
|
|
@@ -36,7 +36,7 @@ describe('CustomObject retrieve', () => {
|
|
|
36
36
|
value: 'my-value',
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
expect(response.status).toBe(
|
|
39
|
+
expect(response.status).toBe(201)
|
|
40
40
|
customObject = response.body
|
|
41
41
|
expect(customObject.container).toBe('my-container')
|
|
42
42
|
expect(customObject.key).toBe('my-key')
|
|
@@ -67,7 +67,7 @@ describe('CustomObject retrieve', () => {
|
|
|
67
67
|
value: 'my-value',
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
expect(response.status).toBe(
|
|
70
|
+
expect(response.status).toBe(201)
|
|
71
71
|
})
|
|
72
72
|
|
|
73
73
|
test('New with version (errors)', async () => {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Router } from 'express'
|
|
3
|
+
import { CustomerGroupRepository } from '../repositories/customer-group'
|
|
4
|
+
import { AbstractStorage } from '../storage'
|
|
5
|
+
|
|
6
|
+
export class CustomerGroupService extends AbstractService {
|
|
7
|
+
public repository: CustomerGroupRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new CustomerGroupRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'customer-groups'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express'
|
|
2
|
+
import AbstractService from './abstract'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { DiscountCodeRepository } from '../repositories/discount-code'
|
|
5
|
+
|
|
6
|
+
export class DiscountCodeService extends AbstractService {
|
|
7
|
+
public repository: DiscountCodeRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new DiscountCodeRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'discount-codes'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Router } from 'express'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { ExtensionRepository } from '../repositories/extension'
|
|
5
|
+
|
|
6
|
+
export class ExtensionServices extends AbstractService {
|
|
7
|
+
public repository: ExtensionRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new ExtensionRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'extensions'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -14,7 +14,7 @@ describe('Inventory Entry Query', () => {
|
|
|
14
14
|
sku: '1337',
|
|
15
15
|
quantityOnStock: 100,
|
|
16
16
|
})
|
|
17
|
-
expect(response.status).toBe(
|
|
17
|
+
expect(response.status).toBe(201)
|
|
18
18
|
inventoryEntry = response.body
|
|
19
19
|
})
|
|
20
20
|
|
|
@@ -65,7 +65,7 @@ describe('Inventory Entry Update Actions', () => {
|
|
|
65
65
|
sku: '1337',
|
|
66
66
|
quantityOnStock: 100,
|
|
67
67
|
})
|
|
68
|
-
expect(response.status).toBe(
|
|
68
|
+
expect(response.status).toBe(201)
|
|
69
69
|
inventoryEntry = response.body
|
|
70
70
|
|
|
71
71
|
response = await supertest(ctMock.app)
|
|
@@ -77,7 +77,7 @@ describe('Inventory Entry Update Actions', () => {
|
|
|
77
77
|
},
|
|
78
78
|
resourceTypeIds: ['inventory-entry'],
|
|
79
79
|
})
|
|
80
|
-
expect(response.status).toBe(
|
|
80
|
+
expect(response.status).toBe(201)
|
|
81
81
|
customType = response.body
|
|
82
82
|
})
|
|
83
83
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { MyCartDraft } from '@commercetools/platform-sdk'
|
|
2
|
+
import supertest from 'supertest'
|
|
3
|
+
import { CommercetoolsMock } from '../index'
|
|
4
|
+
|
|
5
|
+
const ctMock = new CommercetoolsMock()
|
|
6
|
+
|
|
7
|
+
describe('MyCart', () => {
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
const response = await supertest(ctMock.app)
|
|
10
|
+
.post('/dummy/types')
|
|
11
|
+
.send({
|
|
12
|
+
key: 'custom-payment',
|
|
13
|
+
name: {
|
|
14
|
+
'nl-NL': 'custom-payment',
|
|
15
|
+
},
|
|
16
|
+
resourceTypeIds: ['payment'],
|
|
17
|
+
})
|
|
18
|
+
expect(response.status).toBe(201)
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
ctMock.clear()
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
test('Create my cart', async () => {
|
|
26
|
+
const draft: MyCartDraft = {
|
|
27
|
+
currency: 'EUR',
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const response = await supertest(ctMock.app)
|
|
31
|
+
.post('/dummy/me/carts')
|
|
32
|
+
.send(draft)
|
|
33
|
+
|
|
34
|
+
expect(response.status).toBe(201)
|
|
35
|
+
expect(response.body).toEqual({
|
|
36
|
+
id: expect.anything(),
|
|
37
|
+
createdAt: expect.anything(),
|
|
38
|
+
lastModifiedAt: expect.anything(),
|
|
39
|
+
version: 1,
|
|
40
|
+
cartState: 'Active',
|
|
41
|
+
lineItems: [],
|
|
42
|
+
customLineItems: [],
|
|
43
|
+
totalPrice: {
|
|
44
|
+
type: 'centPrecision',
|
|
45
|
+
centAmount: 0,
|
|
46
|
+
currencyCode: 'EUR',
|
|
47
|
+
fractionDigits: 0,
|
|
48
|
+
},
|
|
49
|
+
taxMode: 'Platform',
|
|
50
|
+
taxRoundingMode: 'HalfEven',
|
|
51
|
+
taxCalculationMode: 'LineItemLevel',
|
|
52
|
+
|
|
53
|
+
refusedGifts: [],
|
|
54
|
+
origin: 'Customer',
|
|
55
|
+
})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('Get my cart by ID', async () => {
|
|
59
|
+
const draft: MyCartDraft = {
|
|
60
|
+
currency: 'EUR',
|
|
61
|
+
}
|
|
62
|
+
const createResponse = await supertest(ctMock.app)
|
|
63
|
+
.post('/dummy/me/carts')
|
|
64
|
+
.send(draft)
|
|
65
|
+
|
|
66
|
+
const response = await supertest(ctMock.app).get(
|
|
67
|
+
`/dummy/me/carts/${createResponse.body.id}`
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
expect(response.status).toBe(200)
|
|
71
|
+
expect(response.body).toEqual(createResponse.body)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
test('Get my active cart', async () => {
|
|
75
|
+
const draft: MyCartDraft = {
|
|
76
|
+
currency: 'EUR',
|
|
77
|
+
}
|
|
78
|
+
const createResponse = await supertest(ctMock.app)
|
|
79
|
+
.post('/dummy/me/carts')
|
|
80
|
+
.send(draft)
|
|
81
|
+
|
|
82
|
+
const response = await supertest(ctMock.app).get(`/dummy/me/active-cart`)
|
|
83
|
+
|
|
84
|
+
expect(response.status).toBe(200)
|
|
85
|
+
expect(response.body).toEqual(createResponse.body)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('Get my active cart which doesnt exists', async () => {
|
|
89
|
+
const response = await supertest(ctMock.app).get(`/dummy/me/active-cart`)
|
|
90
|
+
|
|
91
|
+
expect(response.status).toBe(404)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Request, Response, Router } from 'express'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { CartRepository } from '../repositories/cart'
|
|
5
|
+
|
|
6
|
+
export class MyCartService extends AbstractService {
|
|
7
|
+
public repository: CartRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new CartRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'me'
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
registerRoutes(parent: Router) {
|
|
19
|
+
// Overwrite this function to be able to handle /me/active-cart path.
|
|
20
|
+
const basePath = this.getBasePath()
|
|
21
|
+
const router = Router({ mergeParams: true })
|
|
22
|
+
|
|
23
|
+
this.extraRoutes(router)
|
|
24
|
+
|
|
25
|
+
router.get('/active-cart', this.activeCart.bind(this))
|
|
26
|
+
router.get('/carts/', this.get.bind(this))
|
|
27
|
+
router.get('/carts/:id', this.getWithId.bind(this))
|
|
28
|
+
|
|
29
|
+
router.delete('/carts/:id', this.deletewithId.bind(this))
|
|
30
|
+
|
|
31
|
+
router.post('/carts/', this.post.bind(this))
|
|
32
|
+
router.post('/carts/:id', this.postWithId.bind(this))
|
|
33
|
+
|
|
34
|
+
parent.use(`/${basePath}`, router)
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
activeCart(request: Request, response: Response) {
|
|
38
|
+
const resource = this.repository.getActiveCart(request.params.projectKey)
|
|
39
|
+
if (!resource) {
|
|
40
|
+
return response.status(404).send('Not found')
|
|
41
|
+
}
|
|
42
|
+
return response.status(200).send(resource)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -15,7 +15,7 @@ describe('MyPayment', () => {
|
|
|
15
15
|
},
|
|
16
16
|
resourceTypeIds: ['payment'],
|
|
17
17
|
})
|
|
18
|
-
expect(response.status).toBe(
|
|
18
|
+
expect(response.status).toBe(201)
|
|
19
19
|
})
|
|
20
20
|
|
|
21
21
|
test('Create payment', async () => {
|
|
@@ -32,7 +32,7 @@ describe('MyPayment', () => {
|
|
|
32
32
|
.post('/dummy/me/payments')
|
|
33
33
|
.send(draft)
|
|
34
34
|
|
|
35
|
-
expect(response.status).toBe(
|
|
35
|
+
expect(response.status).toBe(201)
|
|
36
36
|
expect(response.body).toEqual({
|
|
37
37
|
id: expect.anything(),
|
|
38
38
|
createdAt: expect.anything(),
|