Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle non-200 success codes #38

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/sailthru.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/


exports.VERSION = '3.0.5';
exports.VERSION = '3.0.6';


USER_AGENT = 'Sailthru API Node/JavaScript Client ' + exports.VERSION;
Expand Down Expand Up @@ -119,7 +119,7 @@
that.last_rate_limit_info[parse_uri.pathname + '|' + options.method] = rate_limit_headers;
}

if (statusCode === 200) {
if (statusCode >= 200 && statusCode <= 204) {
return callback(null, json_response);
} else {
json_err = {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "sailthru-client",
"description": "Node.js client for Sailthru API",
"version": "3.0.5",
"version": "3.0.6",
"author": {
"name": "George Liao",
"email": "[email protected]",
Expand Down
41 changes: 41 additions & 0 deletions test/test_sailthru.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,5 +586,46 @@
});
};

// ensure we will correctly handle 201 and 204 responses
exports.saveWatch = function(test) {
const watchData = {
profile_id: '12345',
watch: {
interest_type: 'wishlist',
query: { content_id: '67890' },
},
}

nock('https://api.sailthru.com')
.post(/^\/content\/watch/, function (q) {
var data = JSON.parse(q.json);
test.deepEqual(data, watchData);
return true;
})
.reply(201, {/* don't care about response */});

test.expect(2);
Copy link

@m1dcarry m1dcarry May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me as to why we are expecting 2 here? Shouldn't it be expecting 1 because we are only creating a single watch?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The number is how many assertions nodeunit should expect. I've mainly just done this to follow the pattern elsewhere in this repo :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right okay. I misunderstood that! thanks


var callback = function(err, res) {
test.equal(err, undefined);
test.done();
};
SailthruClient.apiPost('content/watch', watchData, callback);
};

exports.deleteWatch = function(test) {
nock('https://api.sailthru.com')
.delete(/^\/content\/watch/)
.reply(204, {/* don't care about response */});

test.expect(1);

var callback = function(err, res) {
test.equal(err, undefined);
test.done();
};
SailthruClient.apiDelete('content/watch', {}, callback);
};


}).call(this);