From 7f4af5f8a05bb871debe3bdc209051bc2cd2c805 Mon Sep 17 00:00:00 2001 From: Sam Weaver Date: Thu, 27 Dec 2018 23:26:21 -0500 Subject: [PATCH 1/4] Add ability to search for closed cards on a board --- index.d.ts | 2 ++ lib/resources/Boards.js | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/index.d.ts b/index.d.ts index 40c27c3..898cdfa 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,6 +25,8 @@ declare class TrelloBoard { del(boardId: string): Promise; searchCards(boardId: string): Promise; + + searchClosedCards(boardId: string): Promise; } diff --git a/lib/resources/Boards.js b/lib/resources/Boards.js index 05b6e9e..50d459e 100644 --- a/lib/resources/Boards.js +++ b/lib/resources/Boards.js @@ -14,5 +14,11 @@ module.exports = TrelloResource.extend({ method: 'GET', path: '/{id}/cards', urlParams: ['id'] + }), + + searchClosedCards: trelloMethod({ + method: 'GET', + path: '/{id}/cards/closed', + urlParams: ['id'] }) -}); +}); \ No newline at end of file From 3d20eec808de807d0a953a8c5f2ae8cd5eef5358 Mon Sep 17 00:00:00 2001 From: Sam Weaver Date: Thu, 27 Dec 2018 23:27:22 -0500 Subject: [PATCH 2/4] Version bump. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 5e08102..79ee3c2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "trello-node-api", - "version": "0.0.6", + "version": "0.0.7", "description": "Trello Node API wrapper", "keywords": [ "node-trello", @@ -60,4 +60,4 @@ "lint": "tsc index.d.ts", "test.mocha": "npm run lint; mocha -r ts-node/register test/**/*.spec.ts" } -} +} \ No newline at end of file From 6cc79b77d2bf36c90df80aade9f7cd4869a3c094 Mon Sep 17 00:00:00 2001 From: BL Date: Sat, 29 Dec 2018 10:51:02 +0530 Subject: [PATCH 3/4] correct close board API to filter so it can support more than one filter on single API call and updates the README.md --- README.md | 27 +++++++++++++++---- examples/javascript/boards/searchCards.js | 14 ++++++++++ .../javascript/boards/searchClosedCards.js | 14 ++++++++++ index.d.ts | 4 +-- lib/resources/Boards.js | 6 ++--- test/intialize/index.ts | 4 +++ test/resources/Board.spec.ts | 15 ++++------- 7 files changed, 64 insertions(+), 20 deletions(-) create mode 100644 examples/javascript/boards/searchCards.js create mode 100644 examples/javascript/boards/searchClosedCards.js create mode 100644 test/intialize/index.ts diff --git a/README.md b/README.md index 1985c9a..04886ef 100644 --- a/README.md +++ b/README.md @@ -46,10 +46,8 @@ trello.setOauthToken('oauthToken'); - Kindly validate test cases & linting before opening new PR. ## Do you need an expert? -Are you finding a developer for your word class product? If yes, please contact here. [Submit your project request here.](https://goo.gl/forms/UofdG5GY5iHMoUWg2) -``` -Originally by [Bhushankumar Lilapara](https://github.com/bhushankumarl) (bhushankumar.lilapara@gmail.com). -``` +Are you finding a developer for your world-class product? If yes, please contact here. [Submit your project request here.](https://goo.gl/forms/UofdG5GY5iHMoUWg2) +Originally by [Bhushankumar L](mailto:bhushankumar.lilapara@gmail.com). ## Examples @@ -212,6 +210,24 @@ Originally by [Bhushankumar Lilapara](https://github.com/bhushankumarl) (bhushan }); ``` +#### Search Cards +``` + Trello.board.searchCards('BOARD_ID').then(function (response) { + console.log('response ', response); + }).catch(function (error) { + console.log('error', error); + }); +``` + +#### Search Closed Cards +``` + Trello.board.searchCardsFilter('BOARD_ID', 'closed').then(function (response) { + console.log('response ', response); + }).catch(function (error) { + console.log('error', error); + }); +``` + #### Search Field Board ``` Trello.board.searchField('BOARD_ID', 'FIELD_NAME').then(function (response) { @@ -676,4 +692,5 @@ Originally by [Bhushankumar Lilapara](https://github.com/bhushankumarl) (bhushan }).catch(function (error) { console.log('error', error); }); -``` \ No newline at end of file +``` + diff --git a/examples/javascript/boards/searchCards.js b/examples/javascript/boards/searchCards.js new file mode 100644 index 0000000..9d9edf7 --- /dev/null +++ b/examples/javascript/boards/searchCards.js @@ -0,0 +1,14 @@ +var apiKey = process.env.TRELLO_API_KEY || 'YOUR_API_KEY'; +var oauthToken = process.env.TRELLO_OAUTH_TOKEN || 'OAUTH_TOKEN'; + +var Trello = require('../../../lib/trello-node-api')(apiKey, oauthToken); + +var boardRequest = function () { + Trello.board.searchCards('BOARD_ID').then(function (response) { + console.log('response ', response); + }).catch(function (error) { + console.log('error', error); + }); +}; + +boardRequest(); \ No newline at end of file diff --git a/examples/javascript/boards/searchClosedCards.js b/examples/javascript/boards/searchClosedCards.js new file mode 100644 index 0000000..9cfdf96 --- /dev/null +++ b/examples/javascript/boards/searchClosedCards.js @@ -0,0 +1,14 @@ +var apiKey = process.env.TRELLO_API_KEY || 'YOUR_API_KEY'; +var oauthToken = process.env.TRELLO_OAUTH_TOKEN || 'OAUTH_TOKEN'; + +var Trello = require('../../../lib/trello-node-api')(apiKey, oauthToken); + +var boardRequest = function () { + Trello.board.searchCardsFilter('BOARD_ID', 'closed').then(function (response) { + console.log('response ', response); + }).catch(function (error) { + console.log('error', error); + }); +}; + +boardRequest(); \ No newline at end of file diff --git a/index.d.ts b/index.d.ts index 898cdfa..0e809f6 100644 --- a/index.d.ts +++ b/index.d.ts @@ -25,8 +25,8 @@ declare class TrelloBoard { del(boardId: string): Promise; searchCards(boardId: string): Promise; - - searchClosedCards(boardId: string): Promise; + + searchCardsFilter(boardId: string, filter: string): Promise; } diff --git a/lib/resources/Boards.js b/lib/resources/Boards.js index 50d459e..d7f803d 100644 --- a/lib/resources/Boards.js +++ b/lib/resources/Boards.js @@ -16,9 +16,9 @@ module.exports = TrelloResource.extend({ urlParams: ['id'] }), - searchClosedCards: trelloMethod({ + searchCardsFilter: trelloMethod({ method: 'GET', - path: '/{id}/cards/closed', - urlParams: ['id'] + path: '/{id}/cards/{filter}', + urlParams: ['id', 'filter'] }) }); \ No newline at end of file diff --git a/test/intialize/index.ts b/test/intialize/index.ts new file mode 100644 index 0000000..b4335d4 --- /dev/null +++ b/test/intialize/index.ts @@ -0,0 +1,4 @@ +export const CONFIG = { + TRELLO_API_KEY: process.env.TRELLO_API_KEY || 'YOUR_API_KEY', + TRELLO_OAUTH_TOKEN: process.env.TRELLO_OAUTH_TOKEN || 'OAUTH_TOKEN' +}; \ No newline at end of file diff --git a/test/resources/Board.spec.ts b/test/resources/Board.spec.ts index 4f3a3e9..37b3de8 100644 --- a/test/resources/Board.spec.ts +++ b/test/resources/Board.spec.ts @@ -1,12 +1,12 @@ -const apiKey = process.env.TRELLO_API_KEY || 'YOUR_API_KEY'; -const oauthToken = process.env.TRELLO_OAUTH_TOKEN || 'OAUTH_TOKEN'; - +import {CONFIG} from '../intialize'; import * as TrelloNodeAPI from 'trello-node-api'; +const apiKey = CONFIG.TRELLO_API_KEY; +const oauthToken = CONFIG.TRELLO_OAUTH_TOKEN; + const Trello = new TrelloNodeAPI(); Trello.setApiKey(apiKey); Trello.setOauthToken(oauthToken); -import {mocha} from 'mocha' /* tslint:disable:no-string-literal */ describe('Board', () => { @@ -28,12 +28,7 @@ describe('Board', () => { prefs_background: 'blue', prefs_cardAging: 'regular' }; - let response = await Trello.board.create(data).catch(error => { - if (error) { - console.log('error ', error); - return; - } - }); + let response = await Trello.board.create(data); console.log('response', response); }); From 1929c51519540170864231a091e5af8bab0f0185 Mon Sep 17 00:00:00 2001 From: BL Date: Sat, 29 Dec 2018 11:06:59 +0530 Subject: [PATCH 4/4] add test cases for create board and remove board --- test/intialize/index.ts | 4 ++-- test/resources/Board.spec.ts | 45 ++++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 11 deletions(-) diff --git a/test/intialize/index.ts b/test/intialize/index.ts index b4335d4..f43b558 100644 --- a/test/intialize/index.ts +++ b/test/intialize/index.ts @@ -1,4 +1,4 @@ export const CONFIG = { - TRELLO_API_KEY: process.env.TRELLO_API_KEY || 'YOUR_API_KEY', - TRELLO_OAUTH_TOKEN: process.env.TRELLO_OAUTH_TOKEN || 'OAUTH_TOKEN' + TRELLO_API_KEY: process.env.TRELLO_API_KEY || undefined, + TRELLO_OAUTH_TOKEN: process.env.TRELLO_OAUTH_TOKEN || undefined }; \ No newline at end of file diff --git a/test/resources/Board.spec.ts b/test/resources/Board.spec.ts index 37b3de8..709fa70 100644 --- a/test/resources/Board.spec.ts +++ b/test/resources/Board.spec.ts @@ -1,5 +1,9 @@ import {CONFIG} from '../intialize'; -import * as TrelloNodeAPI from 'trello-node-api'; +import * as TrelloNodeAPI from '../../lib/trello-node-api'; + +import * as chai from 'chai'; + +const expect = chai.expect; const apiKey = CONFIG.TRELLO_API_KEY; const oauthToken = CONFIG.TRELLO_OAUTH_TOKEN; @@ -7,16 +11,22 @@ const oauthToken = CONFIG.TRELLO_OAUTH_TOKEN; const Trello = new TrelloNodeAPI(); Trello.setApiKey(apiKey); Trello.setOauthToken(oauthToken); -/* tslint:disable:no-string-literal */ -describe('Board', () => { - it('It should create the Board', async () => { +let boardDocument: any = {}; +describe('Board', function () { + + before(function () { + expect(apiKey).to.be.a('string'); + expect(oauthToken).to.be.a('string'); + }); + + it('It should create the Board', async function () { + const boardName = 'Auto generated board ' + new Date().getUTCMilliseconds(); let data = { - name: 'BOARD_NAME_1', // REQUIRED + name: boardName, // REQUIRED defaultLabels: false, defaultLists: false, - desc: 'Board description.', - idOrganization: 'ORGANIZATION_ID', + desc: 'This is test board. Here is the Board description.', keepFromSource: 'none', powerUps: 'all', prefs_permissionLevel: 'private', @@ -28,8 +38,25 @@ describe('Board', () => { prefs_background: 'blue', prefs_cardAging: 'regular' }; - let response = await Trello.board.create(data); - console.log('response', response); + try { + let response = await Trello.board.create(data); + console.log('response', response); + boardDocument = response; + expect(response).to.be.a('object'); + } catch (error) { + console.log('error ', error); + expect(error).to.be.undefined; + } }); + it('It should delete the Board', async function () { + try { + let response = await Trello.board.del(boardDocument.id); + console.log('response', response); + expect(response).to.be.a('object'); + } catch (error) { + console.log('error ', error); + expect(error).to.be.undefined; + } + }); }); \ No newline at end of file