[feature] Notification service added

This commit is contained in:
Georgii Petrov
2024-04-23 17:08:02 +03:00
parent d2895a5500
commit 44e4d28b55
6 changed files with 234 additions and 20 deletions

View File

@ -1,20 +1,19 @@
const { describe, test, expect, afterAll} = require('@jest/globals');
const { describe, test, expect, afterAll } = require('@jest/globals');
const nodemailer = require('../../Common/node_modules/nodemailer');
const mailService = require('../../Common/sources/mailService');
const operationContext = require('../../Common/sources/operationContext');
const ctx = new operationContext.Context();
const defaultTestSMTPServer = {
host: 'smtp.ethereal.email',
port: 587
};
const testTimeout = 1000 * 10;
afterAll(function () {
mailService.transportersRelease();
})
describe('Mail service', function () {
console.log('!!!!!!!!!!!!!!!!', global.dev);
describe('SMTP', function () {
const { host, port } = defaultTestSMTPServer;
@ -23,7 +22,7 @@ describe('Mail service', function () {
// Ethereial is a special SMTP sever for mailing tests in collaboration with Nodemailer.
const accounts = await Promise.all([nodemailer.createTestAccount(), nodemailer.createTestAccount(), nodemailer.createTestAccount()]);
const auth = accounts.map(account => { return { user: account.user, pass: account.pass }});
auth.forEach(credential => mailService.createTransporter(ctx, host, port, credential, { from: 'some.mail@ethereal.com' }));
auth.forEach(credential => mailService.createTransporter(host, port, credential, { from: 'some.mail@ethereal.com' }));
for (let i = 0; i < auth.length; i++) {
const credentials = auth[i];
@ -37,7 +36,7 @@ describe('Mail service', function () {
}
const accountToBeDeleted = auth[1];
mailService.deleteTransporter(ctx, host, accountToBeDeleted.user);
mailService.deleteTransporter(host, accountToBeDeleted.user);
const errorPromise = mailService.send(
host,
@ -46,6 +45,6 @@ describe('Mail service', function () {
);
await expect(errorPromise).rejects.toEqual(`MailService: no transporter exists for host "${host}" and user "${accountToBeDeleted.user}"`);
});
}, testTimeout);
});
});