Skip to content

Commit

Permalink
Merge pull request #1 from ferentchak/master
Browse files Browse the repository at this point in the history
Adding progress functionality to the promise returned
  • Loading branch information
krmorse committed Jan 18, 2014
2 parents e8ba702 + 52fc249 commit 5c5223e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/restapi.js
Expand Up @@ -219,7 +219,9 @@ RestApi.prototype.query = function(options, callback) {
var results = [];

function loadRemainingPages(result) {
results = results.concat(result.Results);
var pageResults = result.Results;
deferred.notify(pageResults);
results = results.concat(pageResults);
if (options.limit && result.StartIndex + options.pageSize <= Math.min(options.limit || options.pageSize, result.TotalResultCount)) {
return self.request.get(_.merge(requestOptions, {
qs: {
Expand All @@ -246,4 +248,4 @@ RestApi.prototype.query = function(options, callback) {
return deferred.promise.nodeify(callback);
};

module.exports = RestApi;
module.exports = RestApi;
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "rally",
"version": "0.1.1",
"version": "0.1.2",
"description": "Rally REST Toolkit for Node.js",
"contributors": [
{
Expand Down
22 changes: 19 additions & 3 deletions spec/restapi.spec.js
Expand Up @@ -81,10 +81,10 @@ describe('RestApi', function() {
var restApi = new RestApi();
var initArgs = request.init.firstCall.args[0];
initArgs.requestOptions.headers.should.eql({
'X-RallyIntegrationLibrary': 'Rally REST Toolkit for Node.js v0.1.1',
'X-RallyIntegrationLibrary': 'Rally REST Toolkit for Node.js v0.1.2',
'X-RallyIntegrationName': 'Rally REST Toolkit for Node.js',
'X-RallyIntegrationVendor': 'Rally Software, Inc.',
'X-RallyIntegrationVersion': '0.1.1'
'X-RallyIntegrationVersion': '0.1.2'
});
restApi.request.should.be.exactly(request.init.firstCall.returnValue);
});
Expand Down Expand Up @@ -496,6 +496,22 @@ describe('RestApi', function() {
}).done();
});

it('should call progress function for each page of multiple page call', function(done) {
var restApi = new RestApi();
var pagesReturned = 0;
restApi.query({
type: 'defect',
start: 1,
pageSize: 2,
limit: 6
}).progress(function(page){
pagesReturned++;
}).done(function(){
(pagesReturned).should.be.exactly(3);
done();
});
});

it('should return no more than TotalResultCount', function(done) {
var restApi = new RestApi();
restApi.query({
Expand Down Expand Up @@ -536,4 +552,4 @@ describe('RestApi', function() {
});
});
});
});
});

0 comments on commit 5c5223e

Please sign in to comment.