@labdigital/commercetools-mock 1.5.0 → 1.6.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 +5 -4
- package/dist/index.cjs +117 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +30 -7
- package/dist/index.d.ts +30 -7
- package/dist/index.js +117 -17
- package/dist/index.js.map +1 -1
- package/package.json +4 -3
- package/src/constants.ts +2 -2
- package/src/ctMock.ts +176 -176
- package/src/exceptions.ts +10 -10
- package/src/helpers.ts +26 -26
- package/src/index.test.ts +173 -173
- package/src/index.ts +3 -3
- package/src/lib/expandParser.ts +19 -19
- package/src/lib/haversine.test.ts +13 -13
- package/src/lib/haversine.ts +14 -14
- package/src/lib/masking.ts +15 -15
- package/src/lib/parser.ts +2 -2
- package/src/lib/predicateParser.test.ts +204 -204
- package/src/lib/predicateParser.ts +398 -398
- package/src/lib/projectionSearchFilter.test.ts +168 -168
- package/src/lib/projectionSearchFilter.ts +272 -269
- package/src/lib/proxy.ts +8 -8
- package/src/oauth/errors.ts +4 -4
- package/src/oauth/helpers.ts +6 -6
- package/src/oauth/server.ts +103 -101
- package/src/oauth/store.ts +27 -27
- package/src/priceSelector.test.ts +68 -68
- package/src/priceSelector.ts +70 -70
- package/src/product-projection-search.ts +296 -296
- package/src/projectAPI.test.ts +3 -3
- package/src/projectAPI.ts +46 -46
- package/src/repositories/abstract.ts +190 -190
- package/src/repositories/associate-role.ts +10 -7
- package/src/repositories/attribute-group.ts +63 -8
- package/src/repositories/business-unit.ts +10 -7
- package/src/repositories/cart-discount.ts +134 -134
- package/src/repositories/cart.ts +517 -514
- package/src/repositories/category.ts +170 -167
- package/src/repositories/channel.ts +114 -111
- package/src/repositories/custom-object.ts +66 -63
- package/src/repositories/customer-group.ts +72 -69
- package/src/repositories/customer.ts +90 -90
- package/src/repositories/discount-code.ts +171 -168
- package/src/repositories/errors.ts +15 -15
- package/src/repositories/extension.ts +79 -76
- package/src/repositories/helpers.ts +180 -180
- package/src/repositories/index.ts +39 -39
- package/src/repositories/inventory-entry.ts +98 -95
- package/src/repositories/my-order.ts +11 -11
- package/src/repositories/order-edit.ts +29 -29
- package/src/repositories/order.test.ts +191 -191
- package/src/repositories/order.ts +393 -393
- package/src/repositories/payment.ts +155 -155
- package/src/repositories/product-discount.ts +149 -149
- package/src/repositories/product-projection.ts +135 -50
- package/src/repositories/product-selection.ts +31 -31
- package/src/repositories/product-type.ts +156 -156
- package/src/repositories/product.ts +600 -597
- package/src/repositories/project.ts +136 -135
- package/src/repositories/quote-request.ts +19 -19
- package/src/repositories/quote.ts +19 -19
- package/src/repositories/review.ts +24 -24
- package/src/repositories/shipping-method.ts +217 -217
- package/src/repositories/shopping-list.ts +49 -49
- package/src/repositories/staged-quote.ts +20 -20
- package/src/repositories/standalone-price.ts +72 -61
- package/src/repositories/state.ts +84 -84
- package/src/repositories/store.ts +114 -114
- package/src/repositories/subscription.ts +40 -40
- package/src/repositories/tax-category.ts +98 -98
- package/src/repositories/type.ts +157 -157
- package/src/repositories/zone.ts +71 -71
- package/src/server.ts +2 -2
- package/src/services/abstract.ts +173 -173
- package/src/services/attribute-group.ts +16 -0
- package/src/services/cart-discount.ts +8 -8
- package/src/services/cart.test.ts +409 -409
- package/src/services/cart.ts +50 -50
- package/src/services/category.test.ts +25 -25
- package/src/services/category.ts +8 -8
- package/src/services/channel.ts +8 -8
- package/src/services/custom-object.test.ts +184 -184
- package/src/services/custom-object.ts +48 -48
- package/src/services/customer-group.ts +8 -8
- package/src/services/customer.test.ts +151 -151
- package/src/services/customer.ts +27 -27
- package/src/services/discount-code.ts +8 -8
- package/src/services/extension.ts +8 -8
- package/src/services/index.ts +52 -44
- package/src/services/inventory-entry.test.ts +162 -162
- package/src/services/inventory-entry.ts +8 -8
- package/src/services/my-cart.test.ts +78 -78
- package/src/services/my-cart.ts +28 -28
- package/src/services/my-customer.test.ts +44 -44
- package/src/services/my-customer.ts +53 -53
- package/src/services/my-order.ts +20 -20
- package/src/services/my-payment.test.ts +65 -65
- package/src/services/my-payment.ts +8 -8
- package/src/services/order.test.ts +527 -527
- package/src/services/order.ts +31 -31
- package/src/services/payment.test.ts +65 -65
- package/src/services/payment.ts +8 -8
- package/src/services/product-discount.ts +8 -8
- package/src/services/product-projection.test.ts +502 -428
- package/src/services/product-projection.ts +32 -18
- package/src/services/product-type.test.ts +56 -56
- package/src/services/product-type.ts +8 -8
- package/src/services/product.test.ts +510 -510
- package/src/services/product.ts +8 -8
- package/src/services/project.ts +34 -34
- package/src/services/shipping-method.test.ts +81 -81
- package/src/services/shipping-method.ts +12 -12
- package/src/services/shopping-list.ts +8 -8
- package/src/services/standalone-price.test.ts +256 -256
- package/src/services/standalone-price.ts +8 -8
- package/src/services/state.test.ts +42 -42
- package/src/services/state.ts +8 -8
- package/src/services/store.test.ts +57 -57
- package/src/services/store.ts +8 -8
- package/src/services/subscription.ts +8 -8
- package/src/services/tax-category.test.ts +61 -61
- package/src/services/tax-category.ts +8 -8
- package/src/services/type.ts +8 -8
- package/src/services/zone.ts +8 -8
- package/src/storage/abstract.ts +58 -58
- package/src/storage/in-memory.ts +419 -419
- package/src/types.ts +82 -82
|
@@ -5,540 +5,540 @@ import { afterEach, beforeEach, describe, expect, test } from 'vitest'
|
|
|
5
5
|
import { CommercetoolsMock, getBaseResourceProperties } from '../index.js'
|
|
6
6
|
|
|
7
7
|
describe('Order Query', () => {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
8
|
+
const ctMock = new CommercetoolsMock()
|
|
9
|
+
let order: Order | undefined
|
|
10
|
+
|
|
11
|
+
beforeEach(async () => {
|
|
12
|
+
let response = await supertest(ctMock.app)
|
|
13
|
+
.post('/dummy/carts')
|
|
14
|
+
.send({
|
|
15
|
+
currency: 'EUR',
|
|
16
|
+
custom: {
|
|
17
|
+
type: {
|
|
18
|
+
key: 'my-cart',
|
|
19
|
+
},
|
|
20
|
+
fields: {
|
|
21
|
+
description: 'example description',
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
})
|
|
25
|
+
expect(response.status).toBe(201)
|
|
26
|
+
const cart = response.body
|
|
27
|
+
|
|
28
|
+
response = await supertest(ctMock.app)
|
|
29
|
+
.post('/dummy/orders')
|
|
30
|
+
.send({
|
|
31
|
+
cart: {
|
|
32
|
+
typeId: 'cart',
|
|
33
|
+
id: cart.id,
|
|
34
|
+
},
|
|
35
|
+
orderNumber: 'foobar',
|
|
36
|
+
})
|
|
37
|
+
expect(response.status).toBe(201)
|
|
38
|
+
order = response.body
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
afterEach(() => {
|
|
42
|
+
ctMock.clear()
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
test('no filter', async () => {
|
|
46
|
+
assert(order, 'order not created')
|
|
47
|
+
|
|
48
|
+
const response = await supertest(ctMock.app).get(`/dummy/orders`)
|
|
49
|
+
expect(response.status).toBe(200)
|
|
50
|
+
expect(response.body.count).toBe(1)
|
|
51
|
+
expect(response.body.total).toBe(1)
|
|
52
|
+
expect(response.body.offset).toBe(0)
|
|
53
|
+
expect(response.body.limit).toBe(20)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
test('filter orderNumber', async () => {
|
|
57
|
+
assert(order, 'order not created')
|
|
58
|
+
|
|
59
|
+
{
|
|
60
|
+
const response = await supertest(ctMock.app)
|
|
61
|
+
.get(`/dummy/orders`)
|
|
62
|
+
.query({ where: 'orderNumber="nomatch"' })
|
|
63
|
+
expect(response.status).toBe(200)
|
|
64
|
+
expect(response.body.count).toBe(0)
|
|
65
|
+
}
|
|
66
|
+
{
|
|
67
|
+
const response = await supertest(ctMock.app)
|
|
68
|
+
.get(`/dummy/orders`)
|
|
69
|
+
.query({ where: 'orderNumber="foobar"' })
|
|
70
|
+
expect(response.status).toBe(200)
|
|
71
|
+
expect(response.body.count).toBe(1)
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('expand payment without payments', async () => {
|
|
76
|
+
assert(order, 'order not created')
|
|
77
|
+
|
|
78
|
+
const response = await supertest(ctMock.app)
|
|
79
|
+
.get(`/dummy/orders/${order.id}`)
|
|
80
|
+
.query({ expand: 'paymentInfo.payments[*].paymentStatus.state' })
|
|
81
|
+
|
|
82
|
+
expect(response.status).toBe(200)
|
|
83
|
+
expect(response.body.id).toBe(order.id)
|
|
84
|
+
})
|
|
85
85
|
})
|
|
86
86
|
|
|
87
87
|
describe('Order payment tests', () => {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
88
|
+
const ctMock = new CommercetoolsMock({
|
|
89
|
+
defaultProjectKey: 'dummy',
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
afterEach(() => {
|
|
93
|
+
ctMock.clear()
|
|
94
|
+
})
|
|
95
|
+
|
|
96
|
+
test('query payment id', async () => {
|
|
97
|
+
const state: State = {
|
|
98
|
+
...getBaseResourceProperties(),
|
|
99
|
+
builtIn: false,
|
|
100
|
+
initial: false,
|
|
101
|
+
key: 'PaymentSuccess',
|
|
102
|
+
type: 'PaymentState',
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const payment: Payment = {
|
|
106
|
+
...getBaseResourceProperties(),
|
|
107
|
+
interfaceInteractions: [],
|
|
108
|
+
paymentStatus: {
|
|
109
|
+
state: {
|
|
110
|
+
typeId: 'state',
|
|
111
|
+
id: state.id,
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
amountPlanned: {
|
|
115
|
+
type: 'centPrecision',
|
|
116
|
+
fractionDigits: 2,
|
|
117
|
+
centAmount: 1234,
|
|
118
|
+
currencyCode: 'EUR',
|
|
119
|
+
},
|
|
120
|
+
paymentMethodInfo: {
|
|
121
|
+
paymentInterface: 'buckaroo',
|
|
122
|
+
method: 'mastercard',
|
|
123
|
+
},
|
|
124
|
+
version: 2,
|
|
125
|
+
transactions: [
|
|
126
|
+
{
|
|
127
|
+
id: 'fake-transaction-id',
|
|
128
|
+
type: 'Charge',
|
|
129
|
+
amount: {
|
|
130
|
+
centAmount: 1234,
|
|
131
|
+
currencyCode: 'EUR',
|
|
132
|
+
type: 'centPrecision',
|
|
133
|
+
fractionDigits: 2,
|
|
134
|
+
},
|
|
135
|
+
state: 'Success',
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
const order: Order = {
|
|
141
|
+
...getBaseResourceProperties(),
|
|
142
|
+
customLineItems: [],
|
|
143
|
+
lastMessageSequenceNumber: 0,
|
|
144
|
+
lineItems: [],
|
|
145
|
+
orderNumber: '1337',
|
|
146
|
+
orderState: 'Open',
|
|
147
|
+
origin: 'Customer',
|
|
148
|
+
paymentInfo: {
|
|
149
|
+
payments: [
|
|
150
|
+
{
|
|
151
|
+
typeId: 'payment',
|
|
152
|
+
id: payment.id,
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
},
|
|
156
|
+
refusedGifts: [],
|
|
157
|
+
shipping: [],
|
|
158
|
+
shippingMode: 'Single',
|
|
159
|
+
syncInfo: [],
|
|
160
|
+
totalPrice: {
|
|
161
|
+
type: 'centPrecision',
|
|
162
|
+
fractionDigits: 2,
|
|
163
|
+
centAmount: 2000,
|
|
164
|
+
currencyCode: 'EUR',
|
|
165
|
+
},
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
ctMock.project().add('state', state)
|
|
169
|
+
ctMock.project().add('payment', payment)
|
|
170
|
+
ctMock.project().add('order', order)
|
|
171
|
+
|
|
172
|
+
const response = await supertest(ctMock.app)
|
|
173
|
+
.get(`/dummy/orders`)
|
|
174
|
+
.query({ where: `paymentInfo(payments(id="${payment.id}"))` })
|
|
175
|
+
|
|
176
|
+
expect(response.status).toBe(200)
|
|
177
|
+
expect(response.body.results[0].id).toBe(order.id)
|
|
178
|
+
|
|
179
|
+
{
|
|
180
|
+
const response = await supertest(ctMock.app)
|
|
181
|
+
.get(`/dummy/orders`)
|
|
182
|
+
.query({ where: `paymentInfo(payments(id is defined))` })
|
|
183
|
+
|
|
184
|
+
expect(response.status).toBe(200)
|
|
185
|
+
expect(response.body.results[0].id).toBe(order.id)
|
|
186
|
+
}
|
|
187
|
+
})
|
|
188
|
+
|
|
189
|
+
test('expand payment states', async () => {
|
|
190
|
+
const state: State = {
|
|
191
|
+
...getBaseResourceProperties(),
|
|
192
|
+
builtIn: false,
|
|
193
|
+
initial: false,
|
|
194
|
+
key: 'PaymentSuccess',
|
|
195
|
+
type: 'PaymentState',
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
const payment: Payment = {
|
|
199
|
+
...getBaseResourceProperties(),
|
|
200
|
+
interfaceInteractions: [],
|
|
201
|
+
paymentStatus: {
|
|
202
|
+
state: {
|
|
203
|
+
typeId: 'state',
|
|
204
|
+
id: state.id,
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
amountPlanned: {
|
|
208
|
+
type: 'centPrecision',
|
|
209
|
+
fractionDigits: 2,
|
|
210
|
+
centAmount: 1234,
|
|
211
|
+
currencyCode: 'EUR',
|
|
212
|
+
},
|
|
213
|
+
paymentMethodInfo: {
|
|
214
|
+
paymentInterface: 'buckaroo',
|
|
215
|
+
method: 'mastercard',
|
|
216
|
+
},
|
|
217
|
+
version: 2,
|
|
218
|
+
transactions: [
|
|
219
|
+
{
|
|
220
|
+
id: 'fake-transaction-id',
|
|
221
|
+
type: 'Charge',
|
|
222
|
+
amount: {
|
|
223
|
+
centAmount: 1234,
|
|
224
|
+
currencyCode: 'EUR',
|
|
225
|
+
type: 'centPrecision',
|
|
226
|
+
fractionDigits: 2,
|
|
227
|
+
},
|
|
228
|
+
state: 'Success',
|
|
229
|
+
},
|
|
230
|
+
],
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const order: Order = {
|
|
234
|
+
...getBaseResourceProperties(),
|
|
235
|
+
customLineItems: [],
|
|
236
|
+
lastMessageSequenceNumber: 0,
|
|
237
|
+
lineItems: [],
|
|
238
|
+
orderNumber: '1337',
|
|
239
|
+
orderState: 'Open',
|
|
240
|
+
origin: 'Customer',
|
|
241
|
+
paymentInfo: {
|
|
242
|
+
payments: [
|
|
243
|
+
{
|
|
244
|
+
typeId: 'payment',
|
|
245
|
+
id: payment.id,
|
|
246
|
+
},
|
|
247
|
+
],
|
|
248
|
+
},
|
|
249
|
+
refusedGifts: [],
|
|
250
|
+
shipping: [],
|
|
251
|
+
shippingMode: 'Single',
|
|
252
|
+
syncInfo: [],
|
|
253
|
+
totalPrice: {
|
|
254
|
+
type: 'centPrecision',
|
|
255
|
+
fractionDigits: 2,
|
|
256
|
+
centAmount: 2000,
|
|
257
|
+
currencyCode: 'EUR',
|
|
258
|
+
},
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
ctMock.project().add('state', state)
|
|
262
|
+
ctMock.project().add('payment', payment)
|
|
263
|
+
ctMock.project().add('order', order)
|
|
264
|
+
|
|
265
|
+
const response = await supertest(ctMock.app)
|
|
266
|
+
.get(`/dummy/orders/order-number=${order.orderNumber}`)
|
|
267
|
+
.query({ expand: 'paymentInfo.payments[*].paymentStatus.state' })
|
|
268
|
+
|
|
269
|
+
expect(response.status).toBe(200)
|
|
270
|
+
expect(response.body.id).toBe(order.id)
|
|
271
|
+
const maybePayment = response.body.paymentInfo.payments[0].obj
|
|
272
|
+
expect(maybePayment).toBeDefined()
|
|
273
|
+
expect(maybePayment.paymentStatus.state.obj).toBeDefined()
|
|
274
|
+
})
|
|
275
275
|
})
|
|
276
276
|
|
|
277
277
|
describe('Order Update Actions', () => {
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
278
|
+
const ctMock = new CommercetoolsMock()
|
|
279
|
+
let order: Order | undefined
|
|
280
|
+
|
|
281
|
+
beforeEach(async () => {
|
|
282
|
+
let response = await supertest(ctMock.app).post('/dummy/carts').send({
|
|
283
|
+
currency: 'EUR',
|
|
284
|
+
})
|
|
285
|
+
expect(response.status).toBe(201)
|
|
286
|
+
const cart = response.body
|
|
287
|
+
|
|
288
|
+
response = await supertest(ctMock.app)
|
|
289
|
+
.post('/dummy/orders')
|
|
290
|
+
.send({
|
|
291
|
+
cart: {
|
|
292
|
+
typeId: 'cart',
|
|
293
|
+
id: cart.id,
|
|
294
|
+
},
|
|
295
|
+
})
|
|
296
|
+
expect(response.status).toBe(201)
|
|
297
|
+
order = response.body
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
test('no update', async () => {
|
|
301
|
+
assert(order, 'order not created')
|
|
302
|
+
|
|
303
|
+
const response = await supertest(ctMock.app)
|
|
304
|
+
.post(`/dummy/orders/${order.id}`)
|
|
305
|
+
.send({
|
|
306
|
+
version: 1,
|
|
307
|
+
actions: [{ action: 'setLocale', locale: 'nl-NL' }],
|
|
308
|
+
})
|
|
309
|
+
expect(response.status).toBe(200)
|
|
310
|
+
expect(response.body.version).toBe(2)
|
|
311
|
+
expect(response.body.locale).toBe('nl-NL')
|
|
312
|
+
|
|
313
|
+
const responseAgain = await supertest(ctMock.app)
|
|
314
|
+
.post(`/dummy/orders/${order.id}`)
|
|
315
|
+
.send({
|
|
316
|
+
version: 2,
|
|
317
|
+
actions: [{ action: 'setLocale', locale: 'nl-NL' }],
|
|
318
|
+
})
|
|
319
|
+
expect(responseAgain.status).toBe(200)
|
|
320
|
+
expect(responseAgain.body.version).toBe(2)
|
|
321
|
+
expect(responseAgain.body.locale).toBe('nl-NL')
|
|
322
|
+
})
|
|
323
|
+
|
|
324
|
+
test('setOrderNumber', async () => {
|
|
325
|
+
assert(order, 'order not created')
|
|
326
|
+
|
|
327
|
+
const response = await supertest(ctMock.app)
|
|
328
|
+
.post(`/dummy/orders/${order.id}`)
|
|
329
|
+
.send({
|
|
330
|
+
version: 1,
|
|
331
|
+
actions: [{ action: 'setOrderNumber', orderNumber: '5000123' }],
|
|
332
|
+
})
|
|
333
|
+
expect(response.status).toBe(200)
|
|
334
|
+
expect(response.body.version).toBe(2)
|
|
335
|
+
expect(response.body.orderNumber).toBe('5000123')
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
test('changeOrderState', async () => {
|
|
339
|
+
assert(order, 'order not created')
|
|
340
|
+
|
|
341
|
+
const response = await supertest(ctMock.app)
|
|
342
|
+
.post(`/dummy/orders/${order.id}`)
|
|
343
|
+
.send({
|
|
344
|
+
version: 1,
|
|
345
|
+
actions: [{ action: 'changeOrderState', orderState: 'Complete' }],
|
|
346
|
+
})
|
|
347
|
+
expect(response.status).toBe(200)
|
|
348
|
+
expect(response.body.version).toBe(2)
|
|
349
|
+
expect(response.body.orderState).toBe('Complete')
|
|
350
|
+
})
|
|
351
|
+
|
|
352
|
+
test('changePaymentState | changeOrderState', async () => {
|
|
353
|
+
assert(order, 'order not created')
|
|
354
|
+
|
|
355
|
+
const response = await supertest(ctMock.app)
|
|
356
|
+
.post(`/dummy/orders/${order.id}`)
|
|
357
|
+
.send({
|
|
358
|
+
version: 1,
|
|
359
|
+
actions: [
|
|
360
|
+
{ action: 'changeOrderState', orderState: 'Cancelled' },
|
|
361
|
+
{ action: 'changePaymentState', paymentState: 'Failed' },
|
|
362
|
+
],
|
|
363
|
+
})
|
|
364
|
+
expect(response.status).toBe(200)
|
|
365
|
+
expect(response.body.version).toBe(3)
|
|
366
|
+
expect(response.body.orderState).toBe('Cancelled')
|
|
367
|
+
expect(response.body.paymentState).toBe('Failed')
|
|
368
|
+
})
|
|
369
369
|
})
|
|
370
370
|
|
|
371
371
|
describe('Order Import', () => {
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
372
|
+
const ctMock = new CommercetoolsMock()
|
|
373
|
+
ctMock.project('dummy').add('product', {
|
|
374
|
+
id: '15fc56ba-a74e-4cf8-b4b0-bada5c101541',
|
|
375
|
+
// @ts-ignore
|
|
376
|
+
masterData: {
|
|
377
|
+
// @ts-ignore
|
|
378
|
+
current: {
|
|
379
|
+
name: { 'nl-NL': 'Dummy' },
|
|
380
|
+
slug: { 'nl-NL': 'Dummy' },
|
|
381
|
+
categories: [],
|
|
382
|
+
masterVariant: {
|
|
383
|
+
id: 0,
|
|
384
|
+
sku: 'MYSKU',
|
|
385
|
+
},
|
|
386
|
+
variants: [],
|
|
387
|
+
},
|
|
388
|
+
},
|
|
389
|
+
})
|
|
390
|
+
|
|
391
|
+
test('Import', async () => {
|
|
392
|
+
const response = await supertest(ctMock.app)
|
|
393
|
+
.post(`/dummy/orders/import`)
|
|
394
|
+
.send({
|
|
395
|
+
orderNumber: '100000001',
|
|
396
|
+
totalPrice: {
|
|
397
|
+
centAmount: 1000,
|
|
398
|
+
currencyCode: 'EUR',
|
|
399
|
+
},
|
|
400
|
+
customLineItems: [
|
|
401
|
+
{
|
|
402
|
+
name: {
|
|
403
|
+
'nl-NL': 'Something',
|
|
404
|
+
},
|
|
405
|
+
slug: 'my-slug',
|
|
406
|
+
money: {
|
|
407
|
+
centAmount: 1475,
|
|
408
|
+
currencyCode: 'EUR',
|
|
409
|
+
},
|
|
410
|
+
quantity: 1,
|
|
411
|
+
// custom: {
|
|
412
|
+
// type: {
|
|
413
|
+
// typeId: 'type',
|
|
414
|
+
// key: 'myCustomLineItem',
|
|
415
|
+
// },
|
|
416
|
+
// fields: {
|
|
417
|
+
// myCustomField: 'myCustomValeu',
|
|
418
|
+
// },
|
|
419
|
+
// },
|
|
420
|
+
},
|
|
421
|
+
],
|
|
422
|
+
lineItems: [
|
|
423
|
+
{
|
|
424
|
+
id: '15fc56ba-a74e-4cf8-b4b0-bada5c101541',
|
|
425
|
+
productId: 'PRODUCTID',
|
|
426
|
+
name: {
|
|
427
|
+
'en-US': 'The product',
|
|
428
|
+
},
|
|
429
|
+
productType: {
|
|
430
|
+
typeId: 'product-type',
|
|
431
|
+
id: '109caecb-abe6-4900-ab03-7af5af985ff3',
|
|
432
|
+
// @ts-ignore
|
|
433
|
+
version: 1,
|
|
434
|
+
},
|
|
435
|
+
variant: {
|
|
436
|
+
id: 1,
|
|
437
|
+
sku: 'MYSKU',
|
|
438
|
+
key: 'MYKEY',
|
|
439
|
+
prices: [
|
|
440
|
+
{
|
|
441
|
+
value: {
|
|
442
|
+
type: 'centPrecision',
|
|
443
|
+
currencyCode: 'EUR',
|
|
444
|
+
centAmount: 14900,
|
|
445
|
+
fractionDigits: 2,
|
|
446
|
+
},
|
|
447
|
+
id: '87943be5-c7e6-44eb-b867-f127f94ccfe7',
|
|
448
|
+
country: 'NL',
|
|
449
|
+
// channel: {
|
|
450
|
+
// typeId: 'channel',
|
|
451
|
+
// id: '411485eb-7875-46f4-8d40-1db9e61374ed',
|
|
452
|
+
// },
|
|
453
|
+
// custom: {
|
|
454
|
+
// type: {
|
|
455
|
+
// typeId: 'type',
|
|
456
|
+
// id: '55071385-b6e4-44c4-8c4b-6f2ec0f23649',
|
|
457
|
+
// },
|
|
458
|
+
// fields: {},
|
|
459
|
+
// },
|
|
460
|
+
},
|
|
461
|
+
],
|
|
462
|
+
images: [],
|
|
463
|
+
attributes: [],
|
|
464
|
+
assets: [],
|
|
465
|
+
},
|
|
466
|
+
price: {
|
|
467
|
+
value: {
|
|
468
|
+
type: 'centPrecision',
|
|
469
|
+
currencyCode: 'EUR',
|
|
470
|
+
centAmount: 14900,
|
|
471
|
+
fractionDigits: 2,
|
|
472
|
+
},
|
|
473
|
+
id: '87943be5-c7e6-44eb-b867-f127f94ccfe7',
|
|
474
|
+
country: 'NL',
|
|
475
|
+
// channel: {
|
|
476
|
+
// typeId: 'channel',
|
|
477
|
+
// id: '411485eb-7875-46f4-8d40-1db9e61374ed',
|
|
478
|
+
// },
|
|
479
|
+
// custom: {
|
|
480
|
+
// type: {
|
|
481
|
+
// typeId: 'type',
|
|
482
|
+
// id: '55071385-b6e4-44c4-8c4b-6f2ec0f23649',
|
|
483
|
+
// },
|
|
484
|
+
// fields: {},
|
|
485
|
+
// },
|
|
486
|
+
},
|
|
487
|
+
quantity: 3,
|
|
488
|
+
discountedPricePerQuantity: [],
|
|
489
|
+
// distributionChannel: {
|
|
490
|
+
// typeId: 'channel',
|
|
491
|
+
// id: '411485eb-7875-46f4-8d40-1db9e61374ed',
|
|
492
|
+
// },
|
|
493
|
+
taxRate: {
|
|
494
|
+
name: '21% BTW',
|
|
495
|
+
amount: 0.21,
|
|
496
|
+
includedInPrice: true,
|
|
497
|
+
country: 'NL',
|
|
498
|
+
id: 'Z0wLUuYw',
|
|
499
|
+
subRates: [],
|
|
500
|
+
},
|
|
501
|
+
addedAt: '2020-12-08T09:10:27.085Z',
|
|
502
|
+
lastModifiedAt: '2020-12-08T09:10:27.085Z',
|
|
503
|
+
// state: [
|
|
504
|
+
// {
|
|
505
|
+
// quantity: 3,
|
|
506
|
+
// state: {
|
|
507
|
+
// typeId: 'state',
|
|
508
|
+
// id: 'f1d9531d-41f0-46a7-82f2-c4b0748aa9f5',
|
|
509
|
+
// },
|
|
510
|
+
// },
|
|
511
|
+
// ],
|
|
512
|
+
priceMode: 'Platform',
|
|
513
|
+
totalPrice: {
|
|
514
|
+
type: 'centPrecision',
|
|
515
|
+
currencyCode: 'EUR',
|
|
516
|
+
centAmount: 44700,
|
|
517
|
+
fractionDigits: 2,
|
|
518
|
+
},
|
|
519
|
+
taxedPrice: {
|
|
520
|
+
totalNet: {
|
|
521
|
+
type: 'centPrecision',
|
|
522
|
+
currencyCode: 'EUR',
|
|
523
|
+
centAmount: 36942,
|
|
524
|
+
fractionDigits: 2,
|
|
525
|
+
},
|
|
526
|
+
totalGross: {
|
|
527
|
+
type: 'centPrecision',
|
|
528
|
+
currencyCode: 'EUR',
|
|
529
|
+
centAmount: 44700,
|
|
530
|
+
fractionDigits: 2,
|
|
531
|
+
},
|
|
532
|
+
},
|
|
533
|
+
lineItemMode: 'Standard',
|
|
534
|
+
},
|
|
535
|
+
],
|
|
536
|
+
})
|
|
537
|
+
|
|
538
|
+
expect(response.status).toBe(200)
|
|
539
|
+
|
|
540
|
+
const created: Order = response.body
|
|
541
|
+
expect(created.lineItems).toHaveLength(1)
|
|
542
|
+
expect(created.customLineItems).toHaveLength(1)
|
|
543
|
+
})
|
|
544
544
|
})
|