Skip to content

Commit

Permalink
Add optional project_id on get_users end point
Browse files Browse the repository at this point in the history
  • Loading branch information
pmcilwaine committed Jan 21, 2021
1 parent edb3041 commit ef58dbf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion index.d.ts
Expand Up @@ -82,7 +82,7 @@ declare class TestrailApiClient {

getUser(id: number, callback?: t.Callback<t.ITestrailUser>): t.PromiseResponse<t.ITestrailUser>;
getUserByEmail(email: string, callback?: t.Callback<t.ITestrailUser>): t.PromiseResponse<t.ITestrailUser>;
getUsers(callback?: t.Callback<t.ITestrailUser[]>): t.PromiseResponse<t.ITestrailUser[]>;
getUsers(project_id?: number, callback?: t.Callback<t.ITestrailUser[]>): t.PromiseResponse<t.ITestrailUser[]>;
}

declare namespace TestrailApiClient {
Expand Down
15 changes: 13 additions & 2 deletions index.js
Expand Up @@ -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);
};

// ----------
Expand Down
14 changes: 14 additions & 0 deletions test/users.js
Expand Up @@ -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' },
]);



Expand Down Expand Up @@ -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();
});
});
});

0 comments on commit ef58dbf

Please sign in to comment.