Skip to content

Commit

Permalink
Adds ability to supply a country to narrow down timezones
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed Aug 24, 2019
1 parent cdc2f2d commit 692ff3d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import Question, { QuestionResource } from './resources/question';
import Service, { ServiceResource } from './resources/service';
import Setting from './resources/setting';
import TimeSlot, { TimeSlotResource } from './resources/time-slot';
import Timezone from './resources/timezone';
import Timezone, { TimezoneResource } from './resources/timezone';
import User, { UserResource } from './resources/user';
import WaitList, { WaitListResource } from './resources/wait-list';

Expand Down Expand Up @@ -60,7 +60,7 @@ export class OpenApi {
protected service: ServiceResource;
protected setting: Resource;
protected slot: TimeSlotResource;
protected timezone: Resource;
protected timezone: TimezoneResource;
protected user: UserResource;

constructor(domain?: string) {
Expand Down Expand Up @@ -110,7 +110,7 @@ export class OpenApi {
return this.slot;
}

public timezones(): Resource {
public timezones(): TimezoneResource {
return this.timezone;
}

Expand Down
9 changes: 9 additions & 0 deletions src/resources/timezone.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,12 @@ it('can get timezones', async () => {
expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('timezones');
});

it('can get timezones for a specific country', async () => {
const resource = new Timezone(mockAxios);

await resource.get('ca');

expect(mockAxios.get).toHaveBeenCalledTimes(1);
expect(mockAxios.get).toHaveBeenCalledWith('timezones/ca');
});
16 changes: 12 additions & 4 deletions src/resources/timezone.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { AxiosInstance } from 'axios';

import { Resource } from '../index';
export interface TimezoneResource {
get(country?: string): Promise<any>;
}

export default class Timezone implements Resource {
export default class Timezone implements TimezoneResource {
protected client: AxiosInstance;

constructor(client: AxiosInstance) {
this.client = client;
}

public async get(): Promise<any> {
return await this.client.get('timezones');
public async get(country?: string): Promise<any> {
let url = 'timezones';

if (country) {
url += `/${country}`;
}

return await this.client.get(url);
}
}

0 comments on commit 692ff3d

Please sign in to comment.