@labdigital/commercetools-mock 0.9.0 → 0.10.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.
Files changed (95) hide show
  1. package/README.md +8 -0
  2. package/dist/index.d.ts +18 -17
  3. package/dist/index.global.js +1751 -1664
  4. package/dist/index.global.js.map +1 -1
  5. package/dist/index.js +1773 -1684
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +1966 -1877
  8. package/dist/index.mjs.map +1 -1
  9. package/package.json +28 -20
  10. package/src/constants.ts +4 -2
  11. package/src/ctMock.ts +19 -84
  12. package/src/helpers.ts +9 -10
  13. package/src/index.test.ts +1 -1
  14. package/src/lib/haversine.ts +2 -2
  15. package/src/lib/masking.ts +3 -1
  16. package/src/lib/predicateParser.test.ts +16 -0
  17. package/src/lib/predicateParser.ts +94 -86
  18. package/src/lib/projectionSearchFilter.test.ts +28 -36
  19. package/src/lib/projectionSearchFilter.ts +86 -102
  20. package/src/oauth/store.ts +3 -3
  21. package/src/priceSelector.test.ts +18 -35
  22. package/src/priceSelector.ts +6 -9
  23. package/src/product-projection-search.ts +51 -57
  24. package/src/repositories/abstract.ts +85 -41
  25. package/src/repositories/cart-discount.ts +1 -1
  26. package/src/repositories/cart.ts +36 -31
  27. package/src/repositories/category.ts +17 -19
  28. package/src/repositories/channel.ts +1 -1
  29. package/src/repositories/custom-object.ts +35 -22
  30. package/src/repositories/customer-group.ts +1 -1
  31. package/src/repositories/customer.ts +39 -1
  32. package/src/repositories/discount-code.ts +1 -1
  33. package/src/repositories/errors.ts +9 -11
  34. package/src/repositories/extension.ts +13 -11
  35. package/src/repositories/helpers.ts +8 -13
  36. package/src/repositories/index.ts +59 -0
  37. package/src/repositories/inventory-entry.ts +1 -1
  38. package/src/repositories/order.ts +6 -6
  39. package/src/repositories/payment.ts +3 -3
  40. package/src/repositories/product-discount.ts +1 -1
  41. package/src/repositories/product-projection.ts +1 -0
  42. package/src/repositories/product-type.ts +29 -34
  43. package/src/repositories/product.ts +124 -80
  44. package/src/repositories/project.ts +10 -27
  45. package/src/repositories/shipping-method.ts +15 -17
  46. package/src/repositories/shopping-list.ts +2 -2
  47. package/src/repositories/state.ts +9 -9
  48. package/src/repositories/store.ts +2 -2
  49. package/src/repositories/subscription.ts +1 -1
  50. package/src/repositories/tax-category.ts +4 -4
  51. package/src/repositories/type.ts +12 -14
  52. package/src/repositories/zone.ts +5 -6
  53. package/src/server.ts +5 -0
  54. package/src/services/abstract.ts +44 -11
  55. package/src/services/cart-discount.ts +2 -3
  56. package/src/services/cart.test.ts +8 -10
  57. package/src/services/cart.ts +8 -11
  58. package/src/services/category.test.ts +1 -2
  59. package/src/services/category.ts +2 -3
  60. package/src/services/channel.ts +2 -3
  61. package/src/services/custom-object.test.ts +5 -5
  62. package/src/services/custom-object.ts +2 -3
  63. package/src/services/customer-group.ts +2 -3
  64. package/src/services/customer.test.ts +136 -0
  65. package/src/services/customer.ts +2 -3
  66. package/src/services/discount-code.ts +2 -3
  67. package/src/services/extension.ts +2 -3
  68. package/src/services/index.ts +74 -0
  69. package/src/services/inventory-entry.test.ts +8 -12
  70. package/src/services/inventory-entry.ts +2 -3
  71. package/src/services/my-cart.ts +3 -4
  72. package/src/services/my-customer.ts +2 -3
  73. package/src/services/my-order.ts +3 -4
  74. package/src/services/my-payment.ts +2 -3
  75. package/src/services/order.test.ts +4 -6
  76. package/src/services/order.ts +2 -3
  77. package/src/services/payment.ts +2 -3
  78. package/src/services/product-discount.ts +2 -3
  79. package/src/services/product-projection.test.ts +76 -8
  80. package/src/services/product-projection.ts +2 -3
  81. package/src/services/product-type.ts +2 -3
  82. package/src/services/product.test.ts +199 -89
  83. package/src/services/product.ts +2 -3
  84. package/src/services/project.ts +3 -3
  85. package/src/services/shipping-method.ts +2 -3
  86. package/src/services/shopping-list.ts +2 -3
  87. package/src/services/state.ts +2 -3
  88. package/src/services/store.test.ts +11 -2
  89. package/src/services/store.ts +2 -3
  90. package/src/services/subscription.ts +2 -3
  91. package/src/services/tax-category.ts +2 -3
  92. package/src/services/type.ts +2 -3
  93. package/src/services/zone.ts +2 -3
  94. package/src/storage.ts +23 -30
  95. package/src/types.ts +46 -6
