From 8e040feb106462ba3a419ba534a8dd9601803b65 Mon Sep 17 00:00:00 2001 From: Mike Garuccio Date: Thu, 12 Oct 2017 10:42:19 -0400 Subject: [PATCH] Added ability to get cards on lists and boards with extra parameters --- main.js | 14 +++++++++++ test/spec.js | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) diff --git a/main.js b/main.js index bb487e8..9b07098 100644 --- a/main.js +++ b/main.js @@ -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); }; diff --git a/test/spec.js b/test/spec.js index 5001d14..a7bfe5e 100644 --- a/test/spec.js +++ b/test/spec.js @@ -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;