mirror of
https://github.com/immich-app/immich.git
synced 2025-12-25 12:25:46 -08:00
73 lines
2.5 KiB
TypeScript
73 lines
2.5 KiB
TypeScript
import { EmailRenderRequest, EmailRepository, EmailTemplate } from 'src/repositories/email.repository';
|
|
import { LoggingRepository } from 'src/repositories/logging.repository';
|
|
import { automock } from 'test/utils';
|
|
|
|
describe(EmailRepository.name, () => {
|
|
let sut: EmailRepository;
|
|
|
|
beforeEach(() => {
|
|
// eslint-disable-next-line no-sparse-arrays
|
|
sut = new EmailRepository(automock(LoggingRepository, { args: [, { getEnv: () => ({}) }], strict: false }));
|
|
});
|
|
|
|
describe('renderEmail', () => {
|
|
it('should render the email correctly for TEST_EMAIL template', async () => {
|
|
const request: EmailRenderRequest = {
|
|
template: EmailTemplate.TEST_EMAIL,
|
|
data: { displayName: 'Alen Turing', baseUrl: 'http://localhost' },
|
|
customTemplate: '',
|
|
};
|
|
|
|
const result = await sut.renderEmail(request);
|
|
|
|
expect(result.html).toContain('<!DOCTYPE html PUBLIC');
|
|
expect(result.text).toContain('test email');
|
|
});
|
|
|
|
it('should render the email correctly for WELCOME template', async () => {
|
|
const request: EmailRenderRequest = {
|
|
template: EmailTemplate.WELCOME,
|
|
data: { displayName: 'Alen Turing', username: 'turing', baseUrl: 'http://localhost' },
|
|
customTemplate: '',
|
|
};
|
|
|
|
const result = await sut.renderEmail(request);
|
|
|
|
expect(result.html).toContain('<!DOCTYPE html PUBLIC');
|
|
expect(result.text).toContain('A new account has been created for you');
|
|
});
|
|
|
|
it('should render the email correctly for ALBUM_INVITE template', async () => {
|
|
const request: EmailRenderRequest = {
|
|
template: EmailTemplate.ALBUM_INVITE,
|
|
data: {
|
|
albumName: 'Vacation',
|
|
albumId: '123',
|
|
senderName: 'John',
|
|
recipientName: 'Jane',
|
|
baseUrl: 'http://localhost',
|
|
},
|
|
customTemplate: '',
|
|
};
|
|
|
|
const result = await sut.renderEmail(request);
|
|
|
|
expect(result.html).toContain('<!DOCTYPE html PUBLIC');
|
|
expect(result.text).toContain('Vacation');
|
|
});
|
|
|
|
it('should render the email correctly for ALBUM_UPDATE template', async () => {
|
|
const request: EmailRenderRequest = {
|
|
template: EmailTemplate.ALBUM_UPDATE,
|
|
data: { albumName: 'Holiday', albumId: '123', recipientName: 'Jane', baseUrl: 'http://localhost' },
|
|
customTemplate: '',
|
|
};
|
|
|
|
const result = await sut.renderEmail(request);
|
|
|
|
expect(result.html).toContain('<!DOCTYPE html PUBLIC');
|
|
expect(result.text).toContain('Holiday');
|
|
});
|
|
});
|
|
});
|