@labdigital/commercetools-mock 0.14.1 → 1.1.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/dist/index.d.ts +12 -3
- package/dist/index.global.js +480 -7
- package/dist/index.global.js.map +1 -1
- package/dist/index.js +148 -3
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +148 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +6 -6
- package/src/repositories/product.ts +163 -3
- package/src/repositories/standalone-price.ts +53 -15
- package/src/services/product.test.ts +124 -0
- package/src/services/standalone-price.test.ts +248 -10
|
@@ -4,34 +4,272 @@ import { CommercetoolsMock } from '../index'
|
|
|
4
4
|
|
|
5
5
|
const ctMock = new CommercetoolsMock()
|
|
6
6
|
|
|
7
|
-
describe('
|
|
8
|
-
|
|
7
|
+
describe('Standalone price Query', () => {
|
|
8
|
+
beforeAll(async () => {
|
|
9
9
|
const draft: StandalonePriceDraft = {
|
|
10
|
-
sku: 'test-sku',
|
|
11
10
|
value: {
|
|
11
|
+
centAmount: 100,
|
|
12
12
|
currencyCode: 'EUR',
|
|
13
|
-
centAmount: 1000,
|
|
14
13
|
},
|
|
14
|
+
country: 'DE',
|
|
15
|
+
sku: 'foo',
|
|
15
16
|
active: true,
|
|
17
|
+
channel: {
|
|
18
|
+
typeId: 'channel',
|
|
19
|
+
id: 'bar',
|
|
20
|
+
},
|
|
21
|
+
discounted: {
|
|
22
|
+
value: {
|
|
23
|
+
centAmount: 80,
|
|
24
|
+
currencyCode: 'EUR',
|
|
25
|
+
},
|
|
26
|
+
discount: {
|
|
27
|
+
typeId: 'product-discount',
|
|
28
|
+
id: 'baz',
|
|
29
|
+
},
|
|
30
|
+
},
|
|
16
31
|
}
|
|
32
|
+
const createResponse = await supertest(ctMock.app)
|
|
33
|
+
.post('/dummy/standalone-prices')
|
|
34
|
+
.send(draft)
|
|
35
|
+
expect(createResponse.status).toEqual(201)
|
|
36
|
+
})
|
|
17
37
|
|
|
18
|
-
|
|
19
|
-
|
|
38
|
+
afterAll(async () => {
|
|
39
|
+
ctMock.clear()
|
|
20
40
|
})
|
|
21
41
|
|
|
22
42
|
test('Get standalone price', async () => {
|
|
43
|
+
const response = await supertest(ctMock.app).get('/dummy/standalone-prices?sku=foo')
|
|
44
|
+
|
|
45
|
+
expect(response.status).toBe(200)
|
|
46
|
+
|
|
47
|
+
expect(response.body.results).toEqual([
|
|
48
|
+
{
|
|
49
|
+
active: true,
|
|
50
|
+
channel: {
|
|
51
|
+
id: 'bar',
|
|
52
|
+
typeId: 'channel',
|
|
53
|
+
},
|
|
54
|
+
country: 'DE',
|
|
55
|
+
createdAt: expect.anything(),
|
|
56
|
+
discounted: {
|
|
57
|
+
discount: {
|
|
58
|
+
id: 'baz',
|
|
59
|
+
typeId: 'product-discount',
|
|
60
|
+
},
|
|
61
|
+
value: {
|
|
62
|
+
centAmount: 80,
|
|
63
|
+
currencyCode: 'EUR',
|
|
64
|
+
fractionDigits: 2,
|
|
65
|
+
type: 'centPrecision',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
id: expect.anything(),
|
|
69
|
+
lastModifiedAt: expect.anything(),
|
|
70
|
+
sku: 'foo',
|
|
71
|
+
value: {
|
|
72
|
+
centAmount: 100,
|
|
73
|
+
currencyCode: 'EUR',
|
|
74
|
+
fractionDigits: 2,
|
|
75
|
+
type: 'centPrecision',
|
|
76
|
+
},
|
|
77
|
+
version: 1,
|
|
78
|
+
},
|
|
79
|
+
])
|
|
80
|
+
})
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
describe('Standalone price Actions', () => {
|
|
84
|
+
let id: string | undefined
|
|
85
|
+
beforeEach(async () => {
|
|
23
86
|
const draft: StandalonePriceDraft = {
|
|
24
|
-
sku: 'test-sku',
|
|
25
87
|
value: {
|
|
88
|
+
centAmount: 100,
|
|
26
89
|
currencyCode: 'EUR',
|
|
27
|
-
centAmount: 1000,
|
|
28
90
|
},
|
|
91
|
+
country: 'DE',
|
|
92
|
+
sku: 'foo',
|
|
29
93
|
active: true,
|
|
94
|
+
channel: {
|
|
95
|
+
typeId: 'channel',
|
|
96
|
+
id: 'bar',
|
|
97
|
+
},
|
|
30
98
|
}
|
|
99
|
+
const createResponse = await supertest(ctMock.app)
|
|
100
|
+
.post('/dummy/standalone-prices')
|
|
101
|
+
.send(draft)
|
|
102
|
+
expect(createResponse.status).toEqual(201)
|
|
103
|
+
id = createResponse.body.id
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
afterEach(async () => {
|
|
107
|
+
ctMock.clear()
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
test('changeValue', async () => {
|
|
111
|
+
const response = await supertest(ctMock.app)
|
|
112
|
+
.post('/dummy/standalone-prices/' + id)
|
|
113
|
+
.send({
|
|
114
|
+
version: 1,
|
|
115
|
+
actions: [
|
|
116
|
+
{
|
|
117
|
+
action: 'changeValue',
|
|
118
|
+
value: {
|
|
119
|
+
centAmount: 200,
|
|
120
|
+
currencyCode: 'EUR',
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
expect(response.status).toBe(200)
|
|
127
|
+
|
|
128
|
+
expect(response.body).toEqual({
|
|
129
|
+
active: true,
|
|
130
|
+
channel: {
|
|
131
|
+
id: 'bar',
|
|
132
|
+
typeId: 'channel',
|
|
133
|
+
},
|
|
134
|
+
country: 'DE',
|
|
135
|
+
createdAt: expect.anything(),
|
|
136
|
+
id: id,
|
|
137
|
+
lastModifiedAt: expect.anything(),
|
|
138
|
+
sku: 'foo',
|
|
139
|
+
value: {
|
|
140
|
+
centAmount: 200,
|
|
141
|
+
currencyCode: 'EUR',
|
|
142
|
+
fractionDigits: 2,
|
|
143
|
+
type: 'centPrecision',
|
|
144
|
+
},
|
|
145
|
+
version: 2,
|
|
146
|
+
})
|
|
147
|
+
})
|
|
31
148
|
|
|
32
|
-
|
|
149
|
+
test('setActive', async () => {
|
|
150
|
+
const response = await supertest(ctMock.app)
|
|
151
|
+
.post('/dummy/standalone-prices/' + id)
|
|
152
|
+
.send({
|
|
153
|
+
version: 1,
|
|
154
|
+
actions: [
|
|
155
|
+
{
|
|
156
|
+
action: 'setActive',
|
|
157
|
+
active: false,
|
|
158
|
+
},
|
|
159
|
+
],
|
|
160
|
+
})
|
|
33
161
|
|
|
34
|
-
const response = await supertest(ctMock.app).get(`/dummy/standalone-prices/${createResponse.body.id}`)
|
|
35
162
|
expect(response.status).toBe(200)
|
|
163
|
+
|
|
164
|
+
expect(response.body).toEqual({
|
|
165
|
+
active: false,
|
|
166
|
+
channel: {
|
|
167
|
+
id: 'bar',
|
|
168
|
+
typeId: 'channel',
|
|
169
|
+
},
|
|
170
|
+
country: 'DE',
|
|
171
|
+
createdAt: expect.anything(),
|
|
172
|
+
id: id,
|
|
173
|
+
lastModifiedAt: expect.anything(),
|
|
174
|
+
sku: 'foo',
|
|
175
|
+
value: {
|
|
176
|
+
centAmount: 100,
|
|
177
|
+
currencyCode: 'EUR',
|
|
178
|
+
fractionDigits: 2,
|
|
179
|
+
type: 'centPrecision',
|
|
180
|
+
},
|
|
181
|
+
version: 2,
|
|
182
|
+
})
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
test('setDiscounted', async () => {
|
|
186
|
+
const response = await supertest(ctMock.app)
|
|
187
|
+
.post('/dummy/standalone-prices/' + id)
|
|
188
|
+
.send({
|
|
189
|
+
version: 1,
|
|
190
|
+
actions: [
|
|
191
|
+
{
|
|
192
|
+
action: 'setDiscountedPrice',
|
|
193
|
+
discounted: {
|
|
194
|
+
value: {
|
|
195
|
+
centAmount: 80,
|
|
196
|
+
currencyCode: 'EUR',
|
|
197
|
+
},
|
|
198
|
+
discount: {
|
|
199
|
+
typeId: 'product-discount',
|
|
200
|
+
id: 'baz',
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
],
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
expect(response.status).toBe(200)
|
|
208
|
+
|
|
209
|
+
expect(response.body).toEqual({
|
|
210
|
+
active: true,
|
|
211
|
+
channel: {
|
|
212
|
+
id: 'bar',
|
|
213
|
+
typeId: 'channel',
|
|
214
|
+
},
|
|
215
|
+
country: 'DE',
|
|
216
|
+
createdAt: expect.anything(),
|
|
217
|
+
discounted: {
|
|
218
|
+
discount: {
|
|
219
|
+
id: 'baz',
|
|
220
|
+
typeId: 'product-discount',
|
|
221
|
+
},
|
|
222
|
+
value: {
|
|
223
|
+
centAmount: 80,
|
|
224
|
+
currencyCode: 'EUR',
|
|
225
|
+
fractionDigits: 2,
|
|
226
|
+
type: 'centPrecision',
|
|
227
|
+
},
|
|
228
|
+
},
|
|
229
|
+
id: id,
|
|
230
|
+
lastModifiedAt: expect.anything(),
|
|
231
|
+
sku: 'foo',
|
|
232
|
+
value: {
|
|
233
|
+
centAmount: 100,
|
|
234
|
+
currencyCode: 'EUR',
|
|
235
|
+
fractionDigits: 2,
|
|
236
|
+
type: 'centPrecision',
|
|
237
|
+
},
|
|
238
|
+
version: 2,
|
|
239
|
+
})
|
|
240
|
+
|
|
241
|
+
const response2 = await supertest(ctMock.app)
|
|
242
|
+
.post('/dummy/standalone-prices/' + id)
|
|
243
|
+
.send({
|
|
244
|
+
version: 2,
|
|
245
|
+
actions: [
|
|
246
|
+
{
|
|
247
|
+
action: 'setDiscountedPrice',
|
|
248
|
+
discounted: null,
|
|
249
|
+
},
|
|
250
|
+
],
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
expect(response2.status).toBe(200)
|
|
254
|
+
|
|
255
|
+
expect(response2.body).toEqual({
|
|
256
|
+
active: true,
|
|
257
|
+
channel: {
|
|
258
|
+
id: 'bar',
|
|
259
|
+
typeId: 'channel',
|
|
260
|
+
},
|
|
261
|
+
country: 'DE',
|
|
262
|
+
createdAt: expect.anything(),
|
|
263
|
+
id: id,
|
|
264
|
+
lastModifiedAt: expect.anything(),
|
|
265
|
+
sku: 'foo',
|
|
266
|
+
value: {
|
|
267
|
+
centAmount: 100,
|
|
268
|
+
currencyCode: 'EUR',
|
|
269
|
+
fractionDigits: 2,
|
|
270
|
+
type: 'centPrecision',
|
|
271
|
+
},
|
|
272
|
+
version: 3,
|
|
273
|
+
})
|
|
36
274
|
})
|
|
37
275
|
})
|