From 93401ed57624569db4e272acde20b888dfa7c378 Mon Sep 17 00:00:00 2001 From: Craig Paul Date: Mon, 19 Nov 2018 09:35:45 -0600 Subject: [PATCH] Adds location, service and user filter to wait list resource --- src/resources/wait-list.test.ts | 51 +++++++++++++++++++++++++++++++++ src/resources/wait-list.ts | 17 +++++++++++ src/types/filters.d.ts | 6 ++++ 3 files changed, 74 insertions(+) diff --git a/src/resources/wait-list.test.ts b/src/resources/wait-list.test.ts index e69de29..d6752a3 100644 --- a/src/resources/wait-list.test.ts +++ b/src/resources/wait-list.test.ts @@ -0,0 +1,51 @@ +import mockAxios from 'axios'; + +import WaitList from './wait-list'; + +it('will set location filter using a number', async () => { + const resource = new WaitList(mockAxios); + + expect(resource.at(1)).toHaveProperty('filters', { + location: 1, + }); +}); + +it('will set location filter using a numeric string', async () => { + const resource = new WaitList(mockAxios); + + expect(resource.at('1')).toHaveProperty('filters', { + location: '1', + }); +}); + +it('will set service filter using a number', async () => { + const resource = new WaitList(mockAxios); + + expect(resource.seeking(1)).toHaveProperty('filters', { + service: 1, + }); +}); + +it('will set service filter using a numeric string', async () => { + const resource = new WaitList(mockAxios); + + expect(resource.seeking('1')).toHaveProperty('filters', { + service: '1', + }); +}); + +it('will set user filter using a number', async () => { + const resource = new WaitList(mockAxios); + + expect(resource.with(1)).toHaveProperty('filters', { + user: 1, + }); +}); + +it('will set user filter using a numeric string', async () => { + const resource = new WaitList(mockAxios); + + expect(resource.with('1')).toHaveProperty('filters', { + user: '1', + }); +}); diff --git a/src/resources/wait-list.ts b/src/resources/wait-list.ts index 7f99f72..6ef0203 100644 --- a/src/resources/wait-list.ts +++ b/src/resources/wait-list.ts @@ -1,12 +1,25 @@ +import { AxiosInstance } from 'axios'; + +import { WaitListFilter } from '../types/filters'; import { AttendeeModel, PreferenceModel } from '../types/models'; import { WaitListResource } from '../types/resources'; export default class WaitList implements WaitListResource { + protected client: AxiosInstance; + protected filters: WaitListFilter; + + constructor(client: AxiosInstance) { + this.client = client; + this.filters = {} + } + public async add(): Promise { // } public at(location: number | string): this { + this.filters.location = location; + return this; } @@ -35,6 +48,8 @@ export default class WaitList implements WaitListResource { } public seeking(service: number | string): this { + this.filters.service = service; + return this; } @@ -43,6 +58,8 @@ export default class WaitList implements WaitListResource { } public with(user: number | string): this { + this.filters.user = user; + return this; } } diff --git a/src/types/filters.d.ts b/src/types/filters.d.ts index 82d4f90..1fd58d6 100644 --- a/src/types/filters.d.ts +++ b/src/types/filters.d.ts @@ -46,3 +46,9 @@ export interface UserFilter { services?: number | number[] | string | string[]; location?: number | string; } + +export interface WaitListFilter { + location?: number | string; + service?: number | string; + user?: number | string; +}