Skip to content

Commit

Permalink
fix: ignore null items in API responses (#240)
Browse files Browse the repository at this point in the history
* fix: ignore null items in API responses

- configure the talk client to use the production API for tests.
- test a talk production search that is known to break the API client.
- ignore null response data, so that the tests pass.

* clean up loops with forEach

* fix indentation

* test individual comments

* refactor with filter(Boolean) to remove null responses

* Mock the Talk API with nock

* Move the tests to talk-test.zooniverse.org

* Test an empty search

---------

Co-authored-by: Mark Bouslog <[email protected]>
  • Loading branch information
eatyourgreens and mcbouslog authored Apr 8, 2024
1 parent efd7e7d commit 9db4b43
Show file tree
Hide file tree
Showing 8 changed files with 1,258 additions and 172 deletions.
5 changes: 4 additions & 1 deletion .mocharc.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
module.exports = {
reporter: 'spec',
checkLeaks: true,
slow: 300
slow: 300,
require: [
'test/support/setup.mjs'
]
}
2 changes: 1 addition & 1 deletion lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var TALK_HOSTS = {
production: 'https://talk.zooniverse.org',
staging: 'https://talk-staging.zooniverse.org',
development: 'https://talk-staging.zooniverse.org',
test: 'https://talk-staging.zooniverse.org'
test: 'https://talk-test.zooniverse.org'
};

var SUGAR_HOSTS = {
Expand Down
27 changes: 10 additions & 17 deletions lib/json-api-client/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,32 +87,25 @@
this._handleLinks(response.links);
}
if ('linked' in response) {
ref1 = response.linked;
for (typeName in ref1) {
linkedResources = ref1[typeName];
ref2 = [].concat(linkedResources);
for (j = 0, len1 = ref2.length; j < len1; j++) {
resourceData = ref2[j];
for (typeName in response.linked) {
linkedResources = response.linked[typeName];
linkedResources.filter(Boolean).forEach((resourceData) => {
this.type(typeName).create(resourceData, headers, response.meta);
}
});
}
}
results = [];
if ('data' in response) {
ref3 = [].concat(response.data);
for (k = 0, len2 = ref3.length; k < len2; k++) {
resourceData = ref3[k];
results.push(this.type(resourceData.type).create(resourceData, headers, response.meta));
}
response.data.filter(Boolean).forEach((resourceData) => {
results.push(this.type(resourceData.type).create(resourceData, headers, response.meta));
});
} else {
for (typeName in response) {
resources = response[typeName];
if (indexOf.call(RESERVED_TOP_LEVEL_KEYS, typeName) < 0) {
ref4 = [].concat(resources);
for (l = 0, len3 = ref4.length; l < len3; l++) {
resourceData = ref4[l];
results.push(this.type(typeName).create(resourceData, headers, response.meta));
}
resources.filter(Boolean).forEach((resourceData) => {
results.push(this.type(typeName).create(resourceData, headers, response.meta));
});
}
}
}
Expand Down
Loading

0 comments on commit 9db4b43

Please sign in to comment.