@labdigital/commercetools-mock 2.4.0 → 2.5.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.cjs +18 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +18 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/ctMock.ts +31 -0
- package/src/services/custom-object.test.ts +17 -1
- package/src/services/customer.test.ts +20 -0
package/package.json
CHANGED
package/src/ctMock.ts
CHANGED
|
@@ -193,6 +193,37 @@ export class CommercetoolsMock {
|
|
|
193
193
|
headers: mapHeaderType(res.headers),
|
|
194
194
|
})
|
|
195
195
|
}),
|
|
196
|
+
http.head(`${this.options.apiHost}/*`, async ({ request }) => {
|
|
197
|
+
const body = await request.text()
|
|
198
|
+
const url = new URL(request.url)
|
|
199
|
+
const headers = copyHeaders(request.headers)
|
|
200
|
+
|
|
201
|
+
const res = await inject(server)
|
|
202
|
+
.get(url.pathname + '?' + url.searchParams.toString())
|
|
203
|
+
.body(body)
|
|
204
|
+
.headers(headers)
|
|
205
|
+
.end()
|
|
206
|
+
|
|
207
|
+
if (res.statusCode === 200) {
|
|
208
|
+
const parsedBody = JSON.parse(res.body)
|
|
209
|
+
// Check if we have a count property (e.g. for query-lookups)
|
|
210
|
+
// or if we have a result object (e.g. for single lookups)
|
|
211
|
+
const resultCount =
|
|
212
|
+
'count' in parsedBody
|
|
213
|
+
? parsedBody.count
|
|
214
|
+
: Object.keys(parsedBody).length
|
|
215
|
+
|
|
216
|
+
return new HttpResponse(null, {
|
|
217
|
+
status: resultCount > 0 ? 200 : 404,
|
|
218
|
+
headers: mapHeaderType(res.headers),
|
|
219
|
+
})
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return new HttpResponse(null, {
|
|
223
|
+
status: res.statusCode,
|
|
224
|
+
headers: mapHeaderType(res.headers),
|
|
225
|
+
})
|
|
226
|
+
}),
|
|
196
227
|
http.get(`${this.options.apiHost}/*`, async ({ request }) => {
|
|
197
228
|
const body = await request.text()
|
|
198
229
|
const url = new URL(request.url)
|
|
@@ -47,7 +47,23 @@ describe('CustomObject retrieve', () => {
|
|
|
47
47
|
ctMock.clear()
|
|
48
48
|
})
|
|
49
49
|
|
|
50
|
-
test('
|
|
50
|
+
test('exists', async () => {
|
|
51
|
+
const response = await supertest(ctMock.app)
|
|
52
|
+
.head('/dummy/custom-objects/my-container/my-key')
|
|
53
|
+
.send()
|
|
54
|
+
|
|
55
|
+
expect(response.status).toBe(200)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
test('non-existent', async () => {
|
|
59
|
+
const response = await supertest(ctMock.app)
|
|
60
|
+
.head('/dummy/custom-objects/invalid-container/invalid')
|
|
61
|
+
.send()
|
|
62
|
+
|
|
63
|
+
expect(response.status).toBe(404)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('get', async () => {
|
|
51
67
|
const response = await supertest(ctMock.app)
|
|
52
68
|
.get('/dummy/custom-objects/my-container/my-key')
|
|
53
69
|
.send()
|
|
@@ -26,6 +26,26 @@ describe('Customer Update Actions', () => {
|
|
|
26
26
|
ctMock.clear()
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
+
test('exists', async () => {
|
|
30
|
+
assert(customer, 'customer not created')
|
|
31
|
+
|
|
32
|
+
const response = await supertest(ctMock.app)
|
|
33
|
+
.head(`/dummy/customers/${customer.id}`)
|
|
34
|
+
.send()
|
|
35
|
+
|
|
36
|
+
expect(response.status).toBe(200)
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
test('non-existent', async () => {
|
|
40
|
+
assert(customer, 'customer not created')
|
|
41
|
+
|
|
42
|
+
const response = await supertest(ctMock.app)
|
|
43
|
+
.head(`/dummy/customers/invalid-id`)
|
|
44
|
+
.send()
|
|
45
|
+
|
|
46
|
+
expect(response.status).toBe(404)
|
|
47
|
+
})
|
|
48
|
+
|
|
29
49
|
test('changeEmail', async () => {
|
|
30
50
|
assert(customer, 'customer not created')
|
|
31
51
|
|