-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6a9c91f
commit 39152d7
Showing
5 changed files
with
167 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import mockAxios from 'axios'; | ||
|
||
import TimeSlot from './time-slot'; | ||
|
||
it('will set location filter using a number', async () => { | ||
const resource = new TimeSlot(mockAxios); | ||
|
||
expect(resource.at(1)).toHaveProperty('filters', { | ||
location: 1, | ||
}); | ||
}); | ||
|
||
it('will set start and end filters', async () => { | ||
const resource = new TimeSlot(mockAxios); | ||
|
||
expect(resource.between('2018-01-01', '2018-01-31')).toHaveProperty('filters', { | ||
end: '2018-01-31', | ||
start: '2018-01-01', | ||
}); | ||
}); | ||
|
||
it('will set user filter using a number', async () => { | ||
const resource = new TimeSlot(mockAxios); | ||
|
||
expect(resource.by(1)).toHaveProperty('filters', { | ||
user: 1, | ||
}); | ||
}); | ||
|
||
it('will set service filter using a number', async () => { | ||
const resource = new TimeSlot(mockAxios); | ||
|
||
expect(resource.for(1)).toHaveProperty('filters', { | ||
services: 1, | ||
}); | ||
}); | ||
|
||
it('will set service filter using an array of numbers', async () => { | ||
const resource = new TimeSlot(mockAxios); | ||
|
||
expect(resource.for([1, 2])).toHaveProperty('filters', { | ||
services: [1, 2], | ||
}); | ||
}); | ||
|
||
it('can string all filterable options together', async () => { | ||
const resource = new TimeSlot(mockAxios); | ||
|
||
const expected = expect( | ||
resource | ||
.between('2018-01-01', '2018-01-31') | ||
.at(1) | ||
.for([1, 2]) | ||
.by(1), | ||
); | ||
|
||
expected.toHaveProperty('filters', { | ||
end: '2018-01-31', | ||
location: 1, | ||
services: [1, 2], | ||
start: '2018-01-01', | ||
user: 1, | ||
}); | ||
}); | ||
|
||
it('can get time slots', async () => { | ||
const resource = new TimeSlot(mockAxios); | ||
|
||
await resource | ||
.between('2018-01-01', '2018-01-31') | ||
.at(1) | ||
.for([1, 2]) | ||
.by(1) | ||
.get(); | ||
|
||
expect(mockAxios.get).toHaveBeenCalledTimes(1); | ||
expect(mockAxios.get).toHaveBeenCalledWith('times', { | ||
params: { | ||
end: '2018-01-31', | ||
location_id: 1, | ||
service_id: [1, 2], | ||
staff_id: 1, | ||
start: '2018-01-01', | ||
}, | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { AxiosInstance } from 'axios'; | ||
|
||
import { TimeSlotFilter } from '../types/filters'; | ||
import { TimeSlotResource } from '../types/resources'; | ||
import { TimeSlotParameters } from '../types/parameters'; | ||
|
||
export default class TimeSlot implements TimeSlotResource { | ||
protected client: AxiosInstance; | ||
protected filters: TimeSlotFilter; | ||
|
||
constructor(client: AxiosInstance) { | ||
this.client = client; | ||
this.filters = {}; | ||
} | ||
|
||
public at(location: number): this { | ||
this.filters.location = location; | ||
|
||
return this; | ||
} | ||
|
||
public between(start: string, end: string): this { | ||
this.filters.start = start; | ||
this.filters.end = end; | ||
|
||
return this; | ||
} | ||
|
||
public by(user: number): this { | ||
this.filters.user = user; | ||
|
||
return this; | ||
} | ||
|
||
public for(services: number | number[]): this { | ||
this.filters.services = services; | ||
|
||
return this; | ||
} | ||
|
||
public async get(): Promise<any> { | ||
const params: TimeSlotParameters = { | ||
end: this.filters.end, | ||
location_id: this.filters.location, | ||
service_id: this.filters.services, | ||
start: this.filters.start, | ||
}; | ||
|
||
if (this.filters.user) { | ||
params.staff_id = this.filters.user; | ||
} | ||
|
||
return await this.client.get('times', { params }); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters