Skip to content
This repository has been archived by the owner on Jun 9, 2023. It is now read-only.

feat: send emails to rsvps on event cancel #842

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions cypress/integration/dashboard/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,4 +219,40 @@ describe('events dashboard', () => {
});
});
});

it('emails not cancelled rsvps when event is cancelled', () => {
cy.visit('/dashboard/events');
cy.findAllByRole('row')
.not(':contains("canceled")')
.find('a')
.first('contains(/dashboard/events/\\d+$)')
.click()
.invoke('text')
.as('eventTitle');

cy.findByRole('button', { name: 'Cancel' }).click();
cy.findByRole('alertdialog').findByText('Confirm').click();

cy.waitUntilMail('allMail');
cy.get('@allMail').mhFirst().as('emails');

cy.url()
.then((url) => parseInt(url.match(/\d+$/)))
.as('eventId');
cy.get('@eventId')
.then((eventId) => cy.getRSVPs(eventId))
.then((rsvps) => {
const expectedEmails = rsvps
.filter((rsvp) => !rsvp.canceled)
.map(({ user: { email } }) => email);
cy.get('@emails')
.mhGetRecipients()
.should('have.members', expectedEmails);
});

cy.get('@eventTitle').then((eventTitle) => {
cy.get('@emails').mhGetSubject().should('include', eventTitle);
});
cy.mhDeleteAll();
});
});
18 changes: 17 additions & 1 deletion server/src/controllers/Events/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ ${unsubscribe}
const subject = `Venue changed for event ${event.name}`;
const body = `We have had to change the location of ${event.name}.
The event is now being held at <br>
${venue.name} <br>
${venue.name} <br>
${venue.street_address ? venue.street_address + '<br>' : ''}
${venue.city} <br>
${venue.region} <br>
Expand All @@ -383,6 +383,22 @@ ${unsubscribe}
data: { canceled: true },
});

const notCancelledRsvps = await prisma.rsvps.findMany({
where: {
event_id: id,
canceled: false,
},
include: { user: true },
});

if (notCancelledRsvps) {
const emailList = notCancelledRsvps.map((rsvp) => rsvp.user.email);
const subject = `Event ${event.name} cancelled`;
const body = `placeholder body`;

new MailerService(emailList, subject, body).sendEmail();
}

return event;
}

Expand Down