@labdigital/commercetools-mock 0.5.11 → 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 +30 -12
- package/dist/commercetools-mock.cjs.development.js +3190 -1574
- 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 +3190 -1574
- package/dist/commercetools-mock.esm.js.map +1 -1
- package/dist/ctMock.d.ts +1 -0
- package/dist/lib/filterParser.d.ts +1 -0
- package/dist/repositories/abstract.d.ts +11 -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 +10 -0
- 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 +6 -0
- 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/custom-object.d.ts +2 -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/product-projection.d.ts +11 -0
- package/dist/services/project.d.ts +11 -0
- package/dist/services/shopping-list.d.ts +9 -0
- package/dist/services/subscription.d.ts +9 -0
- package/dist/services/zone.d.ts +9 -0
- package/dist/storage.d.ts +27 -16
- package/dist/types.d.ts +9 -4
- package/package.json +20 -20
- package/src/ctMock.ts +49 -15
- package/src/lib/filterParser.test.ts +15 -0
- package/src/lib/filterParser.ts +17 -0
- package/src/oauth/server.ts +3 -1
- package/src/repositories/abstract.ts +49 -34
- 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 +5 -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 +74 -0
- 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 +50 -0
- 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 +26 -18
- 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 +53 -3
- package/src/services/custom-object.ts +30 -0
- 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/my-payment.ts +1 -1
- package/src/services/order.test.ts +4 -4
- package/src/services/payment.test.ts +2 -2
- package/src/services/product-projection.test.ts +105 -0
- package/src/services/product-projection.ts +29 -0
- 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/shopping-list.ts +17 -0
- package/src/services/state.test.ts +2 -2
- package/src/services/store.test.ts +60 -0
- 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 +127 -31
- package/src/types.ts +9 -3
package/src/services/abstract.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { Update } from '@commercetools/platform-sdk'
|
|
2
2
|
import { ParsedQs } from 'qs'
|
|
3
3
|
import { Request, Response, Router } from 'express'
|
|
4
|
-
import
|
|
4
|
+
import { AbstractResourceRepository } from '../repositories/abstract'
|
|
5
5
|
|
|
6
6
|
export default abstract class AbstractService {
|
|
7
7
|
protected abstract getBasePath(): string
|
|
8
|
-
public abstract repository:
|
|
8
|
+
public abstract repository: AbstractResourceRepository
|
|
9
|
+
|
|
10
|
+
createStatusCode = 201
|
|
9
11
|
|
|
10
12
|
constructor(parent: Router) {
|
|
11
13
|
this.registerRoutes(parent)
|
|
@@ -21,15 +23,15 @@ export default abstract class AbstractService {
|
|
|
21
23
|
this.extraRoutes(router)
|
|
22
24
|
|
|
23
25
|
router.get('/', this.get.bind(this))
|
|
26
|
+
router.get('/key=:key', this.getWithKey.bind(this)) // same thing goes for the key routes
|
|
24
27
|
router.get('/:id', this.getWithId.bind(this))
|
|
25
|
-
router.get('/key=:key', this.getWithKey.bind(this))
|
|
26
28
|
|
|
27
|
-
router.delete('/:id', this.deletewithId.bind(this))
|
|
28
29
|
router.delete('/key=:key', this.deletewithKey.bind(this))
|
|
30
|
+
router.delete('/:id', this.deletewithId.bind(this))
|
|
29
31
|
|
|
30
32
|
router.post('/', this.post.bind(this))
|
|
31
|
-
router.post('/:id', this.postWithId.bind(this))
|
|
32
33
|
router.post('/key=:key', this.postWithKey.bind(this))
|
|
34
|
+
router.post('/:id', this.postWithId.bind(this))
|
|
33
35
|
|
|
34
36
|
parent.use(`/${basePath}`, router)
|
|
35
37
|
}
|
|
@@ -43,11 +45,22 @@ export default abstract class AbstractService {
|
|
|
43
45
|
}
|
|
44
46
|
|
|
45
47
|
getWithId(request: Request, response: Response) {
|
|
46
|
-
|
|
48
|
+
const result = this._expandWithId(request, request.params['id'])
|
|
49
|
+
if (!result) {
|
|
50
|
+
return response.status(404).send()
|
|
51
|
+
}
|
|
52
|
+
console.log(JSON.stringify(result, null, 4))
|
|
53
|
+
return response.status(200).send(result)
|
|
47
54
|
}
|
|
48
55
|
|
|
49
56
|
getWithKey(request: Request, response: Response) {
|
|
50
|
-
|
|
57
|
+
const result = this.repository.getByKey(
|
|
58
|
+
request.params.projectKey,
|
|
59
|
+
request.params['key'],
|
|
60
|
+
{ expand: this._parseParam(request.query.expand) }
|
|
61
|
+
)
|
|
62
|
+
if (!result) return response.status(404).send()
|
|
63
|
+
return response.status(200).send(result)
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
deletewithId(request: Request, response: Response) {
|
|
@@ -71,7 +84,8 @@ export default abstract class AbstractService {
|
|
|
71
84
|
post(request: Request, response: Response) {
|
|
72
85
|
const draft = request.body
|
|
73
86
|
const resource = this.repository.create(request.params.projectKey, draft)
|
|
74
|
-
|
|
87
|
+
const result = this._expandWithId(request, resource.id)
|
|
88
|
+
return response.status(this.createStatusCode).send(result)
|
|
75
89
|
}
|
|
76
90
|
|
|
77
91
|
postWithId(request: Request, response: Response) {
|
|
@@ -94,25 +108,19 @@ export default abstract class AbstractService {
|
|
|
94
108
|
updateRequest.actions
|
|
95
109
|
)
|
|
96
110
|
|
|
97
|
-
|
|
111
|
+
const result = this._expandWithId(request, updatedResource.id)
|
|
112
|
+
return response.status(200).send(result)
|
|
98
113
|
}
|
|
99
114
|
|
|
100
115
|
postWithKey(request: Request, response: Response) {
|
|
101
116
|
return response.status(500).send('Not implemented')
|
|
102
117
|
}
|
|
103
118
|
|
|
104
|
-
protected _expandWithId(
|
|
105
|
-
request: Request,
|
|
106
|
-
response: Response,
|
|
107
|
-
resourceId: string
|
|
108
|
-
) {
|
|
119
|
+
protected _expandWithId(request: Request, resourceId: string) {
|
|
109
120
|
const result = this.repository.get(request.params.projectKey, resourceId, {
|
|
110
121
|
expand: this._parseParam(request.query.expand),
|
|
111
122
|
})
|
|
112
|
-
|
|
113
|
-
return response.status(404).send('Not found')
|
|
114
|
-
}
|
|
115
|
-
return response.status(200).send(result)
|
|
123
|
+
return result
|
|
116
124
|
}
|
|
117
125
|
|
|
118
126
|
// No idea what i'm doing
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express'
|
|
2
|
+
import AbstractService from './abstract'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { CartDiscountRepository } from '../repositories/cart-discount'
|
|
5
|
+
|
|
6
|
+
export class CartDiscountService extends AbstractService {
|
|
7
|
+
public repository: CartDiscountRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new CartDiscountRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'cart-discounts'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -1,6 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
Address,
|
|
3
|
+
Cart,
|
|
4
|
+
CentPrecisionMoney,
|
|
5
|
+
ProductDraft,
|
|
6
|
+
} from '@commercetools/platform-sdk'
|
|
2
7
|
import supertest from 'supertest'
|
|
3
8
|
import { CommercetoolsMock } from '../index'
|
|
9
|
+
import assert from 'assert'
|
|
4
10
|
|
|
5
11
|
describe('Carts Query', () => {
|
|
6
12
|
const ctMock = new CommercetoolsMock()
|
|
@@ -32,7 +38,7 @@ describe('Carts Query', () => {
|
|
|
32
38
|
},
|
|
33
39
|
],
|
|
34
40
|
})
|
|
35
|
-
expect(response.status).toBe(
|
|
41
|
+
expect(response.status).toBe(201)
|
|
36
42
|
|
|
37
43
|
response = await supertest(ctMock.app)
|
|
38
44
|
.post('/dummy/carts')
|
|
@@ -48,7 +54,7 @@ describe('Carts Query', () => {
|
|
|
48
54
|
},
|
|
49
55
|
},
|
|
50
56
|
})
|
|
51
|
-
expect(response.status).toBe(
|
|
57
|
+
expect(response.status).toBe(201)
|
|
52
58
|
})
|
|
53
59
|
|
|
54
60
|
test('no filter', async () => {
|
|
@@ -69,3 +75,308 @@ describe('Carts Query', () => {
|
|
|
69
75
|
expect(myCart.custom?.type.obj?.description?.en).toBe('Test Type')
|
|
70
76
|
})
|
|
71
77
|
})
|
|
78
|
+
|
|
79
|
+
describe('Order Update Actions', () => {
|
|
80
|
+
const ctMock = new CommercetoolsMock()
|
|
81
|
+
let cart: Cart | undefined
|
|
82
|
+
const productDraft: ProductDraft = {
|
|
83
|
+
name: {
|
|
84
|
+
'nl-NL': 'test product',
|
|
85
|
+
},
|
|
86
|
+
productType: {
|
|
87
|
+
typeId: 'product-type',
|
|
88
|
+
id: 'some-uuid',
|
|
89
|
+
},
|
|
90
|
+
masterVariant: {
|
|
91
|
+
sku: '1337',
|
|
92
|
+
prices: [
|
|
93
|
+
{
|
|
94
|
+
value: {
|
|
95
|
+
type: 'centPrecision',
|
|
96
|
+
currencyCode: 'EUR',
|
|
97
|
+
centAmount: 14900,
|
|
98
|
+
fractionDigits: 2,
|
|
99
|
+
} as CentPrecisionMoney,
|
|
100
|
+
},
|
|
101
|
+
],
|
|
102
|
+
|
|
103
|
+
attributes: [
|
|
104
|
+
{
|
|
105
|
+
name: 'test',
|
|
106
|
+
value: 'test',
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
},
|
|
110
|
+
variants: [
|
|
111
|
+
{
|
|
112
|
+
sku: '1338',
|
|
113
|
+
prices: [
|
|
114
|
+
{
|
|
115
|
+
value: {
|
|
116
|
+
type: 'centPrecision',
|
|
117
|
+
currencyCode: 'EUR',
|
|
118
|
+
centAmount: 14900,
|
|
119
|
+
fractionDigits: 2,
|
|
120
|
+
} as CentPrecisionMoney,
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
attributes: [
|
|
124
|
+
{
|
|
125
|
+
name: 'test2',
|
|
126
|
+
value: 'test2',
|
|
127
|
+
},
|
|
128
|
+
],
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
slug: {
|
|
132
|
+
'nl-NL': 'test-product',
|
|
133
|
+
},
|
|
134
|
+
publish: true,
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
beforeEach(async () => {
|
|
138
|
+
let response = await supertest(ctMock.app)
|
|
139
|
+
.post('/dummy/carts')
|
|
140
|
+
.send({
|
|
141
|
+
currency: 'EUR',
|
|
142
|
+
})
|
|
143
|
+
expect(response.status).toBe(201)
|
|
144
|
+
cart = response.body
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
afterEach(() => {
|
|
148
|
+
ctMock.clear()
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('no update', async () => {
|
|
152
|
+
assert(cart, 'cart not created')
|
|
153
|
+
|
|
154
|
+
const response = await supertest(ctMock.app)
|
|
155
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
156
|
+
.send({
|
|
157
|
+
version: 1,
|
|
158
|
+
actions: [{ action: 'setLocale', locale: 'nl-NL' }],
|
|
159
|
+
})
|
|
160
|
+
expect(response.status).toBe(200)
|
|
161
|
+
expect(response.body.version).toBe(2)
|
|
162
|
+
expect(response.body.locale).toBe('nl-NL')
|
|
163
|
+
|
|
164
|
+
const responseAgain = await supertest(ctMock.app)
|
|
165
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
166
|
+
.send({
|
|
167
|
+
version: 2,
|
|
168
|
+
actions: [{ action: 'setLocale', locale: 'nl-NL' }],
|
|
169
|
+
})
|
|
170
|
+
expect(responseAgain.status).toBe(200)
|
|
171
|
+
expect(responseAgain.body.version).toBe(2)
|
|
172
|
+
expect(responseAgain.body.locale).toBe('nl-NL')
|
|
173
|
+
})
|
|
174
|
+
|
|
175
|
+
test('addLineItem', async () => {
|
|
176
|
+
const product = await supertest(ctMock.app)
|
|
177
|
+
.post(`/dummy/products`)
|
|
178
|
+
.send(productDraft)
|
|
179
|
+
.then(x => x.body)
|
|
180
|
+
|
|
181
|
+
assert(cart, 'cart not created')
|
|
182
|
+
assert(product, 'product not created')
|
|
183
|
+
|
|
184
|
+
const response = await supertest(ctMock.app)
|
|
185
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
186
|
+
.send({
|
|
187
|
+
version: 1,
|
|
188
|
+
actions: [
|
|
189
|
+
{
|
|
190
|
+
action: 'addLineItem',
|
|
191
|
+
productId: product.id,
|
|
192
|
+
variantId: product.masterData.current.variants[0].id,
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
})
|
|
196
|
+
expect(response.status).toBe(200)
|
|
197
|
+
expect(response.body.version).toBe(2)
|
|
198
|
+
expect(response.body.lineItems).toHaveLength(1)
|
|
199
|
+
expect(response.body.totalPrice.centAmount).toEqual(14900)
|
|
200
|
+
})
|
|
201
|
+
|
|
202
|
+
test('addLineItem by SKU', async () => {
|
|
203
|
+
const product = await supertest(ctMock.app)
|
|
204
|
+
.post(`/dummy/products`)
|
|
205
|
+
.send(productDraft)
|
|
206
|
+
.then(x => x.body)
|
|
207
|
+
|
|
208
|
+
assert(cart, 'cart not created')
|
|
209
|
+
assert(product, 'product not created')
|
|
210
|
+
|
|
211
|
+
const response = await supertest(ctMock.app)
|
|
212
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
213
|
+
.send({
|
|
214
|
+
version: 1,
|
|
215
|
+
actions: [{ action: 'addLineItem', sku: '1337', quantity: 2 }],
|
|
216
|
+
})
|
|
217
|
+
expect(response.status).toBe(200)
|
|
218
|
+
expect(response.body.version).toBe(2)
|
|
219
|
+
expect(response.body.lineItems).toHaveLength(1)
|
|
220
|
+
expect(response.body.totalPrice.centAmount).toEqual(29800)
|
|
221
|
+
})
|
|
222
|
+
|
|
223
|
+
test('addLineItem unknown product', async () => {
|
|
224
|
+
assert(cart, 'cart not created')
|
|
225
|
+
|
|
226
|
+
const response = await supertest(ctMock.app)
|
|
227
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
228
|
+
.send({
|
|
229
|
+
version: 1,
|
|
230
|
+
actions: [{ action: 'addLineItem', productId: '123', variantId: 1 }],
|
|
231
|
+
})
|
|
232
|
+
expect(response.status).toBe(400)
|
|
233
|
+
expect(response.body.message).toBe("A product with ID '123' not found.")
|
|
234
|
+
})
|
|
235
|
+
|
|
236
|
+
test('removeLineItem', async () => {
|
|
237
|
+
const product = await supertest(ctMock.app)
|
|
238
|
+
.post(`/dummy/products`)
|
|
239
|
+
.send(productDraft)
|
|
240
|
+
.then(x => x.body)
|
|
241
|
+
|
|
242
|
+
assert(cart, 'cart not created')
|
|
243
|
+
assert(product, 'product not created')
|
|
244
|
+
|
|
245
|
+
const updatedCart = await supertest(ctMock.app)
|
|
246
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
247
|
+
.send({
|
|
248
|
+
version: 1,
|
|
249
|
+
actions: [
|
|
250
|
+
{
|
|
251
|
+
action: 'addLineItem',
|
|
252
|
+
productId: product.id,
|
|
253
|
+
variantId: product.masterData.current.variants[0].id,
|
|
254
|
+
},
|
|
255
|
+
],
|
|
256
|
+
})
|
|
257
|
+
const lineItem = updatedCart.body.lineItems[0]
|
|
258
|
+
assert(lineItem, 'lineItem not created')
|
|
259
|
+
|
|
260
|
+
expect(updatedCart.body.lineItems).toHaveLength(1)
|
|
261
|
+
|
|
262
|
+
const response = await supertest(ctMock.app)
|
|
263
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
264
|
+
.send({
|
|
265
|
+
version: updatedCart.body.version,
|
|
266
|
+
actions: [{ action: 'removeLineItem', lineItemId: lineItem.id }],
|
|
267
|
+
})
|
|
268
|
+
expect(response.status).toBe(200)
|
|
269
|
+
expect(response.body.version).toBe(3)
|
|
270
|
+
expect(response.body.lineItems).toHaveLength(0)
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
test('removeLineItem decrease quantity', async () => {
|
|
274
|
+
const product = await supertest(ctMock.app)
|
|
275
|
+
.post(`/dummy/products`)
|
|
276
|
+
.send(productDraft)
|
|
277
|
+
.then(x => x.body)
|
|
278
|
+
|
|
279
|
+
assert(cart, 'cart not created')
|
|
280
|
+
assert(product, 'product not created')
|
|
281
|
+
|
|
282
|
+
const updatedCart = await supertest(ctMock.app)
|
|
283
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
284
|
+
.send({
|
|
285
|
+
version: 1,
|
|
286
|
+
actions: [
|
|
287
|
+
{
|
|
288
|
+
action: 'addLineItem',
|
|
289
|
+
productId: product.id,
|
|
290
|
+
variantId: product.masterData.current.variants[0].id,
|
|
291
|
+
quantity: 2,
|
|
292
|
+
},
|
|
293
|
+
],
|
|
294
|
+
})
|
|
295
|
+
const lineItem = updatedCart.body.lineItems[0]
|
|
296
|
+
assert(lineItem, 'lineItem not created')
|
|
297
|
+
|
|
298
|
+
expect(updatedCart.body.lineItems).toHaveLength(1)
|
|
299
|
+
expect(updatedCart.body.lineItems[0].quantity).toBe(2)
|
|
300
|
+
|
|
301
|
+
const response = await supertest(ctMock.app)
|
|
302
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
303
|
+
.send({
|
|
304
|
+
version: updatedCart.body.version,
|
|
305
|
+
actions: [
|
|
306
|
+
{ action: 'removeLineItem', lineItemId: lineItem.id, quantity: 1 },
|
|
307
|
+
],
|
|
308
|
+
})
|
|
309
|
+
expect(response.status).toBe(200)
|
|
310
|
+
expect(response.body.version).toBe(3)
|
|
311
|
+
expect(response.body.lineItems).toHaveLength(1)
|
|
312
|
+
expect(response.body.lineItems[0].quantity).toBe(1)
|
|
313
|
+
})
|
|
314
|
+
|
|
315
|
+
test('setBillingAddress', async () => {
|
|
316
|
+
assert(cart, 'cart not created')
|
|
317
|
+
|
|
318
|
+
const address: Address = {
|
|
319
|
+
streetName: 'Street name',
|
|
320
|
+
city: 'Utrecht',
|
|
321
|
+
country: 'NL',
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
const response = await supertest(ctMock.app)
|
|
325
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
326
|
+
.send({
|
|
327
|
+
version: 1,
|
|
328
|
+
actions: [{ action: 'setBillingAddress', address }],
|
|
329
|
+
})
|
|
330
|
+
expect(response.status).toBe(200)
|
|
331
|
+
expect(response.body.version).toBe(2)
|
|
332
|
+
expect(response.body.billingAddress).toEqual(address)
|
|
333
|
+
})
|
|
334
|
+
|
|
335
|
+
test('setCountry', async () => {
|
|
336
|
+
assert(cart, 'cart not created')
|
|
337
|
+
|
|
338
|
+
const response = await supertest(ctMock.app)
|
|
339
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
340
|
+
.send({
|
|
341
|
+
version: 1,
|
|
342
|
+
actions: [{ action: 'setCountry', country: 'NL' }],
|
|
343
|
+
})
|
|
344
|
+
expect(response.status).toBe(200)
|
|
345
|
+
expect(response.body.version).toBe(2)
|
|
346
|
+
expect(response.body.country).toBe('NL')
|
|
347
|
+
})
|
|
348
|
+
|
|
349
|
+
test('setCustomerEmail', async () => {
|
|
350
|
+
assert(cart, 'cart not created')
|
|
351
|
+
|
|
352
|
+
const response = await supertest(ctMock.app)
|
|
353
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
354
|
+
.send({
|
|
355
|
+
version: 1,
|
|
356
|
+
actions: [{ action: 'setCustomerEmail', email: 'john@doe.com' }],
|
|
357
|
+
})
|
|
358
|
+
expect(response.status).toBe(200)
|
|
359
|
+
expect(response.body.version).toBe(2)
|
|
360
|
+
expect(response.body.customerEmail).toBe('john@doe.com')
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
test('setShippingAddress', async () => {
|
|
364
|
+
assert(cart, 'cart not created')
|
|
365
|
+
|
|
366
|
+
const address: Address = {
|
|
367
|
+
streetName: 'Street name',
|
|
368
|
+
city: 'Utrecht',
|
|
369
|
+
country: 'NL',
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
const response = await supertest(ctMock.app)
|
|
373
|
+
.post(`/dummy/carts/${cart.id}`)
|
|
374
|
+
.send({
|
|
375
|
+
version: 1,
|
|
376
|
+
actions: [{ action: 'setShippingAddress', address }],
|
|
377
|
+
})
|
|
378
|
+
expect(response.status).toBe(200)
|
|
379
|
+
expect(response.body.version).toBe(2)
|
|
380
|
+
expect(response.body.shippingAddress).toEqual(address)
|
|
381
|
+
})
|
|
382
|
+
})
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Category } from '@commercetools/platform-sdk'
|
|
2
|
+
import supertest from 'supertest'
|
|
3
|
+
import { CommercetoolsMock } from '../index'
|
|
4
|
+
|
|
5
|
+
describe('Categories Query', () => {
|
|
6
|
+
const ctMock = new CommercetoolsMock()
|
|
7
|
+
|
|
8
|
+
beforeEach(async () => {
|
|
9
|
+
let response
|
|
10
|
+
response = await supertest(ctMock.app)
|
|
11
|
+
.post('/dummy/categories')
|
|
12
|
+
.send({
|
|
13
|
+
name: {
|
|
14
|
+
en: 'Top hat',
|
|
15
|
+
},
|
|
16
|
+
slug: {
|
|
17
|
+
en: 'top-hat',
|
|
18
|
+
},
|
|
19
|
+
orderHint: '0.1',
|
|
20
|
+
})
|
|
21
|
+
expect(response.status).toBe(201)
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
test('no filter', async () => {
|
|
25
|
+
const response = await supertest(ctMock.app)
|
|
26
|
+
.get('/dummy/categories')
|
|
27
|
+
.query({})
|
|
28
|
+
.send()
|
|
29
|
+
|
|
30
|
+
expect(response.status).toBe(200)
|
|
31
|
+
expect(response.body.count).toBe(1)
|
|
32
|
+
|
|
33
|
+
const category = response.body.results[0] as Category
|
|
34
|
+
|
|
35
|
+
expect(category.name.en).toBe('Top hat')
|
|
36
|
+
})
|
|
37
|
+
})
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Router } from 'express'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { CategoryRepository } from '../repositories/category'
|
|
5
|
+
|
|
6
|
+
export class CategoryServices extends AbstractService {
|
|
7
|
+
public repository: CategoryRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new CategoryRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'categories'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Router } from 'express'
|
|
3
|
+
import { ChannelRepository } from '../repositories/channel'
|
|
4
|
+
import { AbstractStorage } from '../storage'
|
|
5
|
+
|
|
6
|
+
export class ChannelService extends AbstractService {
|
|
7
|
+
public repository: ChannelRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new ChannelRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'channels'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -15,7 +15,7 @@ describe('CustomObject create', () => {
|
|
|
15
15
|
value: 'my-value',
|
|
16
16
|
})
|
|
17
17
|
|
|
18
|
-
expect(response.status).toBe(
|
|
18
|
+
expect(response.status).toBe(201)
|
|
19
19
|
const customObject = response.body
|
|
20
20
|
expect(customObject.container).toBe('my-container')
|
|
21
21
|
expect(customObject.key).toBe('my-key')
|
|
@@ -36,7 +36,7 @@ describe('CustomObject retrieve', () => {
|
|
|
36
36
|
value: 'my-value',
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
expect(response.status).toBe(
|
|
39
|
+
expect(response.status).toBe(201)
|
|
40
40
|
customObject = response.body
|
|
41
41
|
expect(customObject.container).toBe('my-container')
|
|
42
42
|
expect(customObject.key).toBe('my-key')
|
|
@@ -67,7 +67,7 @@ describe('CustomObject retrieve', () => {
|
|
|
67
67
|
value: 'my-value',
|
|
68
68
|
})
|
|
69
69
|
|
|
70
|
-
expect(response.status).toBe(
|
|
70
|
+
expect(response.status).toBe(201)
|
|
71
71
|
})
|
|
72
72
|
|
|
73
73
|
test('New with version (errors)', async () => {
|
|
@@ -141,4 +141,54 @@ describe('CustomObject retrieve', () => {
|
|
|
141
141
|
version: 1,
|
|
142
142
|
})
|
|
143
143
|
})
|
|
144
|
+
|
|
145
|
+
test('update with container and key', async () => {
|
|
146
|
+
ctMock.project('dummy').add('custom-object', {
|
|
147
|
+
...getBaseResourceProperties(),
|
|
148
|
+
container: 'my-container',
|
|
149
|
+
key: 'my-key',
|
|
150
|
+
value: 'my-value',
|
|
151
|
+
version: 2,
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
const response = await supertest(ctMock.app)
|
|
155
|
+
.post('/dummy/custom-objects/my-container/my-key')
|
|
156
|
+
.send({
|
|
157
|
+
value: 'new-value',
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
expect(response.status).toEqual(200)
|
|
161
|
+
expect(response.body).toEqual({
|
|
162
|
+
container: 'my-container',
|
|
163
|
+
createdAt: expect.anything(),
|
|
164
|
+
id: expect.anything(),
|
|
165
|
+
key: 'my-key',
|
|
166
|
+
lastModifiedAt: expect.anything(),
|
|
167
|
+
value: 'new-value',
|
|
168
|
+
version: 2,
|
|
169
|
+
})
|
|
170
|
+
})
|
|
171
|
+
|
|
172
|
+
test('delete with container and key', async () => {
|
|
173
|
+
const response = await supertest(ctMock.app)
|
|
174
|
+
.delete('/dummy/custom-objects/my-container/my-key')
|
|
175
|
+
.send()
|
|
176
|
+
|
|
177
|
+
expect(response.status).toEqual(200)
|
|
178
|
+
expect(response.body).toEqual({
|
|
179
|
+
container: 'my-container',
|
|
180
|
+
createdAt: expect.anything(),
|
|
181
|
+
id: expect.anything(),
|
|
182
|
+
key: 'my-key',
|
|
183
|
+
lastModifiedAt: expect.anything(),
|
|
184
|
+
value: 'my-value',
|
|
185
|
+
version: 1,
|
|
186
|
+
})
|
|
187
|
+
|
|
188
|
+
const fetchRes = await supertest(ctMock.app)
|
|
189
|
+
.get('/dummy/custom-objects/my-container/my-key')
|
|
190
|
+
.send()
|
|
191
|
+
|
|
192
|
+
expect(fetchRes.status).toEqual(404)
|
|
193
|
+
})
|
|
144
194
|
})
|
|
@@ -2,6 +2,7 @@ import AbstractService from './abstract'
|
|
|
2
2
|
import { Request, Response, Router } from 'express'
|
|
3
3
|
import { CustomObjectRepository } from '../repositories/custom-object'
|
|
4
4
|
import { AbstractStorage } from '../storage'
|
|
5
|
+
import { CustomObjectDraft } from '@commercetools/platform-sdk'
|
|
5
6
|
|
|
6
7
|
export class CustomObjectService extends AbstractService {
|
|
7
8
|
public repository: CustomObjectRepository
|
|
@@ -17,6 +18,8 @@ export class CustomObjectService extends AbstractService {
|
|
|
17
18
|
|
|
18
19
|
extraRoutes(router: Router) {
|
|
19
20
|
router.get('/:container/:key', this.getWithContainerAndKey.bind(this))
|
|
21
|
+
router.post('/:container/:key', this.createWithContainerAndKey.bind(this))
|
|
22
|
+
router.delete('/:container/:key', this.deleteWithContainerAndKey.bind(this))
|
|
20
23
|
}
|
|
21
24
|
|
|
22
25
|
getWithContainerAndKey(request: Request, response: Response) {
|
|
@@ -31,4 +34,31 @@ export class CustomObjectService extends AbstractService {
|
|
|
31
34
|
}
|
|
32
35
|
return response.status(200).send(result)
|
|
33
36
|
}
|
|
37
|
+
|
|
38
|
+
createWithContainerAndKey(request: Request, response: Response) {
|
|
39
|
+
const draft: CustomObjectDraft = {
|
|
40
|
+
...request.body,
|
|
41
|
+
key: request.params.key,
|
|
42
|
+
container: request.params.container,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const result = this.repository.create(request.params.projectKey, draft)
|
|
46
|
+
return response.status(200).send(result)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
deleteWithContainerAndKey(request: Request, response: Response) {
|
|
50
|
+
const current = this.repository.getWithContainerAndKey(
|
|
51
|
+
request.params.projectKey,
|
|
52
|
+
request.params.container,
|
|
53
|
+
request.params.key
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
if (!current) {
|
|
57
|
+
return response.status(404).send('Not Found')
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const result = this.repository.delete(request.params.projectKey, current.id)
|
|
61
|
+
|
|
62
|
+
return response.status(200).send(result)
|
|
63
|
+
}
|
|
34
64
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import AbstractService from './abstract'
|
|
2
|
+
import { Router } from 'express'
|
|
3
|
+
import { CustomerGroupRepository } from '../repositories/customer-group'
|
|
4
|
+
import { AbstractStorage } from '../storage'
|
|
5
|
+
|
|
6
|
+
export class CustomerGroupService extends AbstractService {
|
|
7
|
+
public repository: CustomerGroupRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new CustomerGroupRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'customer-groups'
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Router } from 'express'
|
|
2
|
+
import AbstractService from './abstract'
|
|
3
|
+
import { AbstractStorage } from '../storage'
|
|
4
|
+
import { DiscountCodeRepository } from '../repositories/discount-code'
|
|
5
|
+
|
|
6
|
+
export class DiscountCodeService extends AbstractService {
|
|
7
|
+
public repository: DiscountCodeRepository
|
|
8
|
+
|
|
9
|
+
constructor(parent: Router, storage: AbstractStorage) {
|
|
10
|
+
super(parent)
|
|
11
|
+
this.repository = new DiscountCodeRepository(storage)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
getBasePath() {
|
|
15
|
+
return 'discount-codes'
|
|
16
|
+
}
|
|
17
|
+
}
|