@@ -14,7 +14,9 @@ export default abstract class AbstractService {
14
14
  this.registerRoutes(parent)
15
15
  }
16
16
 
17
- extraRoutes(router: Router) {}
17
+ extraRoutes(router: Router) {
18
+
19
+ }
18
20
 
19
21
  registerRoutes(parent: Router) {
20
22
  const basePath = this.getBasePath()
@@ -27,8 +29,8 @@ export default abstract class AbstractService {
27
29
  router.get('/key=:key', this.getWithKey.bind(this)) // same thing goes for the key routes
28
30
  router.get('/:id', this.getWithId.bind(this))
29
31
 
30
- router.delete('/key=:key', this.deletewithKey.bind(this))
31
- router.delete('/:id', this.deletewithId.bind(this))
32
+ router.delete('/key=:key', this.deleteWithKey.bind(this))
33
+ router.delete('/:id', this.deleteWithId.bind(this))
32
34
 
33
35
  router.post('/', this.post.bind(this))
34
36
  router.post('/key=:key', this.postWithKey.bind(this))
@@ -68,7 +70,7 @@ export default abstract class AbstractService {
68
70
  return response.status(200).send(result)
69
71
  }
70
72
 
71
- deletewithId(request: Request, response: Response) {
73
+ deleteWithId(request: Request, response: Response) {
72
74
  const result = this.repository.delete(
73
75
  getRepositoryContext(request),
74
76
  request.params['id'],
@@ -82,8 +84,26 @@ export default abstract class AbstractService {
82
84
  return response.status(200).send(result)
83
85
  }
84
86
 
85
- deletewithKey(request: Request, response: Response) {
86
- return response.status(500).send('Not implemented')
87
+ deleteWithKey(request: Request, response: Response) {
88
+ const resource = this.repository.getByKey(
89
+ getRepositoryContext(request),
90
+ request.params['key']
91
+ )
92
+ if (!resource) {
93
+ return response.status(404).send('Not found')
94
+ }
95
+
96
+ const result = this.repository.delete(
97
+ getRepositoryContext(request),
98
+ resource.id,
99
+ {
100
+ expand: this._parseParam(request.query.expand),
101
+ }
102
+ )
103
+ if (!result) {
104
+ return response.status(404).send('Not found')
105
+ }
106
+ return response.status(200).send(result)
87
107
  }
88
108
 
89
109
  post(request: Request, response: Response) {
@@ -106,13 +126,10 @@ export default abstract class AbstractService {
106
126
  return response.status(404).send('Not found')
107
127
  }
108
128
 
109
- if (resource.version !== updateRequest.version) {
110
- return response.status(409).send('Concurrent modification')
111
- }
112
-
113
129
  const updatedResource = this.repository.processUpdateActions(
114
130
  getRepositoryContext(request),
115
131
  resource,
132
+ updateRequest.version,
116
133
  updateRequest.actions
117
134
  )
118
135
 
@@ -121,7 +138,23 @@ export default abstract class AbstractService {
121
138
  }
122
139
 
123
140
  postWithKey(request: Request, response: Response) {
124
- return response.status(500).send('Not implemented')
141
+ const updateRequest: Update = request.body
142
+ const resource = this.repository.getByKey(
143
+ getRepositoryContext(request),
144
+ request.params['key']
145
+ )
146
+ if (!resource) {
147
+ return response.status(404).send('Not found')
148
+ }
149
+ const updatedResource = this.repository.processUpdateActions(
150
+ getRepositoryContext(request),
151
+ resource,
152
+ updateRequest.version,
153
+ updateRequest.actions
154
+ )
155
+
156
+ const result = this._expandWithId(request, updatedResource.id)
157
+ return response.status(200).send(result)
125
158
  }
126
159
 
127
160
  protected _expandWithId(request: Request, resourceId: string) {
@@ -1,14 +1,13 @@
1
1
  import { Router } from 'express'
2
2
  import AbstractService from './abstract'
3
- import { AbstractStorage } from '../storage'
4
3
  import { CartDiscountRepository } from '../repositories/cart-discount'
5
4
 
6
5
  export class CartDiscountService extends AbstractService {
7
6
  public repository: CartDiscountRepository
8
7
 
9
- constructor(parent: Router, storage: AbstractStorage) {
8
+ constructor(parent: Router, repository: CartDiscountRepository) {
10
9
  super(parent)
11
- this.repository = new CartDiscountRepository(storage)
10
+ this.repository = repository
12
11
  }
13
12
 
14
13
  getBasePath() {
@@ -81,11 +81,9 @@ describe('Cart Update Actions', () => {
81
81
  let cart: Cart | undefined
82
82
 
83
83
  const createCart = async (currency: string) => {
84
- let response = await supertest(ctMock.app)
85
- .post('/dummy/carts')
86
- .send({
87
- currency,
88
- })
84
+ const response = await supertest(ctMock.app).post('/dummy/carts').send({
85
+ currency,
86
+ })
89
87
  expect(response.status).toBe(201)
90
88
  cart = response.body
91
89
  }
@@ -189,7 +187,7 @@ describe('Cart Update Actions', () => {
189
187
  const product = await supertest(ctMock.app)
190
188
  .post(`/dummy/products`)
191
189
  .send(productDraft)
192
- .then(x => x.body)
190
+ .then((x) => x.body)
193
191
 
194
192
  assert(cart, 'cart not created')
195
193
  assert(product, 'product not created')
@@ -216,7 +214,7 @@ describe('Cart Update Actions', () => {
216
214
  const product = await supertest(ctMock.app)
217
215
  .post(`/dummy/products`)
218
216
  .send(productDraft)
219
- .then(x => x.body)
217
+ .then((x) => x.body)
220
218
 
221
219
  assert(cart, 'cart not created')
222
220
  assert(product, 'product not created')
@@ -242,7 +240,7 @@ describe('Cart Update Actions', () => {
242
240
  const product = await supertest(ctMock.app)
243
241
  .post(`/dummy/products`)
244
242
  .send(productDraft)
245
- .then(x => x.body)
243
+ .then((x) => x.body)
246
244
 
247
245
  assert(cart, 'cart not created')
248
246
  assert(product, 'product not created')
@@ -277,7 +275,7 @@ describe('Cart Update Actions', () => {
277
275
  const product = await supertest(ctMock.app)
278
276
  .post(`/dummy/products`)
279
277
  .send(productDraft)
280
- .then(x => x.body)
278
+ .then((x) => x.body)
281
279
 
282
280
  assert(cart, 'cart not created')
283
281
  assert(product, 'product not created')
@@ -314,7 +312,7 @@ describe('Cart Update Actions', () => {
314
312
  const product = await supertest(ctMock.app)
315
313
  .post(`/dummy/products`)
316
314
  .send(productDraft)
317
- .then(x => x.body)
315
+ .then((x) => x.body)
318
316
 
319
317
  assert(cart, 'cart not created')
320
318
  assert(product, 'product not created')
@@ -1,7 +1,6 @@
1
1
  import AbstractService from './abstract'
2
2
  import { Router } from 'express'
3
3
  import { CartRepository } from '../repositories/cart'
4
- import { AbstractStorage } from '../storage'
5
4
  import { Cart, CartDraft, Order } from '@commercetools/platform-sdk'
6
5
  import { OrderRepository } from '../repositories/order'
7
6
  import { getRepositoryContext } from '../repositories/helpers'
@@ -10,10 +9,10 @@ export class CartService extends AbstractService {
10
9
  public repository: CartRepository
11
10
  public orderRepository: OrderRepository
12
11
 
13
- constructor(parent: Router, storage: AbstractStorage) {
12
+ constructor(parent: Router, cartRepository: CartRepository, orderRepository: OrderRepository) {
14
13
  super(parent)
15
- this.repository = new CartRepository(storage)
16
- this.orderRepository = new OrderRepository(storage)
14
+ this.repository = cartRepository
15
+ this.orderRepository = orderRepository
17
16
  }
18
17
 
19
18
  getBasePath() {
@@ -38,13 +37,11 @@ export class CartService extends AbstractService {
38
37
  ...cartOrOrder,
39
38
  currency: cartOrOrder.totalPrice.currencyCode,
40
39
  discountCodes: [],
41
- lineItems: cartOrOrder.lineItems.map(lineItem => {
42
- return {
43
- ...lineItem,
44
- variantId: lineItem.variant.id,
45
- sku: lineItem.variant.sku,
46
- }
47
- }),
40
+ lineItems: cartOrOrder.lineItems.map((lineItem) => ({
41
+ ...lineItem,
42
+ variantId: lineItem.variant.id,
43
+ sku: lineItem.variant.sku,
44
+ })),
48
45
  }
49
46
 
50
47
  const newCart = this.repository.create(context, cartDraft)
@@ -6,8 +6,7 @@ describe('Categories Query', () => {
6
6
  const ctMock = new CommercetoolsMock()
7
7
 
8
8
  beforeEach(async () => {
9
- let response
10
- response = await supertest(ctMock.app)
9
+ const response = await supertest(ctMock.app)
11
10
  .post('/dummy/categories')
12
11
  .send({
13
12
  name: {
@@ -1,14 +1,13 @@
1
1
  import AbstractService from './abstract'
2
2
  import { Router } from 'express'
3
- import { AbstractStorage } from '../storage'
4
3
  import { CategoryRepository } from '../repositories/category'
5
4
 
6
5
  export class CategoryServices extends AbstractService {
7
6
  public repository: CategoryRepository
8
7
 
9
- constructor(parent: Router, storage: AbstractStorage) {
8
+ constructor(parent: Router, repository: CategoryRepository) {
10
9
  super(parent)
11
- this.repository = new CategoryRepository(storage)
10
+ this.repository = repository
12
11
  }
13
12
 
14
13
  getBasePath() {
@@ -1,14 +1,13 @@
1
1
  import AbstractService from './abstract'
2
2
  import { Router } from 'express'
3
3
  import { ChannelRepository } from '../repositories/channel'
4
- import { AbstractStorage } from '../storage'
5
4
 
6
5
  export class ChannelService extends AbstractService {
7
6
  public repository: ChannelRepository
8
7
 
9
- constructor(parent: Router, storage: AbstractStorage) {
8
+ constructor(parent: Router, repository: ChannelRepository) {
10
9
  super(parent)
11
- this.repository = new ChannelRepository(storage)
10
+ this.repository = repository
12
11
  }
13
12
 
14
13
  getBasePath() {
@@ -7,7 +7,7 @@ describe('CustomObject create', () => {
7
7
  const ctMock = new CommercetoolsMock()
8
8
 
9
9
  test('Create new object', async () => {
10
- let response = await supertest(ctMock.app)
10
+ const response = await supertest(ctMock.app)
11
11
  .post('/dummy/custom-objects')
12
12
  .send({
13
13
  container: 'my-container',
@@ -145,27 +145,27 @@ describe('CustomObject retrieve', () => {
145
145
  test('update with container and key', async () => {
146
146
  ctMock.project('dummy').add('key-value-document', {
147
147
  ...getBaseResourceProperties(),
148
- container: 'my-container',
148
+ container: 'my-other-container',
149
149
  key: 'my-key',
150
150
  value: 'my-value',
151
151
  version: 2,
152
152
  })
153
153
 
154
154
  const response = await supertest(ctMock.app)
155
- .post('/dummy/custom-objects/my-container/my-key')
155
+ .post('/dummy/custom-objects/my-other-container/my-key')
156
156
  .send({
157
157
  value: 'new-value',
158
158
  })
159
159
 
160
160
  expect(response.status).toEqual(200)
161
161
  expect(response.body).toEqual({
162
- container: 'my-container',
162
+ container: 'my-other-container',
163
163
  createdAt: expect.anything(),
164
164
  id: expect.anything(),
165
165
  key: 'my-key',
166
166
  lastModifiedAt: expect.anything(),
167
167
  value: 'new-value',
168
- version: 2,
168
+ version: 3,
169
169
  })
170
170
  })
171
171
 
@@ -1,16 +1,15 @@
1
1
  import AbstractService from './abstract'
2
2
  import { Request, Response, Router } from 'express'
3
3
  import { CustomObjectRepository } from '../repositories/custom-object'
4
- import { AbstractStorage } from '../storage'
5
4
  import { CustomObjectDraft } from '@commercetools/platform-sdk'
6
5
  import { getRepositoryContext } from '../repositories/helpers'
7
6
 
8
7
  export class CustomObjectService extends AbstractService {
9
8
  public repository: CustomObjectRepository
10
9
 
11
- constructor(parent: Router, storage: AbstractStorage) {
10
+ constructor(parent: Router, repository: CustomObjectRepository) {
12
11
  super(parent)
13
- this.repository = new CustomObjectRepository(storage)
12
+ this.repository = repository
14
13
  }
15
14
 
16
15
  getBasePath() {
@@ -1,14 +1,13 @@
1
1
  import AbstractService from './abstract'
2
2
  import { Router } from 'express'
3
3
  import { CustomerGroupRepository } from '../repositories/customer-group'
4
- import { AbstractStorage } from '../storage'
5
4
 
6
5
  export class CustomerGroupService extends AbstractService {
7
6
  public repository: CustomerGroupRepository
8
7
 
9
- constructor(parent: Router, storage: AbstractStorage) {
8
+ constructor(parent: Router, repository: CustomerGroupRepository) {
10
9
  super(parent)
11
- this.repository = new CustomerGroupRepository(storage)
10
+ this.repository = repository
12
11
  }
13
12
 
14
13
  getBasePath() {
@@ -0,0 +1,136 @@
1
+ import assert from 'assert'
2
+ import { Customer } from '@commercetools/platform-sdk'
3
+ import supertest from 'supertest'
4
+ import { CommercetoolsMock, getBaseResourceProperties } from '../index'
5
+
6
+ describe('Customer Update Actions', () => {
7
+ const ctMock = new CommercetoolsMock()
8
+ let customer: Customer | undefined
9
+
10
+ beforeEach(async () => {
11
+ customer = {
12
+ ...getBaseResourceProperties(),
13
+ id: 'customer-uuid',
14
+ email: 'user@example.com',
15
+ password: 'supersecret',
16
+ addresses: [],
17
+ isEmailVerified: true,
18
+ authenticationMode: 'Password', //default in Commercetools
19
+ version: 1,
20
+ }
21
+ ctMock.project('dummy').add('customer', customer)
22
+ })
23
+
24
+ afterEach(() => {
25
+ ctMock.clear()
26
+ })
27
+
28
+ test('changeEmail', async () => {
29
+ assert(customer, 'customer not created')
30
+
31
+ const response = await supertest(ctMock.app)
32
+ .post(`/dummy/customers/${customer.id}`)
33
+ .send({
34
+ version: 1,
35
+ actions: [{ action: 'changeEmail', email: 'new@example.com' }],
36
+ })
37
+ expect(response.status).toBe(200)
38
+ expect(response.body.version).toBe(2)
39
+ expect(response.body.email).toBe('new@example.com')
40
+ })
41
+
42
+ test('setAuthenticationMode to an invalid mode', async () => {
43
+ assert(customer, 'customer not created')
44
+
45
+ const response = await supertest(ctMock.app)
46
+ .post(`/dummy/customers/${customer.id}`)
47
+ .send({
48
+ version: 1,
49
+ actions: [{ action: 'setAuthenticationMode', authMode: 'invalid' }],
50
+ })
51
+ expect(response.status).toBe(400)
52
+ expect(response.body.message).toBe(
53
+ 'Request body does not contain valid JSON.'
54
+ )
55
+ expect(response.body.errors[0].code).toBe('InvalidJsonInput')
56
+ expect(response.body.errors[0].detailedErrorMessage).toBe(
57
+ "actions -> authMode: Invalid enum value: 'invalid'. Expected one of: 'Password','ExternalAuth'"
58
+ )
59
+ })
60
+
61
+ test('setAuthenticationMode to ExternalAuth', async () => {
62
+ assert(customer, 'customer not created')
63
+
64
+ const response = await supertest(ctMock.app)
65
+ .post(`/dummy/customers/${customer.id}`)
66
+ .send({
67
+ version: 1,
68
+ actions: [
69
+ { action: 'setAuthenticationMode', authMode: 'ExternalAuth' },
70
+ ],
71
+ })
72
+ expect(response.status).toBe(200)
73
+ expect(response.body.version).toBe(2)
74
+ expect(response.body.authenticationMode).toBe('ExternalAuth')
75
+ expect(response.body.password).toBe(undefined)
76
+ })
77
+
78
+ test('setAuthenticationMode error when setting current authMode', async () => {
79
+ assert(customer, 'customer not created')
80
+ assert(
81
+ customer.authenticationMode == 'Password',
82
+ 'customer not in default state'
83
+ )
84
+
85
+ const response = await supertest(ctMock.app)
86
+ .post(`/dummy/customers/${customer.id}`)
87
+ .send({
88
+ version: 1,
89
+ actions: [
90
+ {
91
+ action: 'setAuthenticationMode',
92
+ authMode: 'Password',
93
+ password: 'newpass',
94
+ },
95
+ ],
96
+ })
97
+ expect(response.status).toBe(400)
98
+ expect(response.body.message).toBe(
99
+ "The customer is already using the 'Password' authentication mode."
100
+ )
101
+ })
102
+
103
+ test('setAuthenticationMode to Password', async () => {
104
+ assert(customer, 'customer not created')
105
+
106
+ //change *away from* Password authMode (to be able to test changing *to* Password authMode)
107
+ await supertest(ctMock.app)
108
+ .post(`/dummy/customers/${customer.id}`)
109
+ .send({
110
+ version: 1,
111
+ actions: [
112
+ { action: 'setAuthenticationMode', authMode: 'ExternalAuth' },
113
+ ],
114
+ })
115
+
116
+ //change to Password authMode
117
+ const response = await supertest(ctMock.app)
118
+ .post(`/dummy/customers/${customer.id}`)
119
+ .send({
120
+ version: 2,
121
+ actions: [
122
+ {
123
+ action: 'setAuthenticationMode',
124
+ authMode: 'Password',
125
+ password: 'newpass',
126
+ },
127
+ ],
128
+ })
129
+ expect(response.status).toBe(200)
130
+ expect(response.body.version).toBe(3)
131
+ expect(response.body.authenticationMode).toBe('Password')
132
+ expect(response.body.password).toBe(
133
+ Buffer.from('newpass').toString('base64')
134
+ )
135
+ })
136
+ })
@@ -1,7 +1,6 @@
1
1
  import AbstractService from './abstract'
2
2
  import { Router } from 'express'
3
3
  import { CustomerRepository } from '../repositories/customer'
4
- import { AbstractStorage } from '../storage'
5
4
  import { getBaseResourceProperties } from '../helpers'
6
5
  import { v4 as uuidv4 } from 'uuid'
7
6
  import { getRepositoryContext } from '../repositories/helpers'
@@ -9,9 +8,9 @@ import { getRepositoryContext } from '../repositories/helpers'
9
8
  export class CustomerService extends AbstractService {
10
9
  public repository: CustomerRepository
11
10
 
12
- constructor(parent: Router, storage: AbstractStorage) {
11
+ constructor(parent: Router, repository: CustomerRepository) {
13
12
  super(parent)
14
- this.repository = new CustomerRepository(storage)
13
+ this.repository = repository
15
14
  }
16
15
 
17
16
  getBasePath() {
@@ -1,14 +1,13 @@
1
1
  import { Router } from 'express'
2
2
  import AbstractService from './abstract'
3
- import { AbstractStorage } from '../storage'
4
3
  import { DiscountCodeRepository } from '../repositories/discount-code'
5
4
 
6
5
  export class DiscountCodeService extends AbstractService {
7
6
  public repository: DiscountCodeRepository
8
7
 
9
- constructor(parent: Router, storage: AbstractStorage) {
8
+ constructor(parent: Router, repository: DiscountCodeRepository) {
10
9
  super(parent)
11
- this.repository = new DiscountCodeRepository(storage)
10
+ this.repository = repository
12
11
  }
13
12
 
14
13
  getBasePath() {
@@ -1,14 +1,13 @@
1
1
  import AbstractService from './abstract'
2
2
  import { Router } from 'express'
3
- import { AbstractStorage } from '../storage'
4
3
  import { ExtensionRepository } from '../repositories/extension'
5
4
 
6
5
  export class ExtensionServices extends AbstractService {
7
6
  public repository: ExtensionRepository
8
7
 
9
- constructor(parent: Router, storage: AbstractStorage) {
8
+ constructor(parent: Router, repository: ExtensionRepository) {
10
9
  super(parent)
11
- this.repository = new ExtensionRepository(storage)
10
+ this.repository = repository
12
11
  }
13
12
 
14
13
  getBasePath() {
@@ -0,0 +1,74 @@
1
+ import { CartService } from './cart'
2
+ import { CartDiscountService } from './cart-discount'
3
+ import { CategoryServices } from './category'
4
+ import { ChannelService } from './channel'
5
+ import { CustomObjectService } from './custom-object'
6
+ import { CustomerService } from './customer'
7
+ import { CustomerGroupService } from './customer-group'
8
+ import { DiscountCodeService } from './discount-code'
9
+ import { ExtensionServices } from './extension'
10
+ import { InventoryEntryService } from './inventory-entry'
11
+ import { MyCartService } from './my-cart'
12
+ import { MyCustomerService } from './my-customer'
13
+ import { MyOrderService } from './my-order'
14
+ import { MyPaymentService } from './my-payment'
15
+ import { OrderService } from './order'
16
+ import { PaymentService } from './payment'
17
+ import { ProductService } from './product'
18
+ import { ProductDiscountService } from './product-discount'
19
+ import { ProductProjectionService } from './product-projection'
20
+ import { ProductTypeService } from './product-type'
21
+ import { ShippingMethodService } from './shipping-method'
22
+ import { ShoppingListService } from './shopping-list'
23
+ import { StateService } from './state'
24
+ import { StoreService } from './store'
25
+ import { SubscriptionService } from './subscription'
26
+ import { TaxCategoryService } from './tax-category'
27
+ import { TypeService } from './type'
28
+ import { ZoneService } from './zone'
29
+
30
+ export const createServices = (router: any, repos: any) => ({
31
+ category: new CategoryServices(router, repos['category']),
32
+ cart: new CartService(router, repos['cart'], repos['order']),
33
+ 'cart-discount': new CartDiscountService(router, repos['cart-discount']),
34
+ customer: new CustomerService(router, repos['customer']),
35
+ channel: new ChannelService(router, repos['channel']),
36
+ 'customer-group': new CustomerGroupService(router, repos['customer-group']),
37
+ 'discount-code': new DiscountCodeService(router, repos['discount-code']),
38
+ extension: new ExtensionServices(router, repos['extension']),
39
+ 'inventory-entry': new InventoryEntryService(
40
+ router,
41
+ repos['inventory-entry']
42
+ ),
43
+ 'key-value-document': new CustomObjectService(
44
+ router,
45
+ repos['key-value-document']
46
+ ),
47
+ order: new OrderService(router, repos['order']),
48
+ payment: new PaymentService(router, repos['payment']),
49
+ 'my-cart': new MyCartService(router, repos['my-cart']),
50
+ 'my-order': new MyOrderService(router, repos['my-order']),
51
+ 'my-customer': new MyCustomerService(router, repos['my-customer']),
52
+ 'my-payment': new MyPaymentService(router, repos['my-payment']),
53
+ 'shipping-method': new ShippingMethodService(
54
+ router,
55
+ repos['shipping-method']
56
+ ),
57
+ 'product-type': new ProductTypeService(router, repos['product-type']),
58
+ product: new ProductService(router, repos['product']),
59
+ 'product-discount': new ProductDiscountService(
60
+ router,
61
+ repos['product-discount']
62
+ ),
63
+ 'product-projection': new ProductProjectionService(
64
+ router,
65
+ repos['product-projection']
66
+ ),
67
+ 'shopping-list': new ShoppingListService(router, repos['shopping-list']),
68
+ state: new StateService(router, repos['state']),
69
+ store: new StoreService(router, repos['store']),
70
+ subscription: new SubscriptionService(router, repos['subscription']),
71
+ 'tax-category': new TaxCategoryService(router, repos['tax-category']),
72
+ type: new TypeService(router, repos['type']),
73
+ zone: new ZoneService(router, repos['zone']),
74
+ })
@@ -8,12 +8,10 @@ describe('Inventory Entry Query', () => {
8
8
  let inventoryEntry: InventoryEntry | undefined
9
9
 
10
10
  beforeEach(async () => {
11
- let response = await supertest(ctMock.app)
12
- .post('/dummy/inventory')
13
- .send({
14
- sku: '1337',
15
- quantityOnStock: 100,
16
- })
11
+ const response = await supertest(ctMock.app).post('/dummy/inventory').send({
12
+ sku: '1337',
13
+ quantityOnStock: 100,
14
+ })
17
15
  expect(response.status).toBe(201)
18
16
  inventoryEntry = response.body
19
17
  })
@@ -59,12 +57,10 @@ describe('Inventory Entry Update Actions', () => {
59
57
  let customType: Type | undefined
60
58
 
61
59
  beforeEach(async () => {
62
- let response = await supertest(ctMock.app)
63
- .post('/dummy/inventory')
64
- .send({
65
- sku: '1337',
66
- quantityOnStock: 100,
67
- })
60
+ let response = await supertest(ctMock.app).post('/dummy/inventory').send({
61
+ sku: '1337',
62
+ quantityOnStock: 100,
63
+ })
68
64
  expect(response.status).toBe(201)
69
65
  inventoryEntry = response.body
70
66
 
@@ -1,14 +1,13 @@
1
1
  import AbstractService from './abstract'
2
2
  import { Router } from 'express'
3
- import { AbstractStorage } from '../storage'
4
3
  import { InventoryEntryRepository } from '../repositories/inventory-entry'
5
4
 
6
5
  export class InventoryEntryService extends AbstractService {
7
6
  public repository: InventoryEntryRepository
8
7
 
9
- constructor(parent: Router, storage: AbstractStorage) {
8
+ constructor(parent: Router, repository: InventoryEntryRepository) {
10
9
  super(parent)
11
- this.repository = new InventoryEntryRepository(storage)
10
+ this.repository = repository
12
11
  }
13
12
 
14
13
  getBasePath() {