Skip to content

Commit

Permalink
Finishes unit tests for user resource
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Nov 15, 2018
1 parent 72f0af8 commit b10d60f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions jestconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"transform": {
"^.+\\.(t|j)sx?$": "ts-jest"
},
"clearMocks": true,
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
Expand Down
32 changes: 32 additions & 0 deletions src/resources/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,3 +81,35 @@ it('can string all filterable options together', async () => {
});
expected.toHaveProperty('sortable', 'created');
});

it('can get users without additional parameters', async () => {
const resource = new User(mockAxios);

await resource.get();

expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('users', { params: {} });
});

it('can get users with additional parameters', async () => {
const resource = new User(mockAxios);

await resource
.assigned()
.at(1)
.performing([1, 2])
.sortBy('created')
.get();

expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('users', {
params: {
filters: {
assigned: true,
location: 1,
service: [1, 2],
},
sort: 'created',
},
});
});
2 changes: 1 addition & 1 deletion src/resources/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default class User implements UserResource {
const parameters = this.params();
const params: Filterable<UserFilter> = {};

if (Object.keys(params).length) {
if (Object.keys(parameters).length) {
params.filters = parameters;
}

Expand Down

0 comments on commit b10d60f

Please sign in to comment.