Skip to content

Commit

Permalink
Implements retrieve wait list request endpoint for resource
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Nov 19, 2018
1 parent 87fe76b commit 563b6be
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 3 deletions.
25 changes: 24 additions & 1 deletion src/resources/wait-list.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,30 @@ it('can create a new wait list request for a given client', async () => {
});

it('can retrieve a clients matching wait list request', async () => {
//
const resource = new WaitList(mockAxios);

await resource
.belonging(1)
.include('preferences')
.find(2);

expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('clients/1/requests/2', {
params: {
include: 'preferences',
},
});
});

it('can retrieve a clients matching wait list request without including preferences', async () => {
const resource = new WaitList(mockAxios);

await resource
.belonging(1)
.find(2);

expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('clients/1/requests/2', { params: {} });
});

it('can update a clients wait list request', async () => {
Expand Down
11 changes: 9 additions & 2 deletions src/resources/wait-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { AxiosInstance } from 'axios';

import { WaitListFilter } from '../types/filters';
import { AttendeeModel, PreferenceModel } from '../types/models';
import { WaitListUrlParameters } from '../types/parameters';
import { IncludableParameters, WaitListUrlParameters } from '../types/parameters';
import { WaitListResource } from '../types/resources';

export default class WaitList implements WaitListResource {
Expand Down Expand Up @@ -33,7 +33,14 @@ export default class WaitList implements WaitListResource {
}

public async find(list: number | string): Promise<any> {
//
const params: IncludableParameters = {};
const { client, include } = this.parameters;

if (include) {
params.include = include;
}

return await this.client.get(`clients/${client}/requests/${list}`, { params });
}

public for(attendee: AttendeeModel): this {
Expand Down
4 changes: 4 additions & 0 deletions src/types/parameters.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ export interface AttendeeParameters {
work_phone?: string;
}

export interface IncludableParameters {
include?: string;
}

export interface LocationDetailParameters {
address?: string;
city?: string;
Expand Down

0 comments on commit 563b6be

Please sign in to comment.