diff --git a/cypress/integration/dashboard/events.js b/cypress/integration/dashboard/events.js index ddb0edf241..e3f54e178e 100644 --- a/cypress/integration/dashboard/events.js +++ b/cypress/integration/dashboard/events.js @@ -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(); + }); }); diff --git a/server/src/controllers/Events/resolver.ts b/server/src/controllers/Events/resolver.ts index ceee1c09ed..9ae284a436 100644 --- a/server/src/controllers/Events/resolver.ts +++ b/server/src/controllers/Events/resolver.ts @@ -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
-${venue.name}
+${venue.name}
${venue.street_address ? venue.street_address + '
' : ''} ${venue.city}
${venue.region}
@@ -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; }