Skip to content

Commit

Permalink
Adds meeting method to appointment resource with appropriate constant…
Browse files Browse the repository at this point in the history
… declarations
  • Loading branch information
craigpaul committed Jan 14, 2020
1 parent c52bf1d commit 3466102
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 12 deletions.
17 changes: 17 additions & 0 deletions src/constants/meeting-methods.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
export default class MeetingMethods {
static get AT_LOCATION() {
return 1;
}

static get PHONE_CALL() {
return 2;
}

static get VIDEO_CALL() {
return 3;
}

static get OFF_SITE() {
return 4;
}
}
3 changes: 2 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { AxiosInstance } from 'axios';

import Client from './client';
import Days from './constants/days';
import MeetingMethods from "./constants/meeting-methods";
import Notifications from './constants/notifications';
import Visibilities from "./constants/visibilities";
import Answer from './models/answer';
Expand Down Expand Up @@ -48,7 +49,7 @@ export interface Sortable extends Resource {
sortBy(sortable: string): this;
}

export { Answer, Attendee, Days, Notifications, Preference, Response, Visibilities };
export { Answer, Attendee, Days, MeetingMethods, Notifications, Preference, Response, Visibilities };

export class OpenApi {
protected appointment: AppointmentResource;
Expand Down
35 changes: 24 additions & 11 deletions src/resources/appointment.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import mockAxios from 'axios';

import MeetingMethods from "../constants/meeting-methods";
import Notifications from '../constants/notifications';
import Answer from '../models/answer';
import Attendee from '../models/attendee';
import Response from '../models/response';
import Appointment, { AppointmentMatcherParameters, AppointmentNotificationParameters } from './appointment';
import Appointment, {AppointmentMatcherParameters, AppointmentNotificationParameters} from './appointment';

it('can set the invitation property', async () => {
const resource = new Appointment(mockAxios);
Expand All @@ -30,6 +31,15 @@ it('can set the user property', async () => {
});
});

it('can set the meeting method property', async () => {
const resource = new Appointment(mockAxios);
const { PHONE_CALL } = MeetingMethods;

expect(resource.method(PHONE_CALL)).toHaveProperty('filters', {
method: PHONE_CALL,
});
});

it('can set the service property using a single number', async () => {
const resource = new Appointment(mockAxios);

Expand Down Expand Up @@ -179,15 +189,17 @@ it('can book an appointment with all available parameters', async () => {
const start = '2018-01-01 12:00:00';
const attendee = new Attendee();
const answer = new Answer();
const { PHONE_CALL } = MeetingMethods;
const notifications = [Notifications.CLIENT, Notifications.USER, Notifications.ALL];

notifications.forEach(async (notification: object) => {
for (const notification of notifications) {
await resource
.at(1)
.for([2, 3])
.by(4)
.via(5)
.starting(start)
.method(PHONE_CALL)
.campaign('test campaign')
.content('test content')
.medium('test medium')
Expand Down Expand Up @@ -224,6 +236,7 @@ it('can book an appointment with all available parameters', async () => {
attributes: {
invitation_id: 5,
location_id: 1,
meeting_method: PHONE_CALL,
service_id: [2, 3],
staff_id: 4,
start,
Expand Down Expand Up @@ -281,9 +294,9 @@ it('can book an appointment with all available parameters', async () => {
},
},
});
}

expect(mockAxios.post).toHaveBeenCalledTimes(3);
});
expect(mockAxios.post).toHaveBeenCalledTimes(3);
});

it('can add the given attendee to the given appointment', async () => {
Expand Down Expand Up @@ -492,8 +505,8 @@ it('can reschedule an appointment with the minimum required parameters', async (
const start = '2018-01-01 12:00:00';

await resource
.starting(start)
.reschedule(1);
.starting(start)
.reschedule(1);

expect(mockAxios.patch).toHaveBeenCalledTimes(1);
expect(mockAxios.patch).toHaveBeenCalledWith('appointments/1', {
Expand All @@ -512,11 +525,11 @@ it('can reschedule an appointment with all available parameters', async () => {
const start = '2018-01-01 12:00:00';
const notifications = [Notifications.CLIENT, Notifications.USER, Notifications.ALL];

notifications.forEach(async (notification: object) => {
for (const notification of notifications) {
await resource
.starting(start)
.notify(notification)
.reschedule(1);
.starting(start)
.notify(notification)
.reschedule(1);

expect(mockAxios.patch).toHaveBeenCalledWith('appointments/1', {
data: {
Expand All @@ -530,7 +543,7 @@ it('can reschedule an appointment with all available parameters', async () => {
notify: notification,
},
});
});
}

expect(mockAxios.patch).toHaveBeenCalledTimes(3);
});
14 changes: 14 additions & 0 deletions src/resources/appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AppointmentFilter {
invitation?: number;
location?: number;
matchers?: AppointmentMatcherParameters;
method?: number;
notifications?: AppointmentNotificationParameters;
services?: number | number[];
start?: string;
Expand Down Expand Up @@ -38,6 +39,7 @@ export interface AppointmentParameters {
attributes?: {
invitation_id: number | null;
location_id: number | undefined;
meeting_method?: number;
service_id: number | number[] | undefined;
staff_id: number | null;
start: string | undefined;
Expand Down Expand Up @@ -118,6 +120,8 @@ export interface AppointmentResource extends Resource, ConditionalResource {

matching(matchers: AppointmentMatcherParameters): this;

method(method: number): this;

notify(notifications: AppointmentNotificationParameters): this;

reschedule(appointment: number): Promise<any>;
Expand Down Expand Up @@ -238,6 +242,12 @@ export default class Appointment extends Conditional implements AppointmentResou
return this;
}

public method(method: number): this {
this.filters.method = method;

return this;
}

public notify(notifications: AppointmentNotificationParameters): this {
this.filters.notifications = notifications;

Expand Down Expand Up @@ -339,6 +349,10 @@ export default class Appointment extends Conditional implements AppointmentResou
if (this.filters.invitation) {
params.data.attributes.invitation_id = this.filters.invitation;
}

if (this.filters.method) {
params.data.attributes.meeting_method = this.filters.method;
}
}

if (this.filters.notifications) {
Expand Down

0 comments on commit 3466102

Please sign in to comment.