Skip to content

Commit

Permalink
Added ability to get cards on lists and boards with extra parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
mgaruccio committed Oct 12, 2017
1 parent db21778 commit 8e040fe
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main.js
Expand Up @@ -266,10 +266,24 @@ Trello.prototype.getCardsOnBoard = function (boardId, callback) {
return makeRequest(rest.get, this.uri + '/1/boards/' + boardId + '/cards', {query: this.createQuery()}, callback);
};

Trello.prototype.getCardsOnBoardWithExtraParams = function (boardId, extraParams, callback) {
var query = this.createQuery();
Object.assign(query, extraParams);

return makeRequest(rest.get, this.uri + '/1/boards/' + boardId + '/cards', {query: query}, callback);
}

Trello.prototype.getCardsOnList = function (listId, callback) {
return makeRequest(rest.get, this.uri + '/1/lists/' + listId + '/cards', {query: this.createQuery()}, callback);
};

Trello.prototype.getCardsOnListWithExtraParams = function (listId, extraParams, callback) {
var query = this.createQuery();
Object.assign(query, extraParams);

return makeRequest(rest.get, this.uri + '/1/lists/' + listId + '/cards', {query: query}, callback);
}

Trello.prototype.deleteCard = function (cardId, callback) {
return makeRequest(rest.del, this.uri + '/1/cards/' + cardId, {query: this.createQuery()}, callback);
};
Expand Down
66 changes: 66 additions & 0 deletions test/spec.js
Expand Up @@ -229,6 +229,72 @@ describe('Trello', function () {

});

describe('getCardsOnListWithExtraParams', function () {
var query;
var post;

var testDate = new Date("2015/03/25");
var extraParams = {before: testDate}

beforeEach(function (done) {
sinon.stub(restler, 'get', function (uri, options) {
return {once: function (event, callback) {
callback(null, null);
}};
});

trello.getCardsOnListWithExtraParams('listId', extraParams, function () {
query = restler.get.args[0][1].query;
get = restler.get;
done();
});
});

it('should get from https://api.trello.com/1/lists/listId/cards', function () {
get.should.have.been.calledWith('https://api.trello.com/1/lists/listId/cards');
});
it('should include a date in the query', function () {
query.before.should.equal(testDate)
});

afterEach(function () {
restler.get.restore();
});
});

describe('getCardsOnBoardWithExtraParams', function () {
var query;
var post;

var testDate = new Date("2015/03/25");
var extraParams = {before: testDate}

beforeEach(function (done) {
sinon.stub(restler, 'get', function (uri, options) {
return {once: function (event, callback) {
callback(null, null);
}};
});

trello.getCardsOnBoardWithExtraParams('boardId', extraParams, function () {
query = restler.get.args[0][1].query;
get = restler.get;
done();
});
});

it('should get from https://api.trello.com/1/boards/boardId/cards', function () {
get.should.have.been.calledWith('https://api.trello.com/1/boards/boardId/cards');
});
it('should include a date in the query', function () {
query.before.should.equal(testDate)
});

afterEach(function () {
restler.get.restore();
});
});

describe('addWebhook', function () {
var query;
var post;
Expand Down

0 comments on commit 8e040fe

Please sign in to comment.