@labdigital/commercetools-mock 0.10.0 → 0.11.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 (96) hide show
  1. package/dist/index.d.ts +353 -188
  2. package/dist/index.global.js +1007 -876
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +348 -217
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +348 -217
  7. package/dist/index.mjs.map +1 -1
  8. package/package.json +3 -2
  9. package/src/ctMock.ts +15 -9
  10. package/src/helpers.ts +1 -1
  11. package/src/lib/projectionSearchFilter.ts +3 -2
  12. package/src/priceSelector.test.ts +1 -3
  13. package/src/product-projection-search.ts +1 -3
  14. package/src/projectAPI.test.ts +7 -0
  15. package/src/projectAPI.ts +17 -22
  16. package/src/repositories/abstract.ts +31 -24
  17. package/src/repositories/cart-discount.ts +3 -4
  18. package/src/repositories/cart.ts +20 -15
  19. package/src/repositories/category.ts +6 -7
  20. package/src/repositories/channel.ts +4 -5
  21. package/src/repositories/custom-object.ts +9 -13
  22. package/src/repositories/customer-group.ts +3 -4
  23. package/src/repositories/customer.ts +4 -5
  24. package/src/repositories/discount-code.ts +4 -5
  25. package/src/repositories/errors.ts +1 -3
  26. package/src/repositories/extension.ts +7 -8
  27. package/src/repositories/helpers.ts +2 -2
  28. package/src/repositories/index.ts +19 -3
  29. package/src/repositories/inventory-entry.ts +4 -5
  30. package/src/repositories/my-order.ts +2 -2
  31. package/src/repositories/order-edit.ts +39 -0
  32. package/src/repositories/order.test.ts +16 -11
  33. package/src/repositories/order.ts +15 -8
  34. package/src/repositories/payment.ts +6 -7
  35. package/src/repositories/product-discount.ts +4 -24
  36. package/src/repositories/product-projection.ts +11 -5
  37. package/src/repositories/product-selection.ts +40 -0
  38. package/src/repositories/product-type.ts +11 -28
  39. package/src/repositories/product.ts +117 -10
  40. package/src/repositories/project.ts +9 -8
  41. package/src/repositories/quote-request.ts +28 -0
  42. package/src/repositories/quote.ts +28 -0
  43. package/src/repositories/review.ts +34 -0
  44. package/src/repositories/shipping-method.ts +10 -11
  45. package/src/repositories/shopping-list.ts +4 -4
  46. package/src/repositories/staged-quote.ts +29 -0
  47. package/src/repositories/standalone-price.ts +36 -0
  48. package/src/repositories/state.ts +15 -8
  49. package/src/repositories/store.ts +11 -27
  50. package/src/repositories/subscription.ts +3 -4
  51. package/src/repositories/tax-category.ts +5 -22
  52. package/src/repositories/type.ts +12 -13
  53. package/src/repositories/zone.ts +4 -5
  54. package/src/server.ts +4 -4
  55. package/src/services/abstract.ts +3 -5
  56. package/src/services/cart-discount.ts +1 -1
  57. package/src/services/cart.test.ts +1 -1
  58. package/src/services/cart.ts +40 -33
  59. package/src/services/category.ts +1 -1
  60. package/src/services/channel.ts +1 -1
  61. package/src/services/custom-object.test.ts +1 -1
  62. package/src/services/custom-object.ts +2 -2
  63. package/src/services/customer-group.ts +1 -1
  64. package/src/services/customer.test.ts +1 -1
  65. package/src/services/customer.ts +3 -3
  66. package/src/services/discount-code.ts +1 -1
  67. package/src/services/extension.ts +1 -1
  68. package/src/services/inventory-entry.test.ts +1 -1
  69. package/src/services/inventory-entry.ts +1 -1
  70. package/src/services/my-cart.test.ts +2 -0
  71. package/src/services/my-cart.ts +1 -1
  72. package/src/services/my-customer.ts +1 -1
  73. package/src/services/my-order.ts +1 -1
  74. package/src/services/my-payment.ts +1 -1
  75. package/src/services/order.test.ts +24 -20
  76. package/src/services/order.ts +2 -2
  77. package/src/services/payment.ts +1 -1
  78. package/src/services/product-discount.ts +1 -17
  79. package/src/services/product-projection.test.ts +1 -1
  80. package/src/services/product-projection.ts +2 -2
  81. package/src/services/product-type.ts +1 -17
  82. package/src/services/product.test.ts +63 -2
  83. package/src/services/product.ts +1 -1
  84. package/src/services/project.ts +4 -5
  85. package/src/services/shipping-method.ts +1 -1
  86. package/src/services/shopping-list.ts +1 -1
  87. package/src/services/state.ts +1 -1
  88. package/src/services/store.ts +2 -18
  89. package/src/services/subscription.ts +1 -1
  90. package/src/services/tax-category.ts +1 -17
  91. package/src/services/type.ts +1 -1
  92. package/src/services/zone.ts +1 -1
  93. package/src/storage/abstract.ts +82 -0
  94. package/src/{storage.ts → storage/in-memory.ts} +57 -118
  95. package/src/storage/index.ts +2 -0
  96. package/src/types.ts +48 -119
