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

fixed missing data object error #224

Merged
merged 1 commit into from
Dec 8, 2017
Merged
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
3 changes: 2 additions & 1 deletion src/RetryRestClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ RetryRestClient.prototype.delete = function ( /* [params], [callback] */ ) {

RetryRestClient.prototype.invoke = function(method, args){
var cb;
args = Array.prototype.slice.call(args); // convert array-like object to array.
if(args && args[args.length -1] instanceof Function){
cb = args[args.length -1];
delete args[args.length -1];
args.pop(); // Remove the callback
}

var promise = this.handleRetry(method, args);
Expand Down
65 changes: 63 additions & 2 deletions test/retry-rest-client.tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ describe('RetryRestClient', function () {
});
});

it('should return promise when no callback is provided', function(done){
it('should return promise for successful request when no callback is provided', function(done){
nock(API_URL)
.get('/')
.reply(200, { success: true });
Expand All @@ -85,7 +85,7 @@ describe('RetryRestClient', function () {
});
});

it('should return promise when no callback is provided', function(done){
it('should return promise for failed request when no callback is provided', function(done){
nock(API_URL)
.get('/')
.reply(500);
Expand Down Expand Up @@ -294,4 +294,65 @@ describe('RetryRestClient', function () {
done();
});
});

it('should remove callback from arguments object if data is passed', function (done) {
var self = this;
var restClientSpy = {
create: function(){
expect(arguments.length).to.be.equal(1);
done();
return Promise.resolve();
}
}

var client = new RetryRestClient(restClientSpy, { enabled: false });
client.create({data: 'foobar'}, function() { });
});

it('should remove callback from arguments object if urlParams and data is passed', function (done) {
var self = this;
var restClientSpy = {
create: function(){
expect(arguments.length).to.be.equal(2);
done();
return Promise.resolve();
}
}

var client = new RetryRestClient(restClientSpy, { enabled: false });
var urlParams = { id: '123' };
var data = {data: 'foobar'};
client.create('/:id', data, function() { });
});

it('should not remove data object when no callback is passed', function (done) {
var self = this;
var restClientSpy = {
create: function(){
expect(arguments.length).to.be.equal(1);
done();
return Promise.resolve();
}
}

var client = new RetryRestClient(restClientSpy, { enabled: false });
var data = {data: 'foobar'};
client.create(data);
});

it('should not remove data object when urlParams is passed and no callback is passed', function (done) {
var self = this;
var restClientSpy = {
create: function(){
expect(arguments.length).to.be.equal(2);
done();
return Promise.resolve();
}
}

var client = new RetryRestClient(restClientSpy, { enabled: false });
var urlParams = { id: '123' };
var data = {data: 'foobar'};
client.create('/:id', data);
});
});