Skip to content
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 apps/backend/src/eventHandlers/email/essEmailHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,42 @@ describe('essEmailHandler co-proposer invites', () => {
);
});

it('should send mail when co-proposer invite is accepted', async () => {
const mockInvite = new Invite(
1,
faker.string.alphanumeric(8),
dummyUser.email,
new Date(),
dummyUser.id,
new Date(),
dummyUser.id,
false,
null,
EmailTemplateId.CO_PROPOSER_INVITE_ACCEPTED
);

// Mock userDataSource.getUser to return dummyUser for principal investigator but null for claimer
const getUserMock = jest.spyOn(userDataSourceMock, 'getUser');
getUserMock
.mockResolvedValueOnce(dummyUser) // First call for principal investigator
.mockResolvedValueOnce(dummyUser); // Second call for claimer

const event: ApplicationEvent = {
type: Event.PROPOSAL_CO_PROPOSER_INVITE_ACCEPTED,
invite: mockInvite,
key: 'invite',
loggedInUserId: 3,
isRejection: false,
proposalPKey: 1,
};

const sendMailsSpy = jest.spyOn(mockMailService, 'sendMail');

await essEmailHandler(event);

expect(sendMailsSpy).toHaveBeenCalled();
});

describe('handling PROPOSAL_SUBMITTED event', () => {
it('Should have PI and CoProposals in the payload', async () => {
const event: ApplicationEvent = {
Expand Down
4 changes: 0 additions & 4 deletions apps/backend/src/eventHandlers/email/essEmailHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,6 @@ export async function essEmailHandler(event: ApplicationEvent) {
Tokens.CoProposerClaimDataSource
);

const inviteDataSource = container.resolve<InviteDataSource>(
Tokens.InviteDataSource
);

const callDataSource = container.resolve<CallDataSource>(
Tokens.CallDataSource
);
Expand Down
9 changes: 4 additions & 5 deletions apps/backend/src/mutations/InviteMutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ export default class InviteMutations {
return rejection('Invite code has expired', { invite: code });
}

await this.processAcceptedRoleClaims(agent!.id, invite);
await this.processAcceptedCoProposerClaims(agent!.id, invite);
await this.processAcceptedVisitRegistrationClaims(agent!.id, invite);

const updatedInvite = await this.inviteDataSource.update({
id: invite.id,
claimedAt: new Date(),
claimedByUserId: agent!.id,
});

await this.processAcceptedRoleClaims(agent!.id, updatedInvite);
await this.processAcceptedCoProposerClaims(agent!.id, updatedInvite);
await this.processAcceptedVisitRegistrationClaims(agent!.id, updatedInvite);

return updatedInvite;
}

Expand Down Expand Up @@ -282,7 +282,6 @@ export default class InviteMutations {
if (proposalHasUser) {
return;
}

await this.proposalDataSource.addProposalUser(
claim.proposalPk,
claimerUserId
Expand Down