Skip to content

Commit

Permalink
Adds timezone resource
Browse files Browse the repository at this point in the history
  • Loading branch information
coconutcraig committed May 29, 2019
1 parent a0e3f27 commit cef6cd2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Question from './resources/question';
import Service from './resources/service';
import Setting from './resources/setting';
import TimeSlot from './resources/time-slot';
import Timezone from './resources/timezone';
import User from './resources/user';
import WaitList from './resources/wait-list';

Expand Down Expand Up @@ -70,3 +71,10 @@ it('can access the appointment resource', async () => {
expect(instance).toHaveProperty('appointments');
expect(instance.appointments).toBeInstanceOf(Appointment.prototype.constructor);
});

it('can access the timezone resource', async () => {
const instance = new OpenApi('admin');

expect(instance).toHaveProperty('timezones');
expect(instance.timezones).toBeInstanceOf(Timezone.prototype.constructor);
});
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,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 User, { UserResource } from './resources/user';
import WaitList, { WaitListResource } from './resources/wait-list';

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

constructor(domain?: string) {
Expand All @@ -68,6 +70,7 @@ export class OpenApi {
this.service = new Service(this.client);
this.setting = new Setting(this.client);
this.slot = new TimeSlot(this.client);
this.timezone = new Timezone(this.client);
this.user = new User(this.client);
}

Expand Down Expand Up @@ -99,6 +102,10 @@ export class OpenApi {
return this.slot;
}

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

get users(): UserResource {
return this.user;
}
Expand Down
12 changes: 12 additions & 0 deletions src/resources/timezone.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import mockAxios from 'axios';

import Timezone from './timezone';

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

await resource.get();

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

import { Resource } from '../index';

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

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

public async get(): Promise<any> {
return await this.client.get('timezones');
}
}

0 comments on commit cef6cd2

Please sign in to comment.