Skip to content

Commit

Permalink
Test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
deepaksftc committed Jul 25, 2024
1 parent f02e637 commit 3dda24d
Showing 1 changed file with 48 additions and 0 deletions.
48 changes: 48 additions & 0 deletions apps/backend/src/eventHandlers/MailService/SMTPMailService.spec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,59 @@
import * as path from 'path';

import { container } from 'tsyringe';

import { Tokens } from '../../config/Tokens';
import { AdminDataSource } from '../../datasources/AdminDataSource';
import { SettingsId } from '../../models/Settings';
import EmailSettings from './EmailSettings';
import { SMTPMailService } from './SMTPMailService';

jest.mock('email-templates');
const mockAdminDataSource = container.resolve(
Tokens.AdminDataSource
) as AdminDataSource;

test('Return result should indicate all emails were successfully sent', async () => {
jest.spyOn(mockAdminDataSource, 'getSetting').mockResolvedValue(null);

const options: EmailSettings = {
content: {
template_id: path.resolve('src', 'eventHandlers', 'emails', 'submit'),
},
substitution_data: {
piPreferredname: 'John',
piLastname: 'Doe',
proposalNumber: '1',
proposalTitle: 'Title',
coProposers: ['Jane Doe'],
call: '',
},
recipients: [
{
address: 'john.doe@email.com',
},
],
};

const smtpMailService: SMTPMailService = new SMTPMailService();
const result = await smtpMailService.sendMail(options);

return expect(result).toStrictEqual({
results: {
id: 'test',
total_accepted_recipients: 1,
total_rejected_recipients: 0,
},
});
});

test('All emails with bcc were successfully sent', async () => {
jest.spyOn(mockAdminDataSource, 'getSetting').mockResolvedValue({
settingsValue: 'testmail@test.co',
description: 'bcc mail',
id: SettingsId.BCC_EMAIL,
});

const options: EmailSettings = {
content: {
template_id: path.resolve('src', 'eventHandlers', 'emails', 'submit'),
Expand Down

0 comments on commit 3dda24d

Please sign in to comment.