diff --git a/lib/sailthru.js b/lib/sailthru.js index 3b3431b..b11e746 100644 --- a/lib/sailthru.js +++ b/lib/sailthru.js @@ -24,7 +24,7 @@ */ - exports.VERSION = '3.0.5'; + exports.VERSION = '3.0.6'; USER_AGENT = 'Sailthru API Node/JavaScript Client ' + exports.VERSION; @@ -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 = { diff --git a/package-lock.json b/package-lock.json index f1bba1c..0946303 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "sailthru-client", - "version": "3.0.5", + "version": "3.0.6", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index b51c545..e9eccc9 100644 --- a/package.json +++ b/package.json @@ -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": "gliao@sailthru.com", diff --git a/test/test_sailthru.js b/test/test_sailthru.js index 4e3f798..94fec49 100644 --- a/test/test_sailthru.js +++ b/test/test_sailthru.js @@ -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); + + 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);