ftmocks-utils 1.1.4 → 1.1.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/index.js +15 -4
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ftmocks-utils",
3
- "version": "1.1.4",
3
+ "version": "1.1.6",
4
4
  "description": "Util functions for FtMocks",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -34,6 +34,17 @@ const capitalizeHeaders = headers => {
34
34
  );
35
35
  };
36
36
 
37
+ const getHeaders = headers => {
38
+ let res = null;
39
+ try {
40
+ res = new Map([...Object.entries(headers), ...Object.entries(capitalizeHeaders(headers))]);
41
+ } catch(e) {
42
+ console.debug('error at getHeaders', e);
43
+ res = new Map([['Content-Type', 'application/json'], ['content-type', 'application/json']]);
44
+ }
45
+ return Object.fromEntries(res);
46
+ }
47
+
37
48
  const areJsonEqual = (jsonObj1, jsonObj2) => {
38
49
  // Check if both are objects and not null
39
50
  if (typeof jsonObj1 === 'object' && jsonObj1 !== null &&
@@ -244,7 +255,7 @@ async function initiatePlaywrightRoutes (page, ftmocksConifg, testName, mockPath
244
255
 
245
256
  const json = {
246
257
  status,
247
- headers: new Map(Object.entries(capitalizeHeaders(headers))),
258
+ headers: getHeaders(headers),
248
259
  body: content,
249
260
  };
250
261
 
@@ -306,7 +317,7 @@ async function initiateJestFetch (jest, ftmocksConifg, testName) {
306
317
 
307
318
  return Promise.resolve({
308
319
  status,
309
- headers: new Map(Object.entries(capitalizeHeaders(headers))),
320
+ headers: new Map(Object.entries(headers)),
310
321
  json: () => Promise.resolve(JSON.parse(content)),
311
322
  });
312
323
  });
@@ -327,7 +338,7 @@ async function initiateJestFetch (jest, ftmocksConifg, testName) {
327
338
  status: 0,
328
339
  response: null,
329
340
  responseText: '',
330
- headers: new Map(Object.entries(capitalizeHeaders(headers))),
341
+ headers: new Map(Object.entries(headers)),
331
342
  onreadystatechange: null,
332
343
  onload: null,
333
344
  onerror: null,
@@ -350,7 +361,7 @@ async function initiateJestFetch (jest, ftmocksConifg, testName) {
350
361
  xhrMock.status = status;
351
362
  xhrMock.responseText = content;
352
363
  xhrMock.response = content;
353
- xhrMock.headers = new Map(Object.entries(capitalizeHeaders(headers)));
364
+ xhrMock.headers = new Map(Object.entries(headers));
354
365
 
355
366
  if (xhrMock.onreadystatechange) {
356
367
  xhrMock.onreadystatechange();