Skip to content

Commit

Permalink
Ensures a booker identifier can be sent when adding attendees to exis…
Browse files Browse the repository at this point in the history
…ting appointments
  • Loading branch information
craigpaul committed Nov 26, 2019
1 parent 5b96f21 commit 44c92db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
5 changes: 4 additions & 1 deletion src/resources/appointment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ it('can add the given attendee to the given appointment', async () => {
const resource = new Appointment(mockAxios);
const attendee = (new Attendee()).named('Jane', 'Doe').reachable({ email: '[email protected]' });

await resource.with(attendee).add(1);
await resource.with(attendee).actingAs(10).add(1);

expect(mockAxios.put).toHaveBeenCalledTimes(1);
expect(mockAxios.put).toHaveBeenCalledWith('appointments/1/attendees', {
Expand All @@ -304,6 +304,9 @@ it('can add the given attendee to the given appointment', async () => {
type: 'attendees',
}
],
meta: {
booker: 10,
},
}, {
headers: {
'Content-Type': 'application/json; ext=bulk',
Expand Down
21 changes: 16 additions & 5 deletions src/resources/appointment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ interface AddSingleAttendeeParameter {

export interface AddAttendeeParameters {
data: AddSingleAttendeeParameter[],
meta?: {
booker?: number;
}
}

export interface AppointmentResource extends Resource, ConditionalResource {
Expand Down Expand Up @@ -271,10 +274,18 @@ export default class Appointment extends Conditional implements AppointmentResou
return this;
}

protected addParams(): AddAttendeeParameters | object {
return {
protected addParams(): AddAttendeeParameters {
const params: AddAttendeeParameters = {
data: this.transformAttendees(),
};

if (this.meta.booker) {
params.meta = {
booker: this.meta.booker,
};
}

return params;
}

protected hasUtm(): boolean {
Expand Down Expand Up @@ -380,10 +391,10 @@ export default class Appointment extends Conditional implements AppointmentResou
return params;
}

protected transformAttendees() {
protected transformAttendees(): AddSingleAttendeeParameter[] {
return (this.relationships.attendees as AttendeeModel[]).map(
(attendee: AttendeeModel): object => {
return attendee.transform();
(attendee: AttendeeModel): AddSingleAttendeeParameter => {
return (attendee.transform() as AddSingleAttendeeParameter);
}
);
}
Expand Down

0 comments on commit 44c92db

Please sign in to comment.