From ef58dbfaa4b3ba32000f66457dad21d8e74542a6 Mon Sep 17 00:00:00 2001 From: Paul Mcilwaine Date: Thu, 21 Jan 2021 11:54:35 +0100 Subject: [PATCH] Add optional project_id on get_users end point --- index.d.ts | 2 +- index.js | 15 +++++++++++++-- test/users.js | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 7d8c723..449e62d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -82,7 +82,7 @@ declare class TestrailApiClient { getUser(id: number, callback?: t.Callback): t.PromiseResponse; getUserByEmail(email: string, callback?: t.Callback): t.PromiseResponse; - getUsers(callback?: t.Callback): t.PromiseResponse; + getUsers(project_id?: number, callback?: t.Callback): t.PromiseResponse; } declare namespace TestrailApiClient { diff --git a/index.js b/index.js index 5479cb9..e9b2b2b 100644 --- a/index.js +++ b/index.js @@ -470,8 +470,19 @@ TestRail.prototype.getUserByEmail = function (email, callback) { return this.apiGet('get_user_by_email', {email: email}, callback); }; -TestRail.prototype.getUsers = function (callback) { - return this.apiGet('get_users', callback); +TestRail.prototype.getUsers = function (project_id, callback) { + var url = 'get_users'; + + if (typeof project_id === 'function') { + callback = project_id; + project_id = undefined; + } + + if (project_id !== undefined) { + url += '/' + project_id; + } + + return this.apiGet(url, callback); }; // ---------- diff --git a/test/users.js b/test/users.js index 9679e10..85c7ef3 100644 --- a/test/users.js +++ b/test/users.js @@ -41,6 +41,11 @@ describe('users api', function() { { 'id': 2, 'name': 'Ciaran Davenport' } ]); + nock('https://rundef.testrail.com') + .get(testrail.uri + 'get_users/10') + .reply(200, [ + { 'id': 1, 'name': 'Alexis Gonzalez' }, + ]); @@ -82,4 +87,13 @@ describe('users api', function() { done(); }); }); + + it('Get all by project', function (done) { + testrail.getUsers(10, function (err, response, body) { + expect(err).to.be.null; + expect(response).to.be.an.object; + expect(body).to.be.an.array; + done(); + }); + }); });