Skip to content
This repository has been archived by the owner on Jan 21, 2022. It is now read-only.

Add offset and limit to getUserList #13

Merged
merged 2 commits into from
Mar 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.1.0",
"version": "0.2.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
38 changes: 38 additions & 0 deletions src/__tests__/apis/UserApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,44 @@ test('getUserList() returns a list of users', async () => {
expect(userList[0]).toBeInstanceOf(User);
});

test('getUserList() with limit returns a list of users', async () => {
nock('https://api.clerk.dev')
.get('/v1/users?limit=1')
.replyWithFile(200, __dirname + '/responses/getUserList.json', {
'Content-Type': 'application/x-www-form-urlencoded',
});

const userList = await users.getUserList({limit: 1});

expect(userList).toBeInstanceOf(Array);
expect(userList.length).toEqual(1);

// const expected = new User();

// expect(userList[0]).toEqual(expected);

expect(userList[0]).toBeInstanceOf(User);
});

test('getUserList() with limit returns a list of users', async () => {
nock('https://api.clerk.dev')
.get('/v1/users?limit=1&offset=1')
.replyWithFile(200, __dirname + '/responses/getUserList.json', {
'Content-Type': 'application/x-www-form-urlencoded',
});

const userList = await users.getUserList({limit: 1, offset: 1});

expect(userList).toBeInstanceOf(Array);
expect(userList.length).toEqual(1);

// const expected = new User();

// expect(userList[0]).toEqual(expected);

expect(userList[0]).toBeInstanceOf(User);
});

test('getUser() returns a single user', async () => {
const expected = new User({
id: 'user_noone',
Expand Down
8 changes: 7 additions & 1 deletion src/apis/UserApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ interface UserParams {
privateMetadata?: object;
}

interface UserListParams {
limit?: number;
offset?: number;
}

export class UserApi extends AbstractApi {
public async getUserList(): Promise<Array<User>> {
public async getUserList(params: UserListParams = {}): Promise<Array<User>> {
return this._restClient.makeRequest({
method: 'get',
path: '/users',
queryParams: params,
});
}

Expand Down