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
74 changes: 74 additions & 0 deletions __tests__/workers/newNotificationV2Mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ import {
Reference,
type NotificationAwardContext,
type NotificationOpportunityMatchContext,
type NotificationWarmIntroContext,
} from '../../src/notifications';
import { postsFixture } from '../fixture/post';
import { sourcesFixture } from '../fixture/source';
Expand Down Expand Up @@ -96,6 +97,8 @@ import { BriefPost } from '../../src/entity/posts/BriefPost';
import { CampaignUpdateEvent } from '../../src/common/campaign/common';
import { Opportunity } from '../../src/entity/opportunities/Opportunity';
import { OpportunityMatch } from '../../src/entity/OpportunityMatch';
import { OpportunityUserRecruiter } from '../../src/entity/opportunities/user';
import { OpportunityUserType } from '../../src/entity/opportunities/types';
import {
opportunitiesFixture,
opportunityMatchesFixture,
Expand Down Expand Up @@ -2749,3 +2752,74 @@ describe('poll result notifications', () => {
expect(args.transactional_message_id).toEqual('84');
});
});

describe('warm_intro notification', () => {
it('should send email to both candidate and recruiter', async () => {
await saveFixtures(con, Organization, organizationsFixture);
await saveFixtures(con, Opportunity, opportunitiesFixture);
await saveFixtures(con, OpportunityMatch, opportunityMatchesFixture);

// Create a recruiter user
const recruiter = await con.getRepository(User).save({
id: 'recruiter123',
name: 'John Recruiter',
email: 'recruiter@test.com',
username: 'recruiter',
});

// Link recruiter to opportunity
await con.getRepository(OpportunityUserRecruiter).save({
opportunityId: opportunitiesFixture[0].id,
userId: recruiter.id,
type: OpportunityUserType.Recruiter,
});

// Update opportunity match with warmIntro
await con.getRepository(OpportunityMatch).update(
{
opportunityId: opportunitiesFixture[0].id,
userId: '1',
},
{
applicationRank: {
warmIntro: '<p>Great match based on your experience!</p>',
},
},
);

const ctx: NotificationWarmIntroContext = {
userIds: ['1'],
opportunityId: opportunitiesFixture[0].id,
description: 'Great match based on your experience!',
recruiter,
organization: organizationsFixture[0],
};

const notificationId = await saveNotificationV2Fixture(
con,
NotificationType.WarmIntro,
ctx,
);

await expectSuccessfulBackground(worker, {
notification: {
id: notificationId,
userId: '1',
},
});

expect(sendEmail).toHaveBeenCalledTimes(1);
const args = jest.mocked(sendEmail).mock
.calls[0][0] as SendEmailRequestWithTemplate;

expect(args.message_data).toEqual({
title: `It's a match!`,
copy: '<p>Great match based on your experience!</p>',
cc: 'recruiter@test.com',
});

// Verify both emails are in the 'to' field
expect(args.to).toEqual('ido@daily.dev,recruiter@test.com');
expect(args.transactional_message_id).toEqual('85');
});
});
18 changes: 17 additions & 1 deletion src/workers/newNotificationV2Mail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import { generateCampaignPostEmail } from '../common/campaign/post';
import { generateCampaignSquadEmail } from '../common/campaign/source';
import { PollPost } from '../entity/posts/PollPost';
import { OpportunityMatch } from '../entity/OpportunityMatch';
import { OpportunityUserRecruiter } from '../entity/opportunities/user';

interface Data {
notification: ChangeObject<NotificationV2>;
Expand Down Expand Up @@ -1132,9 +1133,17 @@ const notificationToTemplateData: Record<NotificationType, TemplateDataFunc> = {
return null;
}

const recruiterUser = await con
.getRepository(OpportunityUserRecruiter)
.findOneBy({
opportunityId: notif.referenceId,
});
const recruiter = await recruiterUser?.user;

return {
title: `It's a match!`,
copy: warmIntro,
cc: recruiter?.email,
};
},
};
Expand Down Expand Up @@ -1206,7 +1215,14 @@ const worker: Worker = {
identifiers: {
id: user.id,
},
to: user.email,
to: [
user.email,
!isNullOrUndefined(templateData?.cc)
? templateData.cc
: undefined,
]
.filter(Boolean)
.join(','),
send_at:
!isNullOrUndefined(templateData.sendAtMs) &&
templateData.sendAtMs > Date.now()
Expand Down
Loading