diff --git a/src/constants/meeting-methods.ts b/src/constants/meeting-methods.ts new file mode 100644 index 0000000..88142e6 --- /dev/null +++ b/src/constants/meeting-methods.ts @@ -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; + } +} diff --git a/src/index.ts b/src/index.ts index 670777a..3a4b1f8 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; @@ -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; diff --git a/src/resources/appointment.test.ts b/src/resources/appointment.test.ts index 3fc9630..eaec8de 100644 --- a/src/resources/appointment.test.ts +++ b/src/resources/appointment.test.ts @@ -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); @@ -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); @@ -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') @@ -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, @@ -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 () => { @@ -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', { @@ -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: { @@ -530,7 +543,7 @@ it('can reschedule an appointment with all available parameters', async () => { notify: notification, }, }); - }); + } expect(mockAxios.patch).toHaveBeenCalledTimes(3); }); diff --git a/src/resources/appointment.ts b/src/resources/appointment.ts index 2888872..b2a3d61 100644 --- a/src/resources/appointment.ts +++ b/src/resources/appointment.ts @@ -8,6 +8,7 @@ export interface AppointmentFilter { invitation?: number; location?: number; matchers?: AppointmentMatcherParameters; + method?: number; notifications?: AppointmentNotificationParameters; services?: number | number[]; start?: string; @@ -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; @@ -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; @@ -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; @@ -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) {