@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
|
@@ -21,7 +21,7 @@ describe('Order Query', () => {
|
|
|
21
21
|
},
|
|
22
22
|
},
|
|
23
23
|
})
|
|
24
|
-
expect(response.status).toBe(
|
|
24
|
+
expect(response.status).toBe(201)
|
|
25
25
|
const cart = response.body
|
|
26
26
|
|
|
27
27
|
response = await supertest(ctMock.app)
|
|
@@ -33,7 +33,7 @@ describe('Order Query', () => {
|
|
|
33
33
|
},
|
|
34
34
|
orderNumber: 'foobar',
|
|
35
35
|
})
|
|
36
|
-
expect(response.status).toBe(
|
|
36
|
+
expect(response.status).toBe(201)
|
|
37
37
|
order = response.body
|
|
38
38
|
})
|
|
39
39
|
|
|
@@ -279,7 +279,7 @@ describe('Order Update Actions', () => {
|
|
|
279
279
|
.send({
|
|
280
280
|
currency: 'EUR',
|
|
281
281
|
})
|
|
282
|
-
expect(response.status).toBe(
|
|
282
|
+
expect(response.status).toBe(201)
|
|
283
283
|
const cart = response.body
|
|
284
284
|
|
|
285
285
|
response = await supertest(ctMock.app)
|
|
@@ -290,7 +290,7 @@ describe('Order Update Actions', () => {
|
|
|
290
290
|
id: cart.id,
|
|
291
291
|
},
|
|
292
292
|
})
|
|
293
|
-
expect(response.status).toBe(
|
|
293
|
+
expect(response.status).toBe(201)
|
|
294
294
|
order = response.body
|
|
295
295
|
})
|
|
296
296
|
|
|
@@ -15,7 +15,7 @@ describe('Payment', () => {
|
|
|
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('Payment', () => {
|
|
|
32
32
|
.post('/dummy/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(),
|
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Product,
|
|
3
|
-
ProductDraft,
|
|
4
|
-
ProductProjection,
|
|
5
|
-
} from '@commercetools/platform-sdk'
|
|
1
|
+
import { ProductDraft, ProductProjection } from '@commercetools/platform-sdk'
|
|
6
2
|
import supertest from 'supertest'
|
|
7
3
|
import { CommercetoolsMock } from '../index'
|
|
8
4
|
import * as qs from 'querystring'
|
|
@@ -60,7 +56,20 @@ describe('Product Projection', () => {
|
|
|
60
56
|
})
|
|
61
57
|
})
|
|
62
58
|
|
|
63
|
-
test('
|
|
59
|
+
test('Get product projection by 404 when not found by key with expand', async () => {
|
|
60
|
+
const response = await supertest(ctMock.app).get(
|
|
61
|
+
'/dummy/product-projections/key=DOESNOTEXIST?' +
|
|
62
|
+
qs.stringify({
|
|
63
|
+
expand: ['categories[*]'],
|
|
64
|
+
})
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
expect(response.status).toBe(404)
|
|
68
|
+
})
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('Product Projection Search', () => {
|
|
72
|
+
beforeAll(() => {
|
|
64
73
|
ctMock.project('dummy').add('product-projection', {
|
|
65
74
|
id: '',
|
|
66
75
|
version: 1,
|
|
@@ -76,7 +85,9 @@ describe('Product Projection', () => {
|
|
|
76
85
|
lastModifiedAt: '',
|
|
77
86
|
categories: [],
|
|
78
87
|
})
|
|
88
|
+
})
|
|
79
89
|
|
|
90
|
+
test('Search product projection', async () => {
|
|
80
91
|
const response = await supertest(ctMock.app).get(
|
|
81
92
|
'/dummy/product-projections/search?' +
|
|
82
93
|
qs.stringify({
|
|
@@ -106,4 +117,31 @@ describe('Product Projection', () => {
|
|
|
106
117
|
],
|
|
107
118
|
})
|
|
108
119
|
})
|
|
120
|
+
|
|
121
|
+
test('Search product projection with query.filter', async () => {
|
|
122
|
+
const response = await supertest(ctMock.app).get(
|
|
123
|
+
'/dummy/product-projections/search?' +
|
|
124
|
+
qs.stringify({
|
|
125
|
+
'query.filter': ['masterVariant.sku:"1337"'],
|
|
126
|
+
})
|
|
127
|
+
)
|
|
128
|
+
|
|
129
|
+
const projection: ProductProjection = response.body
|
|
130
|
+
expect(projection).toMatchObject({
|
|
131
|
+
count: 1,
|
|
132
|
+
results: [{ masterVariant: { id: 1, sku: '1337' } }],
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
test('Search product projection without filter', async () => {
|
|
137
|
+
const response = await supertest(ctMock.app).get(
|
|
138
|
+
'/dummy/product-projections/search'
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
const projection: ProductProjection = response.body
|
|
142
|
+
expect(projection).toMatchObject({
|
|
143
|
+
count: 1,
|
|
144
|
+
results: [{ masterVariant: { id: 1, sku: '1337' } }],
|
|
145
|
+
})
|
|
146
|
+
})
|
|
109
147
|
})
|
|
@@ -22,7 +22,7 @@ describe('Product type', () => {
|
|
|
22
22
|
.post('/dummy/product-types')
|
|
23
23
|
.send(draft)
|
|
24
24
|
|
|
25
|
-
expect(response.status).toBe(
|
|
25
|
+
expect(response.status).toBe(201)
|
|
26
26
|
|
|
27
27
|
expect(response.body).toEqual({
|
|
28
28
|
attributes: [
|
|
@@ -58,7 +58,7 @@ describe('Product type', () => {
|
|
|
58
58
|
.post('/dummy/product-types')
|
|
59
59
|
.send(draft)
|
|
60
60
|
|
|
61
|
-
expect(createResponse.status).toBe(
|
|
61
|
+
expect(createResponse.status).toBe(201)
|
|
62
62
|
|
|
63
63
|
const response = await supertest(ctMock.app).get(
|
|
64
64
|
`/dummy/product-types/${createResponse.body.id}`
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
CentPrecisionMoney,
|
|
3
|
+
Product,
|
|
4
|
+
ProductDraft,
|
|
5
|
+
} from '@commercetools/platform-sdk'
|
|
2
6
|
import supertest from 'supertest'
|
|
3
7
|
import { CommercetoolsMock } from '../index'
|
|
4
8
|
import assert from 'assert'
|
|
@@ -88,7 +92,7 @@ describe('Product update actions', () => {
|
|
|
88
92
|
.post('/dummy/products')
|
|
89
93
|
.send(draft)
|
|
90
94
|
|
|
91
|
-
expect(response.status).toBe(
|
|
95
|
+
expect(response.status).toBe(201)
|
|
92
96
|
product = response.body
|
|
93
97
|
})
|
|
94
98
|
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Router } from 'express'
|
|
2
|
+
import { Request, Response } from 'express'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { ProjectRepository } from '../repositories/project'
|
|
5
|
+
import { Update } from '@commercetools/platform-sdk'
|
|
6
|
+
|
|
7
|
+
export class ProjectService {
|
|
8
|
+
public repository: ProjectRepository
|
|
9
|
+
|
|
10
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
11
|
+
this.repository = new ProjectRepository(storage)
|
|
12
|
+
this.registerRoutes(parent)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
registerRoutes(parent: Router) {
|
|
16
|
+
parent.get('', this.get.bind(this))
|
|
17
|
+
parent.post('', this.post.bind(this))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get(request: Request, response: Response) {
|
|
21
|
+
const projectKey = request.params.projectKey
|
|
22
|
+
const project = this.repository.get(projectKey)
|
|
23
|
+
return response.status(200).send(project)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
post(request: Request, response: Response) {
|
|
27
|
+
const updateRequest: Update = request.body
|
|
28
|
+
const project = this.repository.get(request.params.projectKey)
|
|
29
|
+
|
|
30
|
+
if (!project) {
|
|
31
|
+
return response.status(404).send({})
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const updatedResource = this.repository.processUpdateActions(
|
|
35
|
+
request.params.projectKey,
|
|
36
|
+
project,
|
|
37
|
+
updateRequest.actions
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
return response.status(200).send({})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -17,7 +17,7 @@ describe('Shipping method', () => {
|
|
|
17
17
|
const createResponse = await supertest(ctMock.app)
|
|
18
18
|
.post('/dummy/tax-categories')
|
|
19
19
|
.send(draft)
|
|
20
|
-
expect(createResponse.status).toEqual(
|
|
20
|
+
expect(createResponse.status).toEqual(201)
|
|
21
21
|
})
|
|
22
22
|
|
|
23
23
|
afterEach(async () => {
|
|
@@ -35,7 +35,7 @@ describe('Shipping method', () => {
|
|
|
35
35
|
.post('/dummy/shipping-methods')
|
|
36
36
|
.send(draft)
|
|
37
37
|
|
|
38
|
-
expect(response.status).toBe(
|
|
38
|
+
expect(response.status).toBe(201)
|
|
39
39
|
|
|
40
40
|
expect(response.body).toEqual({
|
|
41
41
|
createdAt: expect.anything(),
|
|
@@ -63,7 +63,7 @@ describe('Shipping method', () => {
|
|
|
63
63
|
.post('/dummy/shipping-methods')
|
|
64
64
|
.send(draft)
|
|
65
65
|
|
|
66
|
-
expect(createResponse.status).toBe(
|
|
66
|
+
expect(createResponse.status).toBe(201)
|
|
67
67
|
|
|
68
68
|
const response = await supertest(ctMock.app).get(
|
|
69
69
|
`/dummy/shipping-methods/${createResponse.body.id}`
|
|
@@ -14,7 +14,7 @@ describe('State', () => {
|
|
|
14
14
|
.post('/dummy/states')
|
|
15
15
|
.send(draft)
|
|
16
16
|
|
|
17
|
-
expect(response.status).toBe(
|
|
17
|
+
expect(response.status).toBe(201)
|
|
18
18
|
|
|
19
19
|
expect(response.body).toEqual({
|
|
20
20
|
builtIn: false,
|
|
@@ -38,7 +38,7 @@ describe('State', () => {
|
|
|
38
38
|
.post('/dummy/states')
|
|
39
39
|
.send(draft)
|
|
40
40
|
|
|
41
|
-
expect(createResponse.status).toBe(
|
|
41
|
+
expect(createResponse.status).toBe(201)
|
|
42
42
|
|
|
43
43
|
const response = await supertest(ctMock.app).get(
|
|
44
44
|
`/dummy/states/${createResponse.body.id}`
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Router } from 'express'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { SubscriptionRepository } from '../repositories/subscription'
|
|
5
|
+
|
|
6
|
+
export class SubscriptionService extends AbstractService {
|
|
7
|
+
public repository: SubscriptionRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new SubscriptionRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'subscriptions'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -18,7 +18,7 @@ describe('Tax Category', () => {
|
|
|
18
18
|
.post('/dummy/tax-categories')
|
|
19
19
|
.send(draft)
|
|
20
20
|
|
|
21
|
-
expect(response.status).toBe(
|
|
21
|
+
expect(response.status).toBe(201)
|
|
22
22
|
|
|
23
23
|
expect(response.body).toEqual({
|
|
24
24
|
createdAt: expect.anything(),
|
|
@@ -41,7 +41,7 @@ describe('Tax Category', () => {
|
|
|
41
41
|
.post('/dummy/tax-categories')
|
|
42
42
|
.send(draft)
|
|
43
43
|
|
|
44
|
-
expect(createResponse.status).toBe(
|
|
44
|
+
expect(createResponse.status).toBe(201)
|
|
45
45
|
|
|
46
46
|
const response = await supertest(ctMock.app).get(
|
|
47
47
|
`/dummy/tax-categories/${createResponse.body.id}`
|
|
@@ -61,7 +61,7 @@ describe('Tax Category', () => {
|
|
|
61
61
|
.post('/dummy/tax-categories')
|
|
62
62
|
.send(draft)
|
|
63
63
|
|
|
64
|
-
expect(createResponse.status).toBe(
|
|
64
|
+
expect(createResponse.status).toBe(201)
|
|
65
65
|
|
|
66
66
|
const response = await supertest(ctMock.app)
|
|
67
67
|
.get(`/dummy/tax-categories/`)
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express'
|
|
2
|
+
import AbstractService from './abstract'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { ZoneRepository } from '../repositories/zone'
|
|
5
|
+
|
|
6
|
+
export class ZoneService extends AbstractService {
|
|
7
|
+
public repository: ZoneRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new ZoneRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'zones'
|
|
16
|
+
}
|
|
17
|
+
}
|
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
|
|
@@ -183,8 +211,14 @@ export class InMemoryStorage extends AbstractStorage {
|
|
|
183
211
|
|
|
184
212
|
const resources: any[] = Array.from(store.values())
|
|
185
213
|
const resource = resources.find(e => e.key === key)
|
|
186
|
-
if (
|
|
187
|
-
|
|
214
|
+
if (resource) {
|
|
215
|
+
return this.expand(
|
|
216
|
+
projectKey,
|
|
217
|
+
resource,
|
|
218
|
+
params.expand
|
|
219
|
+
) as ResourceMap[RepositoryTypes]
|
|
220
|
+
}
|
|
221
|
+
return null
|
|
188
222
|
}
|
|
189
223
|
|
|
190
224
|
delete(
|
|
@@ -227,7 +261,7 @@ export class InMemoryStorage extends AbstractStorage {
|
|
|
227
261
|
throw new CommercetoolsError<InvalidInputError>(
|
|
228
262
|
{
|
|
229
263
|
code: 'InvalidInput',
|
|
230
|
-
message: err.message,
|
|
264
|
+
message: (err as any).message,
|
|
231
265
|
},
|
|
232
266
|
400
|
|
233
267
|
)
|
|
@@ -295,6 +329,46 @@ export class InMemoryStorage extends AbstractStorage {
|
|
|
295
329
|
return undefined
|
|
296
330
|
}
|
|
297
331
|
|
|
332
|
+
addProject = (projectKey: string): Project => {
|
|
333
|
+
if (!this.projects[projectKey]) {
|
|
334
|
+
this.projects[projectKey] = {
|
|
335
|
+
key: projectKey,
|
|
336
|
+
name: '',
|
|
337
|
+
countries: [],
|
|
338
|
+
currencies: [],
|
|
339
|
+
languages: [],
|
|
340
|
+
createdAt: '2018-10-04T11:32:12.603Z',
|
|
341
|
+
trialUntil: '2018-12',
|
|
342
|
+
carts: {
|
|
343
|
+
countryTaxRateFallbackEnabled: false,
|
|
344
|
+
deleteDaysAfterLastModification: 90,
|
|
345
|
+
},
|
|
346
|
+
messages: { enabled: false, deleteDaysAfterCreation: 15 },
|
|
347
|
+
shippingRateInputType: undefined,
|
|
348
|
+
externalOAuth: undefined,
|
|
349
|
+
searchIndexing: {
|
|
350
|
+
products: {
|
|
351
|
+
status: 'Deactivated',
|
|
352
|
+
},
|
|
353
|
+
orders: {
|
|
354
|
+
status: 'Deactivated',
|
|
355
|
+
},
|
|
356
|
+
},
|
|
357
|
+
version: 1,
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return this.projects[projectKey]
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
saveProject = (project: Project): Project => {
|
|
364
|
+
this.projects[project.key] = project
|
|
365
|
+
return project
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
getProject = (projectKey: string): Project => {
|
|
369
|
+
return this.addProject(projectKey)
|
|
370
|
+
}
|
|
371
|
+
|
|
298
372
|
private expand = <T>(
|
|
299
373
|
projectKey: string,
|
|
300
374
|
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
|