package/src/server.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { CommercetoolsMock } from './index'
2
2
 
3
- process.on('SIGINT', function() {
4
- console.info("Stopping server...")
5
- process.exit();
6
- });
3
+ process.on('SIGINT', function () {
4
+ console.info('Stopping server...')
5
+ process.exit()
6
+ })
7
7
 
8
8
  const instance = new CommercetoolsMock()
9
9
 
@@ -1,12 +1,12 @@
1
1
  import { Update } from '@commercetools/platform-sdk'
2
- import { ParsedQs } from 'qs'
3
2
  import { Request, Response, Router } from 'express'
3
+ import { ParsedQs } from 'qs'
4
4
  import { AbstractResourceRepository } from '../repositories/abstract'
5
5
  import { getRepositoryContext } from '../repositories/helpers'
6
6
 
7
7
  export default abstract class AbstractService {
8
8
  protected abstract getBasePath(): string
9
- public abstract repository: AbstractResourceRepository
9
+ public abstract repository: AbstractResourceRepository<any>
10
10
 
11
11
  createStatusCode = 201
12
12
 
@@ -14,9 +14,7 @@ export default abstract class AbstractService {
14
14
  this.registerRoutes(parent)
15
15
  }
16
16
 
17
- extraRoutes(router: Router) {
18
-
19
- }
17
+ extraRoutes(router: Router) {}
20
18
 
21
19
  registerRoutes(parent: Router) {
22
20
  const basePath = this.getBasePath()
@@ -1,6 +1,6 @@
1
1
  import { Router } from 'express'
2
- import AbstractService from './abstract'
3
2
  import { CartDiscountRepository } from '../repositories/cart-discount'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class CartDiscountService extends AbstractService {
6
6
  public repository: CartDiscountRepository
@@ -4,9 +4,9 @@ import {
4
4
  CentPrecisionMoney,
5
5
  ProductDraft,
6
6
  } from '@commercetools/platform-sdk'
7
+ import assert from 'assert'
7
8
  import supertest from 'supertest'
8
9
  import { CommercetoolsMock } from '../index'
9
- import assert from 'assert'
10
10
 
11
11
  describe('Carts Query', () => {
12
12
  const ctMock = new CommercetoolsMock()
@@ -1,15 +1,19 @@
1
- import AbstractService from './abstract'
2
- import { Router } from 'express'
3
- import { CartRepository } from '../repositories/cart'
4
1
  import { Cart, CartDraft, Order } from '@commercetools/platform-sdk'
5
- import { OrderRepository } from '../repositories/order'
2
+ import { Request, Response, Router } from 'express'
3
+ import { CartRepository } from '../repositories/cart'
6
4
  import { getRepositoryContext } from '../repositories/helpers'
5
+ import { OrderRepository } from '../repositories/order'
6
+ import AbstractService from './abstract'
7
7
 
8
8
  export class CartService extends AbstractService {
9
9
  public repository: CartRepository
10
10
  public orderRepository: OrderRepository
11
11
 
12
- constructor(parent: Router, cartRepository: CartRepository, orderRepository: OrderRepository) {
12
+ constructor(
13
+ parent: Router,
14
+ cartRepository: CartRepository,
15
+ orderRepository: OrderRepository
16
+ ) {
13
17
  super(parent)
14
18
  this.repository = cartRepository
15
19
  this.orderRepository = orderRepository
@@ -20,33 +24,36 @@ export class CartService extends AbstractService {
20
24
  }
21
25
 
22
26
  extraRoutes(parent: Router) {
23
- parent.post('/replicate', (request, response) => {
24
- const context = getRepositoryContext(request)
25
-
26
- // @ts-ignore
27
- const cartOrOrder: Cart | Order | null =
28
- request.body.reference.typeId === 'order'
29
- ? this.orderRepository.get(context, request.body.reference.id)
30
- : this.repository.get(context, request.body.reference.id)
31
-
32
- if (!cartOrOrder) {
33
- return response.status(400).send()
34
- }
35
-
36
- const cartDraft: CartDraft = {
37
- ...cartOrOrder,
38
- currency: cartOrOrder.totalPrice.currencyCode,
39
- discountCodes: [],
40
- lineItems: cartOrOrder.lineItems.map((lineItem) => ({
41
- ...lineItem,
42
- variantId: lineItem.variant.id,
43
- sku: lineItem.variant.sku,
44
- })),
45
- }
46
-
47
- const newCart = this.repository.create(context, cartDraft)
48
-
49
- return response.status(200).send(newCart)
50
- })
27
+ parent.post('/replicate', this.replicate.bind(this))
28
+ }
29
+
30
+ replicate(request: Request, response: Response) {
31
+ const context = getRepositoryContext(request)
32
+
33
+ // @ts-ignore
34
+ const cartOrOrder: Cart | Order | null =
35
+ request.body.reference.typeId === 'order'
36
+ ? this.orderRepository.get(context, request.body.reference.id)
37
+ : this.repository.get(context, request.body.reference.id)
38
+
39
+ if (!cartOrOrder) {
40
+ return response.status(400).send()
41
+ }
42
+
43
+ const cartDraft: CartDraft = {
44
+ ...cartOrOrder,
45
+ currency: cartOrOrder.totalPrice.currencyCode,
46
+ discountCodes: [],
47
+ shipping: [], // TODO: cartOrOrder.shipping,
48
+ lineItems: cartOrOrder.lineItems.map((lineItem) => ({
49
+ ...lineItem,
50
+ variantId: lineItem.variant.id,
51
+ sku: lineItem.variant.sku,
52
+ })),
53
+ }
54
+
55
+ const newCart = this.repository.create(context, cartDraft)
56
+
57
+ return response.status(200).send(newCart)
51
58
  }
52
59
  }
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { CategoryRepository } from '../repositories/category'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class CategoryServices extends AbstractService {
6
6
  public repository: CategoryRepository
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { ChannelRepository } from '../repositories/channel'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class ChannelService extends AbstractService {
6
6
  public repository: ChannelRepository
@@ -1,6 +1,6 @@
1
1
  import { CustomObject } from '@commercetools/platform-sdk'
2
- import { getBaseResourceProperties } from '../helpers'
3
2
  import supertest from 'supertest'
3
+ import { getBaseResourceProperties } from '../helpers'
4
4
  import { CommercetoolsMock } from '../index'
5
5
 
6
6
  describe('CustomObject create', () => {
@@ -1,8 +1,8 @@
1
- import AbstractService from './abstract'
1
+ import { CustomObjectDraft } from '@commercetools/platform-sdk'
2
2
  import { Request, Response, Router } from 'express'
3
3
  import { CustomObjectRepository } from '../repositories/custom-object'
4
- import { CustomObjectDraft } from '@commercetools/platform-sdk'
5
4
  import { getRepositoryContext } from '../repositories/helpers'
5
+ import AbstractService from './abstract'
6
6
 
7
7
  export class CustomObjectService extends AbstractService {
8
8
  public repository: CustomObjectRepository
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { CustomerGroupRepository } from '../repositories/customer-group'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class CustomerGroupService extends AbstractService {
6
6
  public repository: CustomerGroupRepository
@@ -1,5 +1,5 @@
1
- import assert from 'assert'
2
1
  import { Customer } from '@commercetools/platform-sdk'
2
+ import assert from 'assert'
3
3
  import supertest from 'supertest'
4
4
  import { CommercetoolsMock, getBaseResourceProperties } from '../index'
5
5
 
@@ -1,9 +1,9 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
- import { CustomerRepository } from '../repositories/customer'
4
- import { getBaseResourceProperties } from '../helpers'
5
2
  import { v4 as uuidv4 } from 'uuid'
3
+ import { getBaseResourceProperties } from '../helpers'
4
+ import { CustomerRepository } from '../repositories/customer'
6
5
  import { getRepositoryContext } from '../repositories/helpers'
6
+ import AbstractService from './abstract'
7
7
 
8
8
  export class CustomerService extends AbstractService {
9
9
  public repository: CustomerRepository
@@ -1,6 +1,6 @@
1
1
  import { Router } from 'express'
2
- import AbstractService from './abstract'
3
2
  import { DiscountCodeRepository } from '../repositories/discount-code'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class DiscountCodeService extends AbstractService {
6
6
  public repository: DiscountCodeRepository
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { ExtensionRepository } from '../repositories/extension'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class ExtensionServices extends AbstractService {
6
6
  public repository: ExtensionRepository
@@ -1,5 +1,5 @@
1
- import assert from 'assert'
2
1
  import { InventoryEntry, Type } from '@commercetools/platform-sdk'
2
+ import assert from 'assert'
3
3
  import supertest from 'supertest'
4
4
  import { CommercetoolsMock } from '../index'
5
5
 
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { InventoryEntryRepository } from '../repositories/inventory-entry'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class InventoryEntryService extends AbstractService {
6
6
  public repository: InventoryEntryRepository
@@ -40,6 +40,8 @@ describe('MyCart', () => {
40
40
  cartState: 'Active',
41
41
  lineItems: [],
42
42
  customLineItems: [],
43
+ shipping: [],
44
+ shippingMode: 'Single',
43
45
  totalPrice: {
44
46
  type: 'centPrecision',
45
47
  centAmount: 0,
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Request, Response, Router } from 'express'
3
2
  import { CartRepository } from '../repositories/cart'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class MyCartService extends AbstractService {
6
6
  public repository: CartRepository
@@ -1,7 +1,7 @@
1
- import AbstractService from './abstract'
2
1
  import { Request, Response, Router } from 'express'
3
2
  import { CustomerRepository } from '../repositories/customer'
4
3
  import { getRepositoryContext } from '../repositories/helpers'
4
+ import AbstractService from './abstract'
5
5
 
6
6
  export class MyCustomerService extends AbstractService {
7
7
  public repository: CustomerRepository
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { MyOrderRepository } from '../repositories/my-order'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class MyOrderService extends AbstractService {
6
6
  public repository: MyOrderRepository
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { PaymentRepository } from '../repositories/payment'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class MyPaymentService extends AbstractService {
6
6
  public repository: PaymentRepository
@@ -137,21 +137,13 @@ describe('Order payment tests', () => {
137
137
  }
138
138
 
139
139
  const order: Order = {
140
+ ...getBaseResourceProperties(),
140
141
  customLineItems: [],
141
142
  lastMessageSequenceNumber: 0,
142
143
  lineItems: [],
144
+ orderNumber: '1337',
143
145
  orderState: 'Open',
144
146
  origin: 'Customer',
145
- refusedGifts: [],
146
- syncInfo: [],
147
- totalPrice: {
148
- type: 'centPrecision',
149
- fractionDigits: 2,
150
- centAmount: 2000,
151
- currencyCode: 'EUR',
152
- },
153
- ...getBaseResourceProperties(),
154
- orderNumber: '1337',
155
147
  paymentInfo: {
156
148
  payments: [
157
149
  {
@@ -160,6 +152,16 @@ describe('Order payment tests', () => {
160
152
  },
161
153
  ],
162
154
  },
155
+ refusedGifts: [],
156
+ shipping: [],
157
+ shippingMode: 'Single',
158
+ syncInfo: [],
159
+ totalPrice: {
160
+ type: 'centPrecision',
161
+ fractionDigits: 2,
162
+ centAmount: 2000,
163
+ currencyCode: 'EUR',
164
+ },
163
165
  }
164
166
 
165
167
  ctMock.project().add('state', state)
@@ -228,21 +230,13 @@ describe('Order payment tests', () => {
228
230
  }
229
231
 
230
232
  const order: Order = {
233
+ ...getBaseResourceProperties(),
231
234
  customLineItems: [],
232
235
  lastMessageSequenceNumber: 0,
233
236
  lineItems: [],
237
+ orderNumber: '1337',
234
238
  orderState: 'Open',
235
239
  origin: 'Customer',
236
- refusedGifts: [],
237
- syncInfo: [],
238
- totalPrice: {
239
- type: 'centPrecision',
240
- fractionDigits: 2,
241
- centAmount: 2000,
242
- currencyCode: 'EUR',
243
- },
244
- ...getBaseResourceProperties(),
245
- orderNumber: '1337',
246
240
  paymentInfo: {
247
241
  payments: [
248
242
  {
@@ -251,6 +245,16 @@ describe('Order payment tests', () => {
251
245
  },
252
246
  ],
253
247
  },
248
+ refusedGifts: [],
249
+ shipping: [],
250
+ shippingMode: 'Single',
251
+ syncInfo: [],
252
+ totalPrice: {
253
+ type: 'centPrecision',
254
+ fractionDigits: 2,
255
+ centAmount: 2000,
256
+ currencyCode: 'EUR',
257
+ },
254
258
  }
255
259
 
256
260
  ctMock.project().add('state', state)
@@ -1,7 +1,7 @@
1
- import AbstractService from './abstract'
2
1
  import { Request, Response, Router } from 'express'
3
- import { OrderRepository } from '../repositories/order'
4
2
  import { getRepositoryContext } from '../repositories/helpers'
3
+ import { OrderRepository } from '../repositories/order'
4
+ import AbstractService from './abstract'
5
5
 
6
6
  export class OrderService extends AbstractService {
7
7
  public repository: OrderRepository
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { PaymentRepository } from '../repositories/payment'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class PaymentService extends AbstractService {
6
6
  public repository: PaymentRepository
@@ -1,7 +1,6 @@
1
+ import { Router } from 'express'
1
2
  import { ProductDiscountRepository } from '../repositories/product-discount'
2
3
  import AbstractService from './abstract'
3
- import { Request, Response, Router } from 'express'
4
- import { getRepositoryContext } from '../repositories/helpers'
5
4
 
6
5
  export class ProductDiscountService extends AbstractService {
7
6
  public repository: ProductDiscountRepository
@@ -14,19 +13,4 @@ export class ProductDiscountService extends AbstractService {
14
13
  getBasePath() {
15
14
  return 'product-discounts'
16
15
  }
17
-
18
- extraRoutes(router: Router) {
19
- router.get('/key=:key', this.getWithKey.bind(this))
20
- }
21
-
22
- getWithKey(request: Request, response: Response) {
23
- const resource = this.repository.getWithKey(
24
- getRepositoryContext(request),
25
- request.params.key
26
- )
27
- if (resource) {
28
- return response.status(200).send(resource)
29
- }
30
- return response.status(404).send('Not found')
31
- }
32
16
  }
@@ -8,8 +8,8 @@ import {
8
8
  } from '@commercetools/platform-sdk'
9
9
  import supertest from 'supertest'
10
10
  import * as timekeeper from 'timekeeper'
11
- import { CommercetoolsMock } from '../index'
12
11
  import { Writable } from '../types'
12
+ import { CommercetoolsMock } from '../index'
13
13
 
14
14
  const ctMock = new CommercetoolsMock()
15
15
 
@@ -1,7 +1,7 @@
1
- import { ProductProjectionRepository } from './../repositories/product-projection'
2
- import AbstractService from './abstract'
3
1
  import { Request, Response, Router } from 'express'
4
2
  import { getRepositoryContext } from '../repositories/helpers'
3
+ import { ProductProjectionRepository } from './../repositories/product-projection'
4
+ import AbstractService from './abstract'
5
5
 
6
6
  export class ProductProjectionService extends AbstractService {
7
7
  public repository: ProductProjectionRepository
@@ -1,7 +1,6 @@
1
+ import { Router } from 'express'
1
2
  import { ProductTypeRepository } from '../repositories/product-type'
2
3
  import AbstractService from './abstract'
3
- import { Request, Response, Router } from 'express'
4
- import { getRepositoryContext } from '../repositories/helpers'
5
4
 
6
5
  export class ProductTypeService extends AbstractService {
7
6
  public repository: ProductTypeRepository
@@ -14,19 +13,4 @@ export class ProductTypeService extends AbstractService {
14
13
  getBasePath() {
15
14
  return 'product-types'
16
15
  }
17
-
18
- extraRoutes(router: Router) {
19
- router.get('/key=:key', this.getWithKey.bind(this))
20
- }
21
-
22
- getWithKey(request: Request, response: Response) {
23
- const resource = this.repository.getWithKey(
24
- getRepositoryContext(request),
25
- request.params.key
26
- )
27
- if (resource) {
28
- return response.status(200).send(resource)
29
- }
30
- return response.status(404).send('Not found')
31
- }
32
16
  }
@@ -1,7 +1,12 @@
1
- import { Product, ProductData, ProductDraft } from '@commercetools/platform-sdk'
1
+ import {
2
+ Image,
3
+ Product,
4
+ ProductData,
5
+ ProductDraft,
6
+ } from '@commercetools/platform-sdk'
7
+ import assert from 'assert'
2
8
  import supertest from 'supertest'
3
9
  import { CommercetoolsMock } from '../index'
4
- import assert from 'assert'
5
10
 
6
11
  const ctMock = new CommercetoolsMock()
7
12
 
@@ -294,4 +299,60 @@ describe('Product update actions', () => {
294
299
  const attr = response.body.masterData.staged.masterVariant.attributes[0]
295
300
  expect(attr).toEqual({ name: 'test', value: 'foo' })
296
301
  })
302
+
303
+ test('addExternalImage variant', async () => {
304
+ assert(productPublished, 'product not created')
305
+
306
+ const image: Image = {
307
+ url: 'http://example.com/image',
308
+ dimensions: { w: 100, h: 100 },
309
+ }
310
+ const response = await supertest(ctMock.app)
311
+ .post(`/dummy/products/${productPublished.id}`)
312
+ .send({
313
+ version: 1,
314
+ actions: [{ action: 'addExternalImage', sku: '1338', image }],
315
+ })
316
+ expect(response.status).toBe(200)
317
+ expect(response.body.version).toBe(2)
318
+ expect(response.body.masterData.staged.variants[0].images).toHaveLength(1)
319
+ const attr = response.body.masterData.staged.variants[0].images[0]
320
+ expect(attr).toEqual(image)
321
+ })
322
+
323
+ test('removeImage variant', async () => {
324
+ assert(productPublished, 'product not created')
325
+
326
+ const image: Image = {
327
+ url: 'http://example.com/image',
328
+ dimensions: { w: 100, h: 100 },
329
+ }
330
+
331
+ {
332
+ const response = await supertest(ctMock.app)
333
+ .post(`/dummy/products/${productPublished.id}`)
334
+ .send({
335
+ version: 1,
336
+ actions: [{ action: 'addExternalImage', sku: '1338', image }],
337
+ })
338
+ expect(response.status).toBe(200)
339
+ expect(response.body.version).toBe(2)
340
+ }
341
+
342
+ const response = await supertest(ctMock.app)
343
+ .post(`/dummy/products/${productPublished.id}`)
344
+ .send({
345
+ version: 2,
346
+ actions: [
347
+ {
348
+ action: 'removeImage',
349
+ sku: '1338',
350
+ imageUrl: image.url,
351
+ },
352
+ ],
353
+ })
354
+ expect(response.status).toBe(200)
355
+ expect(response.body.version).toBe(3)
356
+ expect(response.body.masterData.staged.variants[0].images).toHaveLength(0)
357
+ })
297
358
  })
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { ProductRepository } from '../repositories/product'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class ProductService extends AbstractService {
6
6
  public repository: ProductRepository
@@ -1,8 +1,7 @@
1
- import { Router } from 'express'
2
- import { Request, Response } from 'express'
3
- import { ProjectRepository } from '../repositories/project'
4
1
  import { Update } from '@commercetools/platform-sdk'
2
+ import { Request, Response, Router } from 'express'
5
3
  import { getRepositoryContext } from '../repositories/helpers'
4
+ import { ProjectRepository } from '../repositories/project'
6
5
 
7
6
  export class ProjectService {
8
7
  public repository: ProjectRepository
@@ -30,13 +29,13 @@ export class ProjectService {
30
29
  return response.status(404).send({})
31
30
  }
32
31
 
33
- this.repository.processUpdateActions(
32
+ const updatedResource = this.repository.processUpdateActions(
34
33
  getRepositoryContext(request),
35
34
  project,
36
35
  updateRequest.version,
37
36
  updateRequest.actions
38
37
  )
39
38
 
40
- return response.status(200).send({})
39
+ return response.status(200).send(updatedResource)
41
40
  }
42
41
  }
@@ -1,6 +1,6 @@
1
+ import { Router } from 'express'
1
2
  import { ShippingMethodRepository } from '../repositories/shipping-method'
2
3
  import AbstractService from './abstract'
3
- import { Router } from 'express'
4
4
 
5
5
  export class ShippingMethodService extends AbstractService {
6
6
  public repository: ShippingMethodRepository
@@ -1,6 +1,6 @@
1
+ import { Router } from 'express'
1
2
  import { ShoppingListRepository } from './../repositories/shopping-list'
2
3
  import AbstractService from './abstract'
3
- import { Router } from 'express'
4
4
 
5
5
  export class ShoppingListService extends AbstractService {
6
6
  public repository: ShoppingListRepository
@@ -1,6 +1,6 @@
1
+ import { Router } from 'express'
1
2
  import { StateRepository } from '../repositories/state'
2
3
  import AbstractService from './abstract'
3
- import { Router } from 'express'
4
4
 
5
5
  export class StateService extends AbstractService {
6
6
  public repository: StateRepository
@@ -1,7 +1,6 @@
1
- import AbstractService from './abstract'
2
- import { Router, Request, Response } from 'express'
1
+ import { Router } from 'express'
3
2
  import { StoreRepository } from '../repositories/store'
4
- import { getRepositoryContext } from '../repositories/helpers'
3
+ import AbstractService from './abstract'
5
4
 
6
5
  export class StoreService extends AbstractService {
7
6
  public repository: StoreRepository
@@ -14,19 +13,4 @@ export class StoreService extends AbstractService {
14
13
  getBasePath() {
15
14
  return 'stores'
16
15
  }
17
-
18
- extraRoutes(router: Router) {
19
- router.get('/key=:key', this.getWithKey.bind(this))
20
- }
21
-
22
- getWithKey(request: Request, response: Response) {
23
- const resource = this.repository.getWithKey(
24
- getRepositoryContext(request),
25
- request.params.key
26
- )
27
- if (resource) {
28
- return response.status(200).send(resource)
29
- }
30
- return response.status(404).send('Not found')
31
- }
32
16
  }