@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@labdigital/commercetools-mock",
3
3
  "author": "Michael van Tellingen",
4
- "version": "2.4.0",
4
+ "version": "2.5.0",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.cjs",
7
7
  "module": "dist/index.js",
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('createget', async () => {
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