@labdigital/commercetools-mock 0.5.13 → 0.5.14
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 +3058 -1645
- 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 +3058 -1645
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/ctMock.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/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 +2 -2
- package/src/repositories/product-type.ts +57 -4
- package/src/repositories/product.ts +4 -2
- package/src/repositories/project.ts +150 -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 +1 -5
- 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 +69 -1
- package/src/types.ts +2 -1
package/src/storage.ts
CHANGED
|
@@ -2,6 +2,7 @@ import assert from 'assert'
|
|
|
2
2
|
import {
|
|
3
3
|
BaseResource,
|
|
4
4
|
Cart,
|
|
5
|
+
Category,
|
|
5
6
|
Customer,
|
|
6
7
|
CustomObject,
|
|
7
8
|
InventoryEntry,
|
|
@@ -14,6 +15,7 @@ import {
|
|
|
14
15
|
Store,
|
|
15
16
|
Type,
|
|
16
17
|
Payment,
|
|
18
|
+
Project,
|
|
17
19
|
State,
|
|
18
20
|
TaxCategory,
|
|
19
21
|
ShippingMethod,
|
|
@@ -21,6 +23,13 @@ import {
|
|
|
21
23
|
InvalidInputError,
|
|
22
24
|
ProductProjection,
|
|
23
25
|
ShoppingList,
|
|
26
|
+
Extension,
|
|
27
|
+
CartDiscount,
|
|
28
|
+
CustomerGroup,
|
|
29
|
+
DiscountCode,
|
|
30
|
+
Zone,
|
|
31
|
+
Channel,
|
|
32
|
+
Subscription,
|
|
24
33
|
} from '@commercetools/platform-sdk'
|
|
25
34
|
import { parseExpandClause } from './lib/expandParser'
|
|
26
35
|
import { RepositoryTypes, ResourceMap, Writable } from './types'
|
|
@@ -68,6 +77,10 @@ export abstract class AbstractStorage {
|
|
|
68
77
|
params: GetParams
|
|
69
78
|
): ResourceMap[RepositoryTypes] | null
|
|
70
79
|
|
|
80
|
+
abstract addProject(projectKey: string): Project
|
|
81
|
+
abstract getProject(projectKey: string): Project
|
|
82
|
+
abstract saveProject(project: Project): Project
|
|
83
|
+
|
|
71
84
|
abstract delete(
|
|
72
85
|
projectKey: string,
|
|
73
86
|
typeId: RepositoryTypes,
|
|
@@ -98,25 +111,40 @@ export class InMemoryStorage extends AbstractStorage {
|
|
|
98
111
|
[projectKey: string]: ProjectStorage
|
|
99
112
|
} = {}
|
|
100
113
|
|
|
114
|
+
protected projects: {
|
|
115
|
+
[projectKey: string]: Project
|
|
116
|
+
} = {}
|
|
117
|
+
|
|
101
118
|
private forProjectKey(projectKey: string) {
|
|
119
|
+
this.addProject(projectKey)
|
|
120
|
+
|
|
102
121
|
let projectStorage = this.resources[projectKey]
|
|
103
122
|
if (!projectStorage) {
|
|
104
123
|
projectStorage = this.resources[projectKey] = {
|
|
105
124
|
cart: new Map<string, Cart>(),
|
|
125
|
+
'cart-discount': new Map<string, CartDiscount>(),
|
|
126
|
+
category: new Map<string, Category>(),
|
|
127
|
+
channel: new Map<string, Channel>(),
|
|
106
128
|
customer: new Map<string, Customer>(),
|
|
129
|
+
'customer-group': new Map<string, CustomerGroup>(),
|
|
130
|
+
'discount-code': new Map<string, DiscountCode>(),
|
|
131
|
+
extension: new Map<string, Extension>(),
|
|
107
132
|
'inventory-entry': new Map<string, InventoryEntry>(),
|
|
108
133
|
'key-value-document': new Map<string, CustomObject>(),
|
|
109
134
|
order: new Map<string, Order>(),
|
|
110
135
|
payment: new Map<string, Payment>(),
|
|
111
136
|
'product-type': new Map<string, ProductType>(),
|
|
112
137
|
product: new Map<string, Product>(),
|
|
138
|
+
'product-selection': new Map<string, any>(),
|
|
113
139
|
'product-projection': new Map<string, ProductProjection>(),
|
|
114
140
|
'shipping-method': new Map<string, ShippingMethod>(),
|
|
115
141
|
state: new Map<string, State>(),
|
|
116
142
|
store: new Map<string, Store>(),
|
|
117
143
|
'shopping-list': new Map<string, ShoppingList>(),
|
|
144
|
+
subscription: new Map<string, Subscription>(),
|
|
118
145
|
'tax-category': new Map<string, TaxCategory>(),
|
|
119
146
|
type: new Map<string, Type>(),
|
|
147
|
+
zone: new Map<string, Zone>(),
|
|
120
148
|
}
|
|
121
149
|
}
|
|
122
150
|
return projectStorage
|
|
@@ -227,7 +255,7 @@ export class InMemoryStorage extends AbstractStorage {
|
|
|
227
255
|
throw new CommercetoolsError<InvalidInputError>(
|
|
228
256
|
{
|
|
229
257
|
code: 'InvalidInput',
|
|
230
|
-
message: err.message,
|
|
258
|
+
message: (err as any).message,
|
|
231
259
|
},
|
|
232
260
|
400
|
|
233
261
|
)
|
|
@@ -295,6 +323,46 @@ export class InMemoryStorage extends AbstractStorage {
|
|
|
295
323
|
return undefined
|
|
296
324
|
}
|
|
297
325
|
|
|
326
|
+
addProject = (projectKey: string): Project => {
|
|
327
|
+
if (!this.projects[projectKey]) {
|
|
328
|
+
this.projects[projectKey] = {
|
|
329
|
+
key: projectKey,
|
|
330
|
+
name: '',
|
|
331
|
+
countries: [],
|
|
332
|
+
currencies: [],
|
|
333
|
+
languages: [],
|
|
334
|
+
createdAt: '2018-10-04T11:32:12.603Z',
|
|
335
|
+
trialUntil: '2018-12',
|
|
336
|
+
carts: {
|
|
337
|
+
countryTaxRateFallbackEnabled: false,
|
|
338
|
+
deleteDaysAfterLastModification: 90,
|
|
339
|
+
},
|
|
340
|
+
messages: { enabled: false, deleteDaysAfterCreation: 15 },
|
|
341
|
+
shippingRateInputType: undefined,
|
|
342
|
+
externalOAuth: undefined,
|
|
343
|
+
searchIndexing: {
|
|
344
|
+
products: {
|
|
345
|
+
status: 'Deactivated',
|
|
346
|
+
},
|
|
347
|
+
orders: {
|
|
348
|
+
status: 'Deactivated',
|
|
349
|
+
},
|
|
350
|
+
},
|
|
351
|
+
version: 1,
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
return this.projects[projectKey]
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
saveProject = (project: Project): Project => {
|
|
358
|
+
this.projects[project.key] = project
|
|
359
|
+
return project
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
getProject = (projectKey: string): Project => {
|
|
363
|
+
return this.addProject(projectKey)
|
|
364
|
+
}
|
|
365
|
+
|
|
298
366
|
private expand = <T>(
|
|
299
367
|
projectKey: string,
|
|
300
368
|
obj: T,
|
package/src/types.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { TaxCategoryRepository } from './repositories/tax-category'
|
|
|
18
18
|
export type Writable<T> = { -readonly [P in keyof T]: Writable<T[P]> }
|
|
19
19
|
|
|
20
20
|
export type RepositoryTypes = ReferenceTypeId | 'product-projection'
|
|
21
|
-
export type ServiceTypes = RepositoryTypes | 'my-payment'
|
|
21
|
+
export type ServiceTypes = RepositoryTypes | 'my-cart' | 'my-payment'
|
|
22
22
|
|
|
23
23
|
export type Services = Partial<
|
|
24
24
|
{
|
|
@@ -43,6 +43,7 @@ export type ResourceMap = {
|
|
|
43
43
|
product: ctp.Product
|
|
44
44
|
'product-discount': ctp.ProductDiscount
|
|
45
45
|
'product-projection': ctp.ProductProjection
|
|
46
|
+
'product-selection': ctp.ProductSelection
|
|
46
47
|
'product-type': ctp.ProductType
|
|
47
48
|
review: ctp.Review
|
|
48
49
|
'shipping-method': ctp.ShippingMethod
|