@labdigital/commercetools-mock 0.9.1 → 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.
- package/README.md +8 -0
- package/dist/index.d.ts +354 -188
- package/dist/index.global.js +2346 -2209
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +1968 -1829
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2171 -2032
- package/dist/index.mjs.map +1 -1
- package/package.json +30 -21
- package/src/constants.ts +4 -2
- package/src/ctMock.ts +27 -86
- package/src/helpers.ts +10 -11
- 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.ts +93 -92
- package/src/lib/projectionSearchFilter.test.ts +28 -36
- package/src/lib/projectionSearchFilter.ts +88 -103
- package/src/oauth/store.ts +3 -3
- package/src/priceSelector.test.ts +16 -35
- package/src/priceSelector.ts +6 -9
- package/src/product-projection-search.ts +49 -57
- package/src/projectAPI.test.ts +7 -0
- package/src/projectAPI.ts +17 -22
- package/src/repositories/abstract.ts +102 -51
- package/src/repositories/cart-discount.ts +4 -5
- package/src/repositories/cart.ts +56 -46
- package/src/repositories/category.ts +23 -26
- package/src/repositories/channel.ts +5 -6
- package/src/repositories/custom-object.ts +41 -32
- package/src/repositories/customer-group.ts +4 -5
- package/src/repositories/customer.ts +42 -5
- package/src/repositories/discount-code.ts +5 -6
- package/src/repositories/errors.ts +10 -14
- package/src/repositories/extension.ts +16 -15
- package/src/repositories/helpers.ts +10 -15
- package/src/repositories/index.ts +75 -0
- package/src/repositories/inventory-entry.ts +5 -6
- package/src/repositories/my-order.ts +2 -2
- package/src/repositories/order-edit.ts +39 -0
- package/src/repositories/order.test.ts +16 -11
- package/src/repositories/order.ts +21 -14
- package/src/repositories/payment.ts +9 -10
- package/src/repositories/product-discount.ts +5 -25
- package/src/repositories/product-projection.ts +12 -5
- package/src/repositories/product-selection.ts +40 -0
- package/src/repositories/product-type.ts +38 -60
- package/src/repositories/product.ts +128 -85
- package/src/repositories/project.ts +16 -33
- package/src/repositories/quote-request.ts +28 -0
- package/src/repositories/quote.ts +28 -0
- package/src/repositories/review.ts +34 -0
- package/src/repositories/shipping-method.ts +25 -28
- package/src/repositories/shopping-list.ts +6 -6
- package/src/repositories/staged-quote.ts +29 -0
- package/src/repositories/standalone-price.ts +36 -0
- package/src/repositories/state.ts +16 -17
- package/src/repositories/store.ts +13 -29
- package/src/repositories/subscription.ts +4 -5
- package/src/repositories/tax-category.ts +9 -26
- package/src/repositories/type.ts +24 -27
- package/src/repositories/zone.ts +9 -11
- package/src/server.ts +5 -0
- package/src/services/abstract.ts +43 -12
- package/src/services/cart-discount.ts +3 -4
- package/src/services/cart.test.ts +9 -11
- package/src/services/cart.ts +42 -38
- package/src/services/category.test.ts +1 -2
- package/src/services/category.ts +3 -4
- package/src/services/channel.ts +3 -4
- package/src/services/custom-object.test.ts +6 -6
- package/src/services/custom-object.ts +4 -5
- package/src/services/customer-group.ts +3 -4
- package/src/services/customer.test.ts +136 -0
- package/src/services/customer.ts +5 -6
- package/src/services/discount-code.ts +3 -4
- package/src/services/extension.ts +3 -4
- package/src/services/index.ts +74 -0
- package/src/services/inventory-entry.test.ts +9 -13
- package/src/services/inventory-entry.ts +3 -4
- package/src/services/my-cart.test.ts +2 -0
- package/src/services/my-cart.ts +4 -5
- package/src/services/my-customer.ts +3 -4
- package/src/services/my-order.ts +4 -5
- package/src/services/my-payment.ts +3 -4
- package/src/services/order.test.ts +28 -26
- package/src/services/order.ts +4 -5
- package/src/services/payment.ts +3 -4
- package/src/services/product-discount.ts +3 -20
- package/src/services/product-projection.test.ts +76 -8
- package/src/services/product-projection.ts +4 -5
- package/src/services/product-type.ts +3 -20
- package/src/services/product.test.ts +200 -90
- package/src/services/product.ts +3 -4
- package/src/services/project.ts +5 -6
- package/src/services/shipping-method.ts +3 -4
- package/src/services/shopping-list.ts +3 -4
- package/src/services/state.ts +3 -4
- package/src/services/store.test.ts +11 -2
- package/src/services/store.ts +4 -21
- package/src/services/subscription.ts +3 -4
- package/src/services/tax-category.ts +3 -20
- package/src/services/type.ts +3 -4
- package/src/services/zone.ts +3 -4
- package/src/storage/abstract.ts +82 -0
- package/src/{storage.ts → storage/in-memory.ts} +79 -147
- package/src/storage/index.ts +2 -0
- package/src/types.ts +52 -83
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { CartService } from './cart'
|
|
2
|
+
import { CartDiscountService } from './cart-discount'
|
|
3
|
+
import { CategoryServices } from './category'
|
|
4
|
+
import { ChannelService } from './channel'
|
|
5
|
+
import { CustomObjectService } from './custom-object'
|
|
6
|
+
import { CustomerService } from './customer'
|
|
7
|
+
import { CustomerGroupService } from './customer-group'
|
|
8
|
+
import { DiscountCodeService } from './discount-code'
|
|
9
|
+
import { ExtensionServices } from './extension'
|
|
10
|
+
import { InventoryEntryService } from './inventory-entry'
|
|
11
|
+
import { MyCartService } from './my-cart'
|
|
12
|
+
import { MyCustomerService } from './my-customer'
|
|
13
|
+
import { MyOrderService } from './my-order'
|
|
14
|
+
import { MyPaymentService } from './my-payment'
|
|
15
|
+
import { OrderService } from './order'
|
|
16
|
+
import { PaymentService } from './payment'
|
|
17
|
+
import { ProductService } from './product'
|
|
18
|
+
import { ProductDiscountService } from './product-discount'
|
|
19
|
+
import { ProductProjectionService } from './product-projection'
|
|
20
|
+
import { ProductTypeService } from './product-type'
|
|
21
|
+
import { ShippingMethodService } from './shipping-method'
|
|
22
|
+
import { ShoppingListService } from './shopping-list'
|
|
23
|
+
import { StateService } from './state'
|
|
24
|
+
import { StoreService } from './store'
|
|
25
|
+
import { SubscriptionService } from './subscription'
|
|
26
|
+
import { TaxCategoryService } from './tax-category'
|
|
27
|
+
import { TypeService } from './type'
|
|
28
|
+
import { ZoneService } from './zone'
|
|
29
|
+
|
|
30
|
+
export const createServices = (router: any, repos: any) => ({
|
|
31
|
+
category: new CategoryServices(router, repos['category']),
|
|
32
|
+
cart: new CartService(router, repos['cart'], repos['order']),
|
|
33
|
+
'cart-discount': new CartDiscountService(router, repos['cart-discount']),
|
|
34
|
+
customer: new CustomerService(router, repos['customer']),
|
|
35
|
+
channel: new ChannelService(router, repos['channel']),
|
|
36
|
+
'customer-group': new CustomerGroupService(router, repos['customer-group']),
|
|
37
|
+
'discount-code': new DiscountCodeService(router, repos['discount-code']),
|
|
38
|
+
extension: new ExtensionServices(router, repos['extension']),
|
|
39
|
+
'inventory-entry': new InventoryEntryService(
|
|
40
|
+
router,
|
|
41
|
+
repos['inventory-entry']
|
|
42
|
+
),
|
|
43
|
+
'key-value-document': new CustomObjectService(
|
|
44
|
+
router,
|
|
45
|
+
repos['key-value-document']
|
|
46
|
+
),
|
|
47
|
+
order: new OrderService(router, repos['order']),
|
|
48
|
+
payment: new PaymentService(router, repos['payment']),
|
|
49
|
+
'my-cart': new MyCartService(router, repos['my-cart']),
|
|
50
|
+
'my-order': new MyOrderService(router, repos['my-order']),
|
|
51
|
+
'my-customer': new MyCustomerService(router, repos['my-customer']),
|
|
52
|
+
'my-payment': new MyPaymentService(router, repos['my-payment']),
|
|
53
|
+
'shipping-method': new ShippingMethodService(
|
|
54
|
+
router,
|
|
55
|
+
repos['shipping-method']
|
|
56
|
+
),
|
|
57
|
+
'product-type': new ProductTypeService(router, repos['product-type']),
|
|
58
|
+
product: new ProductService(router, repos['product']),
|
|
59
|
+
'product-discount': new ProductDiscountService(
|
|
60
|
+
router,
|
|
61
|
+
repos['product-discount']
|
|
62
|
+
),
|
|
63
|
+
'product-projection': new ProductProjectionService(
|
|
64
|
+
router,
|
|
65
|
+
repos['product-projection']
|
|
66
|
+
),
|
|
67
|
+
'shopping-list': new ShoppingListService(router, repos['shopping-list']),
|
|
68
|
+
state: new StateService(router, repos['state']),
|
|
69
|
+
store: new StoreService(router, repos['store']),
|
|
70
|
+
subscription: new SubscriptionService(router, repos['subscription']),
|
|
71
|
+
'tax-category': new TaxCategoryService(router, repos['tax-category']),
|
|
72
|
+
type: new TypeService(router, repos['type']),
|
|
73
|
+
zone: new ZoneService(router, repos['zone']),
|
|
74
|
+
})
|
|
@@ -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
|
|
|
@@ -8,12 +8,10 @@ describe('Inventory Entry Query', () => {
|
|
|
8
8
|
let inventoryEntry: InventoryEntry | undefined
|
|
9
9
|
|
|
10
10
|
beforeEach(async () => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
quantityOnStock: 100,
|
|
16
|
-
})
|
|
11
|
+
const response = await supertest(ctMock.app).post('/dummy/inventory').send({
|
|
12
|
+
sku: '1337',
|
|
13
|
+
quantityOnStock: 100,
|
|
14
|
+
})
|
|
17
15
|
expect(response.status).toBe(201)
|
|
18
16
|
inventoryEntry = response.body
|
|
19
17
|
})
|
|
@@ -59,12 +57,10 @@ describe('Inventory Entry Update Actions', () => {
|
|
|
59
57
|
let customType: Type | undefined
|
|
60
58
|
|
|
61
59
|
beforeEach(async () => {
|
|
62
|
-
let response = await supertest(ctMock.app)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
quantityOnStock: 100,
|
|
67
|
-
})
|
|
60
|
+
let response = await supertest(ctMock.app).post('/dummy/inventory').send({
|
|
61
|
+
sku: '1337',
|
|
62
|
+
quantityOnStock: 100,
|
|
63
|
+
})
|
|
68
64
|
expect(response.status).toBe(201)
|
|
69
65
|
inventoryEntry = response.body
|
|
70
66
|
|
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
2
|
import { InventoryEntryRepository } from '../repositories/inventory-entry'
|
|
3
|
+
import AbstractService from './abstract'
|
|
5
4
|
|
|
6
5
|
export class InventoryEntryService extends AbstractService {
|
|
7
6
|
public repository: InventoryEntryRepository
|
|
8
7
|
|
|
9
|
-
constructor(parent: Router,
|
|
8
|
+
constructor(parent: Router, repository: InventoryEntryRepository) {
|
|
10
9
|
super(parent)
|
|
11
|
-
this.repository =
|
|
10
|
+
this.repository = repository
|
|
12
11
|
}
|
|
13
12
|
|
|
14
13
|
getBasePath() {
|
package/src/services/my-cart.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Request, Response, Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
2
|
import { CartRepository } from '../repositories/cart'
|
|
3
|
+
import AbstractService from './abstract'
|
|
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
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Request, Response, Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
2
|
import { CustomerRepository } from '../repositories/customer'
|
|
5
3
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
4
|
+
import AbstractService from './abstract'
|
|
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
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
2
|
import { MyOrderRepository } from '../repositories/my-order'
|
|
3
|
+
import AbstractService from './abstract'
|
|
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
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
2
|
import { PaymentRepository } from '../repositories/payment'
|
|
3
|
+
import AbstractService from './abstract'
|
|
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() {
|
|
@@ -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)
|
|
@@ -274,11 +278,9 @@ describe('Order Update Actions', () => {
|
|
|
274
278
|
let order: Order | undefined
|
|
275
279
|
|
|
276
280
|
beforeEach(async () => {
|
|
277
|
-
let response = await supertest(ctMock.app)
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
currency: 'EUR',
|
|
281
|
-
})
|
|
281
|
+
let response = await supertest(ctMock.app).post('/dummy/carts').send({
|
|
282
|
+
currency: 'EUR',
|
|
283
|
+
})
|
|
282
284
|
expect(response.status).toBe(201)
|
|
283
285
|
const cart = response.body
|
|
284
286
|
|
|
@@ -359,7 +361,7 @@ describe('Order Update Actions', () => {
|
|
|
359
361
|
],
|
|
360
362
|
})
|
|
361
363
|
expect(response.status).toBe(200)
|
|
362
|
-
expect(response.body.version).toBe(
|
|
364
|
+
expect(response.body.version).toBe(3)
|
|
363
365
|
expect(response.body.orderState).toBe('Cancelled')
|
|
364
366
|
expect(response.body.paymentState).toBe('Failed')
|
|
365
367
|
})
|
package/src/services/order.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Request, Response, Router } from 'express'
|
|
3
|
-
import { OrderRepository } from '../repositories/order'
|
|
4
|
-
import { AbstractStorage } from '../storage'
|
|
5
2
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
3
|
+
import { OrderRepository } from '../repositories/order'
|
|
4
|
+
import AbstractService from './abstract'
|
|
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
|
-
import AbstractService from './abstract'
|
|
2
1
|
import { Router } from 'express'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
2
|
import { PaymentRepository } from '../repositories/payment'
|
|
3
|
+
import AbstractService from './abstract'
|
|
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,33 +1,16 @@
|
|
|
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 { AbstractStorage } from '../storage'
|
|
5
|
-
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
4
|
|
|
7
5
|
export class ProductDiscountService extends AbstractService {
|
|
8
6
|
public repository: ProductDiscountRepository
|
|
9
7
|
|
|
10
|
-
constructor(parent: Router,
|
|
8
|
+
constructor(parent: Router, repository: ProductDiscountRepository) {
|
|
11
9
|
super(parent)
|
|
12
|
-
this.repository =
|
|
10
|
+
this.repository = repository
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
getBasePath() {
|
|
16
14
|
return 'product-discounts'
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
extraRoutes(router: Router) {
|
|
20
|
-
router.get('/key=:key', this.getWithKey.bind(this))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getWithKey(request: Request, response: Response) {
|
|
24
|
-
const resource = this.repository.getWithKey(
|
|
25
|
-
getRepositoryContext(request),
|
|
26
|
-
request.params.key
|
|
27
|
-
)
|
|
28
|
-
if (resource) {
|
|
29
|
-
return response.status(200).send(resource)
|
|
30
|
-
}
|
|
31
|
-
return response.status(404).send('Not found')
|
|
32
|
-
}
|
|
33
16
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Product,
|
|
2
3
|
ProductDraft,
|
|
3
4
|
ProductProjection,
|
|
4
5
|
ProductProjectionPagedSearchResponse,
|
|
@@ -7,13 +8,15 @@ import {
|
|
|
7
8
|
} from '@commercetools/platform-sdk'
|
|
8
9
|
import supertest from 'supertest'
|
|
9
10
|
import * as timekeeper from 'timekeeper'
|
|
11
|
+
import { Writable } from '../types'
|
|
10
12
|
import { CommercetoolsMock } from '../index'
|
|
11
|
-
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
|
-
import { ProductProjectionRepository } from './../repositories/product-projection'
|
|
2
|
-
import AbstractService from './abstract'
|
|
3
|
-
import { AbstractStorage } from '../storage'
|
|
4
1
|
import { Request, Response, Router } from 'express'
|
|
5
2
|
import { getRepositoryContext } from '../repositories/helpers'
|
|
3
|
+
import { ProductProjectionRepository } from './../repositories/product-projection'
|
|
4
|
+
import AbstractService from './abstract'
|
|
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,33 +1,16 @@
|
|
|
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 { AbstractStorage } from '../storage'
|
|
5
|
-
import { getRepositoryContext } from '../repositories/helpers'
|
|
6
4
|
|
|
7
5
|
export class ProductTypeService extends AbstractService {
|
|
8
6
|
public repository: ProductTypeRepository
|
|
9
7
|
|
|
10
|
-
constructor(parent: Router,
|
|
8
|
+
constructor(parent: Router, repository: ProductTypeRepository) {
|
|
11
9
|
super(parent)
|
|
12
|
-
this.repository =
|
|
10
|
+
this.repository = repository
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
getBasePath() {
|
|
16
14
|
return 'product-types'
|
|
17
15
|
}
|
|
18
|
-
|
|
19
|
-
extraRoutes(router: Router) {
|
|
20
|
-
router.get('/key=:key', this.getWithKey.bind(this))
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getWithKey(request: Request, response: Response) {
|
|
24
|
-
const resource = this.repository.getWithKey(
|
|
25
|
-
getRepositoryContext(request),
|
|
26
|
-
request.params.key
|
|
27
|
-
)
|
|
28
|
-
if (resource) {
|
|
29
|
-
return response.status(200).send(resource)
|
|
30
|
-
}
|
|
31
|
-
return response.status(404).send('Not found')
|
|
32
|
-
}
|
|
33
16
|
}
|