2026-06-01 16:24:31 +02:00
|
|
|
import { describe, it, expect } from 'vitest'
|
|
|
|
|
import {
|
|
|
|
|
getMentorBulkAssignmentTemplate,
|
|
|
|
|
getTeamMentorIntroductionTemplate,
|
|
|
|
|
} from '@/lib/email'
|
|
|
|
|
|
|
|
|
|
describe('getMentorBulkAssignmentTemplate', () => {
|
|
|
|
|
it('includes team-member emails, the instructions block, and a custom note', () => {
|
|
|
|
|
const t = getMentorBulkAssignmentTemplate(
|
|
|
|
|
'Alice',
|
|
|
|
|
[
|
|
|
|
|
{
|
|
|
|
|
title: 'Reef Project',
|
|
|
|
|
url: 'https://x/mentor/workspace/1',
|
|
|
|
|
teamMembers: [{ name: 'Bob', email: 'bob@team.com' }],
|
|
|
|
|
},
|
|
|
|
|
],
|
|
|
|
|
'https://x/mentor',
|
2026-06-01 16:28:32 +02:00
|
|
|
'Reach out <b>now</b> & soon',
|
2026-06-01 16:24:31 +02:00
|
|
|
)
|
|
|
|
|
expect(t.html).toContain('bob@team.com')
|
|
|
|
|
expect(t.html).toContain('How to mentor on MOPC')
|
2026-06-01 16:28:32 +02:00
|
|
|
// The admin-supplied custom note must be HTML-escaped in the HTML body.
|
|
|
|
|
expect(t.html).toContain('<b>')
|
|
|
|
|
expect(t.html).not.toContain('<b>now</b>')
|
2026-06-01 16:24:31 +02:00
|
|
|
expect(t.text).toContain('bob@team.com')
|
|
|
|
|
expect(t.text).toContain('How to mentor on MOPC')
|
2026-06-01 16:28:32 +02:00
|
|
|
// The plain-text body keeps the raw note unescaped.
|
|
|
|
|
expect(t.text).toContain('Reach out <b>now</b> & soon')
|
2026-06-01 16:24:31 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('renders without team members or note (backward compatible)', () => {
|
|
|
|
|
const t = getMentorBulkAssignmentTemplate(
|
|
|
|
|
'Alice',
|
|
|
|
|
[{ title: 'P', url: 'https://x/p' }],
|
|
|
|
|
'https://x/mentor',
|
|
|
|
|
)
|
|
|
|
|
expect(t.html).toContain('How to mentor on MOPC')
|
|
|
|
|
// Custom-note box uses the #fff7ed background; absent when no note passed.
|
|
|
|
|
expect(t.html).not.toContain('#fff7ed')
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
describe('getTeamMentorIntroductionTemplate', () => {
|
|
|
|
|
it('includes mentor + teammate emails, the instructions block, and a custom note', () => {
|
|
|
|
|
const t = getTeamMentorIntroductionTemplate(
|
|
|
|
|
'Bob',
|
|
|
|
|
'Reef Project',
|
|
|
|
|
[{ name: 'Alice', email: 'alice@mentor.com' }],
|
|
|
|
|
'https://x/applicant/mentor',
|
|
|
|
|
[{ name: 'Carol', email: 'carol@team.com' }],
|
|
|
|
|
'Welcome aboard!',
|
|
|
|
|
)
|
|
|
|
|
expect(t.html).toContain('alice@mentor.com')
|
|
|
|
|
expect(t.html).toContain('carol@team.com')
|
|
|
|
|
expect(t.html).toContain('Working with your mentor')
|
|
|
|
|
expect(t.html).toContain('Welcome aboard!')
|
2026-06-01 16:28:32 +02:00
|
|
|
// Mirror coverage on the plain-text path.
|
|
|
|
|
expect(t.text).toContain('alice@mentor.com')
|
|
|
|
|
expect(t.text).toContain('carol@team.com')
|
|
|
|
|
expect(t.text).toContain('Welcome aboard!')
|
2026-06-01 16:24:31 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
it('renders without teammates or note (backward compatible)', () => {
|
|
|
|
|
const t = getTeamMentorIntroductionTemplate(
|
|
|
|
|
'Bob',
|
|
|
|
|
'Reef Project',
|
|
|
|
|
[{ name: 'Alice', email: 'alice@mentor.com' }],
|
|
|
|
|
'https://x/applicant/mentor',
|
|
|
|
|
)
|
|
|
|
|
expect(t.html).toContain('Working with your mentor')
|
|
|
|
|
expect(t.html).not.toContain('#fff7ed')
|
|
|
|
|
})
|
|
|
|
|
})
|