@labdigital/commercetools-mock 0.10.0 → 0.10.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 (96) hide show
  1. package/dist/index.d.ts +353 -188
  2. package/dist/index.global.js +930 -874
  3. package/dist/index.global.js.map +1 -1
  4. package/dist/index.js +271 -215
  5. package/dist/index.js.map +1 -1
  6. package/dist/index.mjs +271 -215
  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 +7 -8
  40. package/src/repositories/project.ts +8 -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 +7 -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 +1 -1
  83. package/src/services/product.ts +1 -1
  84. package/src/services/project.ts +2 -3
  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
@@ -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,7 @@
1
1
  import { Product, ProductData, ProductDraft } from '@commercetools/platform-sdk'
2
+ import assert from 'assert'
2
3
  import supertest from 'supertest'
3
4
  import { CommercetoolsMock } from '../index'
4
- import assert from 'assert'
5
5
 
6
6
  const ctMock = new CommercetoolsMock()
7
7
 
@@ -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
@@ -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
  }
@@ -1,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { SubscriptionRepository } from '../repositories/subscription'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class SubscriptionService extends AbstractService {
6
6
  public repository: SubscriptionRepository
@@ -1,7 +1,6 @@
1
+ import { Router } from 'express'
1
2
  import { TaxCategoryRepository } from '../repositories/tax-category'
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 TaxCategoryService extends AbstractService {
7
6
  public repository: TaxCategoryRepository
@@ -14,19 +13,4 @@ export class TaxCategoryService extends AbstractService {
14
13
  getBasePath() {
15
14
  return 'tax-categories'
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,6 +1,6 @@
1
- import AbstractService from './abstract'
2
1
  import { Router } from 'express'
3
2
  import { TypeRepository } from '../repositories/type'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class TypeService extends AbstractService {
6
6
  public repository: TypeRepository
@@ -1,6 +1,6 @@
1
1
  import { Router } from 'express'
2
- import AbstractService from './abstract'
3
2
  import { ZoneRepository } from '../repositories/zone'
3
+ import AbstractService from './abstract'
4
4
 
5
5
  export class ZoneService extends AbstractService {
6
6
  public repository: ZoneRepository
@@ -0,0 +1,82 @@
1
+ import {
2
+ BaseResource,
3
+ Project,
4
+ QueryParam,
5
+ ResourceIdentifier
6
+ } from '@commercetools/platform-sdk'
7
+ import { PagedQueryResponseMap, ResourceMap, ResourceType } from '../types'
8
+
9
+ export type GetParams = {
10
+ expand?: string[]
11
+ }
12
+
13
+ export type QueryParams = {
14
+ expand?: string | string[]
15
+ sort?: string | string[]
16
+ limit?: number
17
+ offset?: number
18
+ withTotal?: boolean
19
+ where?: string | string[]
20
+ [key: string]: QueryParam
21
+ }
22
+
23
+ export abstract class AbstractStorage {
24
+ abstract clear(): void
25
+
26
+ abstract all<RT extends ResourceType>(
27
+ projectKey: string,
28
+ typeId: RT
29
+ ): Array<ResourceMap[RT]>
30
+
31
+ abstract add<RT extends ResourceType>(
32
+ projectKey: string,
33
+ typeId: RT,
34
+ obj: ResourceMap[RT]
35
+ ): void
36
+
37
+ abstract get<RT extends ResourceType>(
38
+ projectKey: string,
39
+ typeId: RT,
40
+ id: string,
41
+ params?: GetParams
42
+ ): ResourceMap[RT] | null
43
+
44
+ abstract getByKey<RT extends ResourceType>(
45
+ projectKey: string,
46
+ typeId: RT,
47
+ key: string,
48
+ params: GetParams
49
+ ): ResourceMap[RT] | null
50
+
51
+ abstract addProject(projectKey: string): Project
52
+ abstract getProject(projectKey: string): Project
53
+ abstract saveProject(project: Project): Project
54
+
55
+ abstract delete<RT extends ResourceType>(
56
+ projectKey: string,
57
+ typeId: RT,
58
+ id: string,
59
+ params: GetParams
60
+ ): ResourceMap[RT] | null
61
+
62
+ abstract query<RT extends ResourceType>(
63
+ projectKey: string,
64
+ typeId: RT,
65
+ params: QueryParams
66
+ ): PagedQueryResponseMap[RT]
67
+
68
+ abstract getByResourceIdentifier<RT extends ResourceType>(
69
+ projectKey: string,
70
+ identifier: ResourceIdentifier
71
+ ): ResourceMap[RT] | null
72
+
73
+ abstract expand<T>(
74
+ projectKey: string,
75
+ obj: T,
76
+ clause: undefined | string | string[]
77
+ ): T
78
+ }
79
+
80
+ export type ProjectStorage = {
81
+ [index in ResourceType]: Map<string, BaseResource>
82
+ }