ftmocks-utils 1.0.3 → 1.0.4

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 +12 -2
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ftmocks-utils",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Util functions for FtMocks",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.js CHANGED
@@ -34,7 +34,7 @@ const areJsonEqual = (jsonObj1, jsonObj2) => {
34
34
  }
35
35
 
36
36
  const getDefaultMockDataFromConfig = (testConfig) => {
37
- const defaultPath = path.join(testConfig.MOCK_DIR, 'defaultMocks');
37
+ const defaultPath = path.join(testConfig.MOCK_DIR, 'default.json');
38
38
 
39
39
  try {
40
40
  const defaultData = fs.readFileSync(defaultPath, 'utf8');
@@ -87,7 +87,17 @@ const loadMockDataFromConfig = (testConfig, _testName) => {
87
87
  }
88
88
  };
89
89
 
90
+ const clearNulls = postData => {
91
+ Object.keys(postData || {}).forEach(key => {
92
+ if(postData[key] === null) {
93
+ delete postData[key];
94
+ }
95
+ });
96
+ };
97
+
90
98
  const isSameRequest = (req1, req2) => {
99
+ clearNulls(req1.postData);
100
+ clearNulls(req2.postData);
91
101
  let matched = true;
92
102
  if(req1.url !== req2.url) {
93
103
  matched = false;
@@ -147,7 +157,7 @@ function getMatchingMockData({testMockData, defaultMockData, url, options, testC
147
157
  served = mock.fileContent.served;
148
158
  return compareMockToFetchRequest(mock, { url, options });
149
159
  }) || [];
150
- let foundMock = matchedMocks.find(mock => !mock.fileContent.served) ? matchedMocks.find(mock => !mock.fileContent.served) : matchedMocks[0];
160
+ let foundMock = matchedMocks.find(mock => !mock.fileContent.served) ? matchedMocks.find(mock => !mock.fileContent.served) : matchedMocks[matchedMocks.length - 1];
151
161
  // updating stats to mock file
152
162
  if(foundMock) {
153
163
  const mockFilePath = path.join(testConfig.MOCK_DIR, `test_${nameToFolder(testName)}`, `mock_${foundMock.id}.json`);