From cfdca5cbd29155ae8f0c3293bab0d68cb2dc742d Mon Sep 17 00:00:00 2001 From: charles Date: Mon, 17 Oct 2016 19:14:31 -0500 Subject: [PATCH] Add addMemberToBoard addMemberToBoard - Initial code addMemberToBoard - Code Test addMemberToBoard - Format changes --- main.js | 7 +++++++ test/spec.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/main.js b/main.js index 4681feb..2681d4b 100644 --- a/main.js +++ b/main.js @@ -83,6 +83,13 @@ Trello.prototype.addListToBoard = function (boardId, name, callback) { return makeRequest(rest.post, this.uri + '/1/boards/' + boardId + '/lists', {query: query}, callback); }; +Trello.prototype.addMemberToBoard = function (boardId, memberId, type, callback) { + var query = this.createQuery(); + var data = {type: type}; // Valid Values: 'normal','admin','observer' + + return makeRequest(rest.put, this.uri + '/1/boards/' + boardId + '/members/' + memberId, { data: data, query: query }, callback); +}; + Trello.prototype.addCommentToCard = function (cardId, comment, callback) { var query = this.createQuery(); query.text = comment; diff --git a/test/spec.js b/test/spec.js index ba9e3ad..312ff8c 100644 --- a/test/spec.js +++ b/test/spec.js @@ -376,6 +376,36 @@ describe('Trello', function () { }); }); + describe('addMemberToBoard', function () { + var data; + var post; + + beforeEach(function (done) { + sinon.stub(restler, 'put', function (uri, options) { + return {once: function (event, callback) { + callback(null, null); + }}; + }); + + trello.addMemberToBoard('boardId', 'memberId', 'normal', function () { + data = restler.put.args[0][1].data; + put = restler.put; + done(); + }); + }); + + it('should post to https://api.trello.com/1/boards/boardId/members/memberId', function () { + put.should.have.been.calledWith('https://api.trello.com/1/boards/boardId/members/memberId'); + }); + + it('should include the type', function () { + data.type.should.equal('normal'); + }); + + afterEach(function () { + restler.put.restore(); + }); + }); describe('addLabelOnBoard', function() { var query;