Skip to content

Commit

Permalink
Adds initial tests and mock for user resource
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Nov 15, 2018
1 parent 0c77118 commit 3e0c42f
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/__mocks__/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default {
get: jest.fn(() => Promise.resolve({ data: {} }))
}
90 changes: 90 additions & 0 deletions src/resources/user.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import mockAxios from 'axios';
import User from './user';

it('will set assigned filter', async () => {
const resource = new User(mockAxios);

expect(resource.assigned())
.toHaveProperty('filters', {
assigned: true,
});
});

it('will set location filter using a number', async () => {
const resource = new User(mockAxios);

expect(resource.at(1))
.toHaveProperty('filters', {
location: 1,
});
});

it('will set location filter using a string', async () => {
const resource = new User(mockAxios);

expect(resource.at('identifier'))
.toHaveProperty('filters', {
location: 'identifier',
});
});

it('will set service filter using a number', async () => {
const resource = new User(mockAxios);

expect(resource.performing(1))
.toHaveProperty('filters', {
services: 1,
});
});

it('will set service filter using an array of numbers', async () => {
const resource = new User(mockAxios);

expect(resource.performing([1, 2]))
.toHaveProperty('filters', {
services: [1, 2],
});
});

it('will set service filter using a string', async () => {
const resource = new User(mockAxios);

expect(resource.performing('identifier'))
.toHaveProperty('filters', {
services: 'identifier',
});
});

it('will set service filter using an array of strings', async () => {
const resource = new User(mockAxios);

expect(resource.performing(['identifier', 'other']))
.toHaveProperty('filters', {
services: ['identifier', 'other'],
});
});

it('will set the sortable filter', async () => {
const resource = new User(mockAxios);

expect(resource.sortBy('first_name,-created'))
.toHaveProperty('sortable', 'first_name,-created');
});

it('can string all filterable options together', async () => {
const resource = new User(mockAxios);

const expected = expect(
resource.assigned()
.at(1)
.performing([1, 2])
.sortBy('created')
);

expected.toHaveProperty('filters', {
assigned: true,
location: 1,
services: [1, 2],
});
expected.toHaveProperty('sortable', 'created');
});

0 comments on commit 3e0c42f

Please sign in to comment.