@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.
- package/README.md +8 -0
- package/dist/index.d.ts +18 -17
- package/dist/index.global.js +1751 -1664
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1773 -1684
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1966 -1877
- package/dist/index.mjs.map +1 -1
- package/package.json +28 -20
- package/src/constants.ts +4 -2
- package/src/ctMock.ts +19 -84
- package/src/helpers.ts +9 -10
- package/src/index.test.ts +1 -1
- package/src/lib/haversine.ts +2 -2
- package/src/lib/masking.ts +3 -1
- package/src/lib/predicateParser.test.ts +16 -0
- package/src/lib/predicateParser.ts +94 -86
- package/src/lib/projectionSearchFilter.test.ts +28 -36
- package/src/lib/projectionSearchFilter.ts +86 -102
- package/src/oauth/store.ts +3 -3
- package/src/priceSelector.test.ts +18 -35
- package/src/priceSelector.ts +6 -9
- package/src/product-projection-search.ts +51 -57
- package/src/repositories/abstract.ts +85 -41
- package/src/repositories/cart-discount.ts +1 -1
- package/src/repositories/cart.ts +36 -31
- package/src/repositories/category.ts +17 -19
- package/src/repositories/channel.ts +1 -1
- package/src/repositories/custom-object.ts +35 -22
- package/src/repositories/customer-group.ts +1 -1
- package/src/repositories/customer.ts +39 -1
- package/src/repositories/discount-code.ts +1 -1
- package/src/repositories/errors.ts +9 -11
- package/src/repositories/extension.ts +13 -11
- package/src/repositories/helpers.ts +8 -13
- package/src/repositories/index.ts +59 -0
- package/src/repositories/inventory-entry.ts +1 -1
- package/src/repositories/order.ts +6 -6
- package/src/repositories/payment.ts +3 -3
- package/src/repositories/product-discount.ts +1 -1
- package/src/repositories/product-projection.ts +1 -0
- package/src/repositories/product-type.ts +29 -34
- package/src/repositories/product.ts +124 -80
- package/src/repositories/project.ts +10 -27
- package/src/repositories/shipping-method.ts +15 -17
- package/src/repositories/shopping-list.ts +2 -2
- package/src/repositories/state.ts +9 -9
- package/src/repositories/store.ts +2 -2
- package/src/repositories/subscription.ts +1 -1
- package/src/repositories/tax-category.ts +4 -4
- package/src/repositories/type.ts +12 -14
- package/src/repositories/zone.ts +5 -6
- package/src/server.ts +5 -0
- package/src/services/abstract.ts +44 -11
- package/src/services/cart-discount.ts +2 -3
- package/src/services/cart.test.ts +8 -10
- package/src/services/cart.ts +8 -11
- package/src/services/category.test.ts +1 -2
- package/src/services/category.ts +2 -3
- package/src/services/channel.ts +2 -3
- package/src/services/custom-object.test.ts +5 -5
- package/src/services/custom-object.ts +2 -3
- package/src/services/customer-group.ts +2 -3
- package/src/services/customer.test.ts +136 -0
- package/src/services/customer.ts +2 -3
- package/src/services/discount-code.ts +2 -3
- package/src/services/extension.ts +2 -3
- package/src/services/index.ts +74 -0
- package/src/services/inventory-entry.test.ts +8 -12
- package/src/services/inventory-entry.ts +2 -3
- package/src/services/my-cart.ts +3 -4
- package/src/services/my-customer.ts +2 -3
- package/src/services/my-order.ts +3 -4
- package/src/services/my-payment.ts +2 -3
- package/src/services/order.test.ts +4 -6
- package/src/services/order.ts +2 -3
- package/src/services/payment.ts +2 -3
- package/src/services/product-discount.ts +2 -3
- package/src/services/product-projection.test.ts +76 -8
- package/src/services/product-projection.ts +2 -3
- package/src/services/product-type.ts +2 -3
- package/src/services/product.test.ts +199 -89
- package/src/services/product.ts +2 -3
- package/src/services/project.ts +3 -3
- package/src/services/shipping-method.ts +2 -3
- package/src/services/shopping-list.ts +2 -3
- package/src/services/state.ts +2 -3
- package/src/services/store.test.ts +11 -2
- package/src/services/store.ts +2 -3
- package/src/services/subscription.ts +2 -3
- package/src/services/tax-category.ts +2 -3
- package/src/services/type.ts +2 -3
- package/src/services/zone.ts +2 -3
- package/src/storage.ts +23 -30
- package/src/types.ts +46 -6
package/src/services/my-cart.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import AbstractService from './abstract'
|
|
2
2
|
import { Request, Response, Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
3
|
import { CartRepository } from '../repositories/cart'
|
|
5
4
|
|
|
6
5
|
export class MyCartService extends AbstractService {
|
|
7
6
|
public repository: CartRepository
|
|
8
7
|
|
|
9
|
-
constructor(parent: Router,
|
|
8
|
+
constructor(parent: Router, repository: CartRepository) {
|
|
10
9
|
super(parent)
|
|
11
|
-
this.repository =
|
|
10
|
+
this.repository = repository
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
getBasePath() {
|
|
@@ -26,7 +25,7 @@ export class MyCartService extends AbstractService {
|
|
|
26
25
|
router.get('/carts/', this.get.bind(this))
|
|
27
26
|
router.get('/carts/:id', this.getWithId.bind(this))
|
|
28
27
|
|
|
29
|
-
router.delete('/carts/:id', this.
|
|
28
|
+
router.delete('/carts/:id', this.deleteWithId.bind(this))
|
|
30
29
|
|
|
31
30
|
router.post('/carts/', this.post.bind(this))
|
|
32
31
|
router.post('/carts/:id', this.postWithId.bind(this))
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import AbstractService from './abstract'
|
|
2
2
|
import { Request, Response, Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
3
|
import { CustomerRepository } from '../repositories/customer'
|
|
5
4
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
5
|
|
|
7
6
|
export class MyCustomerService extends AbstractService {
|
|
8
7
|
public repository: CustomerRepository
|
|
9
8
|
|
|
10
|
-
constructor(parent: Router,
|
|
9
|
+
constructor(parent: Router, repository: CustomerRepository) {
|
|
11
10
|
super(parent)
|
|
12
|
-
this.repository =
|
|
11
|
+
this.repository = repository
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
getBasePath() {
|
package/src/services/my-order.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import AbstractService from './abstract'
|
|
2
2
|
import { Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
3
|
import { MyOrderRepository } from '../repositories/my-order'
|
|
5
4
|
|
|
6
5
|
export class MyOrderService extends AbstractService {
|
|
7
6
|
public repository: MyOrderRepository
|
|
8
7
|
|
|
9
|
-
constructor(parent: Router,
|
|
8
|
+
constructor(parent: Router, repository: MyOrderRepository) {
|
|
10
9
|
super(parent)
|
|
11
|
-
this.repository =
|
|
10
|
+
this.repository = repository
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
getBasePath() {
|
|
@@ -25,7 +24,7 @@ export class MyOrderService extends AbstractService {
|
|
|
25
24
|
router.get('/orders/', this.get.bind(this))
|
|
26
25
|
router.get('/orders/:id', this.getWithId.bind(this))
|
|
27
26
|
|
|
28
|
-
router.delete('/orders/:id', this.
|
|
27
|
+
router.delete('/orders/:id', this.deleteWithId.bind(this))
|
|
29
28
|
|
|
30
29
|
router.post('/orders/', this.post.bind(this))
|
|
31
30
|
router.post('/orders/:id', this.postWithId.bind(this))
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import AbstractService from './abstract'
|
|
2
2
|
import { Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
3
|
import { PaymentRepository } from '../repositories/payment'
|
|
5
4
|
|
|
6
5
|
export class MyPaymentService extends AbstractService {
|
|
7
6
|
public repository: PaymentRepository
|
|
8
7
|
|
|
9
|
-
constructor(parent: Router,
|
|
8
|
+
constructor(parent: Router, repository: PaymentRepository) {
|
|
10
9
|
super(parent)
|
|
11
|
-
this.repository =
|
|
10
|
+
this.repository = repository
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
getBasePath() {
|
|
@@ -274,11 +274,9 @@ describe('Order Update Actions', () => {
|
|
|
274
274
|
let order: Order | undefined
|
|
275
275
|
|
|
276
276
|
beforeEach(async () => {
|
|
277
|
-
let response = await supertest(ctMock.app)
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
currency: 'EUR',
|
|
281
|
-
})
|
|
277
|
+
let response = await supertest(ctMock.app).post('/dummy/carts').send({
|
|
278
|
+
currency: 'EUR',
|
|
279
|
+
})
|
|
282
280
|
expect(response.status).toBe(201)
|
|
283
281
|
const cart = response.body
|
|
284
282
|
|
|
@@ -359,7 +357,7 @@ describe('Order Update Actions', () => {
|
|
|
359
357
|
],
|
|
360
358
|
})
|
|
361
359
|
expect(response.status).toBe(200)
|
|
362
|
-
expect(response.body.version).toBe(
|
|
360
|
+
expect(response.body.version).toBe(3)
|
|
363
361
|
expect(response.body.orderState).toBe('Cancelled')
|
|
364
362
|
expect(response.body.paymentState).toBe('Failed')
|
|
365
363
|
})
|
package/src/services/order.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import AbstractService from './abstract'
|
|
2
2
|
import { Request, Response, Router } from 'express'
|
|
3
3
|
import { OrderRepository } from '../repositories/order'
|
|
4
|
-
import { AbstractStorage } from '../storage'
|
|
5
4
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
5
|
|
|
7
6
|
export class OrderService extends AbstractService {
|
|
8
7
|
public repository: OrderRepository
|
|
9
8
|
|
|
10
|
-
constructor(parent: Router,
|
|
9
|
+
constructor(parent: Router, repository: OrderRepository) {
|
|
11
10
|
super(parent)
|
|
12
|
-
this.repository =
|
|
11
|
+
this.repository = repository
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
getBasePath() {
|
package/src/services/payment.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import AbstractService from './abstract'
|
|
2
2
|
import { Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
3
|
import { PaymentRepository } from '../repositories/payment'
|
|
5
4
|
|
|
6
5
|
export class PaymentService extends AbstractService {
|
|
7
6
|
public repository: PaymentRepository
|
|
8
7
|
|
|
9
|
-
constructor(parent: Router,
|
|
8
|
+
constructor(parent: Router, repository: PaymentRepository) {
|
|
10
9
|
super(parent)
|
|
11
|
-
this.repository =
|
|
10
|
+
this.repository = repository
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
getBasePath() {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ProductDiscountRepository } from '../repositories/product-discount'
|
|
2
2
|
import AbstractService from './abstract'
|
|
3
3
|
import { Request, Response, Router } from 'express'
|
|
4
|
-
import { AbstractStorage } from '../storage'
|
|
5
4
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
5
|
|
|
7
6
|
export class ProductDiscountService extends AbstractService {
|
|
8
7
|
public repository: ProductDiscountRepository
|
|
9
8
|
|
|
10
|
-
constructor(parent: Router,
|
|
9
|
+
constructor(parent: Router, repository: ProductDiscountRepository) {
|
|
11
10
|
super(parent)
|
|
12
|
-
this.repository =
|
|
11
|
+
this.repository = repository
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
getBasePath() {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Product,
|
|
2
3
|
ProductDraft,
|
|
3
4
|
ProductProjection,
|
|
4
5
|
ProductProjectionPagedSearchResponse,
|
|
@@ -8,12 +9,14 @@ import {
|
|
|
8
9
|
import supertest from 'supertest'
|
|
9
10
|
import * as timekeeper from 'timekeeper'
|
|
10
11
|
import { CommercetoolsMock } from '../index'
|
|
11
|
-
import { Writable } from 'types'
|
|
12
|
+
import { Writable } from '../types'
|
|
12
13
|
|
|
13
14
|
const ctMock = new CommercetoolsMock()
|
|
14
15
|
|
|
15
16
|
let productType: ProductType
|
|
16
17
|
let productProjection: ProductProjection
|
|
18
|
+
let publishedProduct: Product
|
|
19
|
+
let unpublishedProduct: Product
|
|
17
20
|
|
|
18
21
|
beforeEach(async () => {
|
|
19
22
|
timekeeper.freeze(new Date('2022-07-22T13:31:49.840Z'))
|
|
@@ -32,7 +35,48 @@ beforeEach(async () => {
|
|
|
32
35
|
productType = response.body
|
|
33
36
|
}
|
|
34
37
|
|
|
35
|
-
// Create
|
|
38
|
+
// Create an unpublished product
|
|
39
|
+
{
|
|
40
|
+
const productDraft: Writable<ProductDraft> = {
|
|
41
|
+
publish: false,
|
|
42
|
+
key: 'my-unpublished-product',
|
|
43
|
+
masterVariant: {
|
|
44
|
+
sku: 'my-unpub-sku',
|
|
45
|
+
prices: [
|
|
46
|
+
{
|
|
47
|
+
value: {
|
|
48
|
+
currencyCode: 'EUR',
|
|
49
|
+
centAmount: 189,
|
|
50
|
+
},
|
|
51
|
+
},
|
|
52
|
+
],
|
|
53
|
+
attributes: [
|
|
54
|
+
{
|
|
55
|
+
name: 'number',
|
|
56
|
+
value: 1 as any,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
59
|
+
},
|
|
60
|
+
name: {
|
|
61
|
+
'nl-NL': 'test unpublished product',
|
|
62
|
+
},
|
|
63
|
+
productType: {
|
|
64
|
+
typeId: 'product-type',
|
|
65
|
+
id: productType.id,
|
|
66
|
+
},
|
|
67
|
+
slug: {
|
|
68
|
+
'nl-NL': 'test-unpublished-product',
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const response = await supertest(ctMock.app)
|
|
73
|
+
.post('/dummy/products')
|
|
74
|
+
.send(productDraft)
|
|
75
|
+
expect(response.ok).toBe(true)
|
|
76
|
+
unpublishedProduct = response.body
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Create a published product
|
|
36
80
|
{
|
|
37
81
|
const productDraft: Writable<ProductDraft> = {
|
|
38
82
|
publish: true,
|
|
@@ -90,6 +134,7 @@ beforeEach(async () => {
|
|
|
90
134
|
.send(productDraft)
|
|
91
135
|
expect(response.ok).toBe(true)
|
|
92
136
|
const product = response.body
|
|
137
|
+
publishedProduct = response.body
|
|
93
138
|
|
|
94
139
|
// Create the expected ProductProjection object
|
|
95
140
|
productProjection = {
|
|
@@ -97,6 +142,9 @@ beforeEach(async () => {
|
|
|
97
142
|
createdAt: '2022-07-22T13:31:49.840Z',
|
|
98
143
|
lastModifiedAt: '2022-07-22T13:31:49.840Z',
|
|
99
144
|
version: 1,
|
|
145
|
+
key: 'my-product-key',
|
|
146
|
+
published: true,
|
|
147
|
+
hasStagedChanges: false,
|
|
100
148
|
masterVariant: {
|
|
101
149
|
id: 1,
|
|
102
150
|
sku: 'my-sku',
|
|
@@ -148,12 +196,7 @@ beforeEach(async () => {
|
|
|
148
196
|
|
|
149
197
|
afterEach(async () => {
|
|
150
198
|
timekeeper.reset()
|
|
151
|
-
|
|
152
|
-
const response = await supertest(ctMock.app)
|
|
153
|
-
.delete(`/dummy/products/${productProjection.id}`)
|
|
154
|
-
.send()
|
|
155
|
-
expect(response.ok).toBe(true)
|
|
156
|
-
const product = response.body
|
|
199
|
+
ctMock.clear()
|
|
157
200
|
})
|
|
158
201
|
|
|
159
202
|
// Test the general product projection implementation
|
|
@@ -196,6 +239,31 @@ describe('Product Projection Search - Generic', () => {
|
|
|
196
239
|
}
|
|
197
240
|
})
|
|
198
241
|
|
|
242
|
+
test('Search - unpublished', async () => {
|
|
243
|
+
{
|
|
244
|
+
const response = await supertest(ctMock.app)
|
|
245
|
+
.get('/dummy/product-projections/search')
|
|
246
|
+
.query({
|
|
247
|
+
limit: 50,
|
|
248
|
+
staged: true,
|
|
249
|
+
})
|
|
250
|
+
|
|
251
|
+
const result: ProductProjectionPagedSearchResponse = response.body
|
|
252
|
+
|
|
253
|
+
expect(result).toMatchObject({
|
|
254
|
+
count: 2,
|
|
255
|
+
limit: 50,
|
|
256
|
+
offset: 0,
|
|
257
|
+
total: 2,
|
|
258
|
+
facets: {},
|
|
259
|
+
results: [
|
|
260
|
+
{ id: unpublishedProduct.id, published: false },
|
|
261
|
+
{ id: publishedProduct.id, published: true },
|
|
262
|
+
],
|
|
263
|
+
})
|
|
264
|
+
}
|
|
265
|
+
})
|
|
266
|
+
|
|
199
267
|
test('Get 404 when not found by key with expand', async () => {
|
|
200
268
|
const response = await supertest(ctMock.app)
|
|
201
269
|
.get('/dummy/product-projections/key=DOESNOTEXIST')
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ProductProjectionRepository } from './../repositories/product-projection'
|
|
2
2
|
import AbstractService from './abstract'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
3
|
import { Request, Response, Router } from 'express'
|
|
5
4
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
5
|
|
|
7
6
|
export class ProductProjectionService extends AbstractService {
|
|
8
7
|
public repository: ProductProjectionRepository
|
|
9
8
|
|
|
10
|
-
constructor(parent: Router,
|
|
9
|
+
constructor(parent: Router, repository: ProductProjectionRepository) {
|
|
11
10
|
super(parent)
|
|
12
|
-
this.repository =
|
|
11
|
+
this.repository = repository
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
getBasePath() {
|
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import { ProductTypeRepository } from '../repositories/product-type'
|
|
2
2
|
import AbstractService from './abstract'
|
|
3
3
|
import { Request, Response, Router } from 'express'
|
|
4
|
-
import { AbstractStorage } from '../storage'
|
|
5
4
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
5
|
|
|
7
6
|
export class ProductTypeService extends AbstractService {
|
|
8
7
|
public repository: ProductTypeRepository
|
|
9
8
|
|
|
10
|
-
constructor(parent: Router,
|
|
9
|
+
constructor(parent: Router, repository: ProductTypeRepository) {
|
|
11
10
|
super(parent)
|
|
12
|
-
this.repository =
|
|
11
|
+
this.repository = repository
|
|
13
12
|
}
|
|
14
13
|
|
|
15
14
|
getBasePath() {
|