Skip to content

Commit

Permalink
Ensures timezone filter is sent with request when provided
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Jun 11, 2019
1 parent 8ad5ea7 commit 3456efe
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/resources/time-slot.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,14 @@ it('can string all filterable options together', async () => {
it('can get time slots for no particular user', async () => {
const resource = new TimeSlot(mockAxios);

const timezones = ['America/Chicago', 'America/Toronto', 'Europe/Amsterdam', 'Europe/Paris'];
const timezone = timezones[Math.floor(Math.random() * timezones.length)];

await resource
.between('2018-01-01', '2018-01-31')
.at(1)
.for([1, 2])
.in(timezone)
.get();

expect(mockAxios.get).toHaveBeenCalledTimes(1);
Expand All @@ -90,18 +94,23 @@ it('can get time slots for no particular user', async () => {
location_id: 1,
service_id: [1, 2],
start: '2018-01-01',
timezone,
},
});
});

it('can get time slots for a specified user', async () => {
const resource = new TimeSlot(mockAxios);

const timezones = ['America/Chicago', 'America/Toronto', 'Europe/Amsterdam', 'Europe/Paris'];
const timezone = timezones[Math.floor(Math.random() * timezones.length)];

await resource
.between('2018-01-01', '2018-01-31')
.at(1)
.for([1, 2])
.by(1)
.in(timezone)
.get();

expect(mockAxios.get).toHaveBeenCalledTimes(1);
Expand All @@ -112,6 +121,7 @@ it('can get time slots for a specified user', async () => {
service_id: [1, 2],
staff_id: 1,
start: '2018-01-01',
timezone,
},
});
});
Expand Down
5 changes: 5 additions & 0 deletions src/resources/time-slot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export interface TimeSlotParameters {
service_id?: number | number[];
staff_id?: number;
start?: string;
timezone?: string;
}

export interface TimeSlotResource extends Resource, ConditionalResource {
Expand Down Expand Up @@ -76,6 +77,10 @@ export default class TimeSlot extends Conditional implements TimeSlotResource {
start: this.filters.start,
};

if (this.filters.timezone) {
params.timezone = this.filters.timezone;
}

if (this.filters.user) {
params.staff_id = this.filters.user;
}
Expand Down

0 comments on commit 3456efe

Please sign in to comment.