Skip to content

Commit 1652103

Browse files
committed
fixed test cases getting failed
1 parent 8eacde5 commit 1652103

File tree

5 files changed

+76
-13
lines changed

5 files changed

+76
-13
lines changed

packages/backend/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"scripts": {
2424
"docker:up": "docker-compose up -d",
2525
"start": "node ./dist/index.js",
26-
"test": "jest --coverage --runInBand --transformIgnorePatterns 'node_modules/(?!(dm3-lib-\\w*)/)'",
26+
"test": "npm run docker:up && jest --coverage --runInBand --transformIgnorePatterns 'node_modules/(?!(dm3-lib-\\w*)/)'",
2727
"build": "yarn tsc && cp ./config.yml ./dist/config.yml | true",
2828
"createDeliveryServiceProfile": "node --no-warnings ./cli.js"
2929
},

packages/backend/src/notifications.test.ts

+16
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,22 @@ describe('Notifications', () => {
278278
},
279279
},
280280
]),
281+
getDeliveryServiceProperties: () => {
282+
return {
283+
notificationChannel: [
284+
{
285+
type: NotificationChannelType.EMAIL,
286+
config: {
287+
smtpHost: 'smtp.gmail.com',
288+
smtpPort: 587,
289+
smtpEmail: '[email protected]',
290+
smtpUsername: '[email protected]',
291+
smtpPassword: 'abcd1234',
292+
},
293+
},
294+
],
295+
};
296+
},
281297
addNewNotificationChannel: addNewNotificationChannelMock,
282298
addUsersNotificationChannel: addUsersNotificationChannelMock,
283299
setOtp: setOtpMock,

packages/lib/delivery/src/Messages.test.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@ import { stringify } from '../../shared/src/stringify';
77
import { getConversationId, getMessages, incomingMessage } from './Messages';
88
import { Session } from './Session';
99
import { SpamFilterRules } from './spam-filter/SpamFilterRules';
10-
import { NotificationChannelType } from './notifications/types';
11-
import { getDeliveryServiceProperties } from '../../../backend/src/config/getDeliveryServiceProperties';
10+
import {
11+
NotificationChannel,
12+
NotificationChannelType,
13+
} from './notifications/types';
1214

1315
const SENDER_NAME = 'alice.eth';
1416
const RECEIVER_NAME = 'bob.eth';
@@ -458,6 +460,19 @@ describe('Messages', () => {
458460
]);
459461
};
460462

463+
const dsNotificationChannels: NotificationChannel[] = [
464+
{
465+
type: NotificationChannelType.EMAIL,
466+
config: {
467+
smtpHost: 'smtp.gmail.com',
468+
smtpPort: 587,
469+
smtpEmail: '[email protected]',
470+
smtpUsername: '[email protected]',
471+
smtpPassword: 'abcd1234',
472+
},
473+
},
474+
];
475+
461476
await incomingMessage(
462477
{
463478
envelop: {
@@ -477,7 +492,7 @@ describe('Messages', () => {
477492
keysA.signingKeyPair,
478493
keysA.encryptionKeyPair,
479494
2 ** 14,
480-
getDeliveryServiceProperties().notificationChannel,
495+
dsNotificationChannels,
481496
getSession,
482497
storeNewMessage,
483498
sendMessageViaSocketMock,

packages/lib/delivery/src/Notification.test.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { NotificationChannel, NotificationChannelType } from './notifications';
22
import { addNewNotificationChannel } from './Notification';
3-
import { getDeliveryServiceProperties } from '../../../backend/src/config/getDeliveryServiceProperties';
43
const nodemailer = require('nodemailer');
54

65
jest.mock('nodemailer');
@@ -28,8 +27,18 @@ describe('Notification', () => {
2827
]);
2928
const setOtp = jest.fn();
3029

31-
const notificationChannels: NotificationChannel[] =
32-
getDeliveryServiceProperties().notificationChannel;
30+
const notificationChannels: NotificationChannel[] = [
31+
{
32+
type: NotificationChannelType.EMAIL,
33+
config: {
34+
smtpHost: 'smtp.gmail.com',
35+
smtpPort: 587,
36+
smtpEmail: '[email protected]',
37+
smtpUsername: '[email protected]',
38+
smtpPassword: 'abcd1234',
39+
},
40+
},
41+
];
3342

3443
const db = {
3544
getUsersNotificationChannels,

packages/lib/delivery/src/notifications/Notifications.test.ts

+29-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
11
import { DeliveryInformation } from '@dm3-org/dm3-lib-messaging';
2-
import { NotificationChannelType, NotificationType } from './types';
2+
import {
3+
NotificationChannel,
4+
NotificationChannelType,
5+
NotificationType,
6+
} from './types';
37
import {
48
NotificationBroker,
59
_setupNotficationBroker,
610
} from './broker/NotificationBroker';
7-
import { getDeliveryServiceProperties } from '../../../../backend/src/config/getDeliveryServiceProperties';
811

912
jest.mock('nodemailer');
1013

1114
describe('Notifications', () => {
1215
it('Send Email notification to verify OTP', async () => {
13-
const dsNotificationChannels =
14-
getDeliveryServiceProperties().notificationChannel;
16+
const dsNotificationChannels: NotificationChannel[] = [
17+
{
18+
type: NotificationChannelType.EMAIL,
19+
config: {
20+
smtpHost: 'smtp.gmail.com',
21+
smtpPort: 587,
22+
smtpEmail: '[email protected]',
23+
smtpUsername: '[email protected]',
24+
smtpPassword: 'abcd1234',
25+
},
26+
},
27+
];
1528

1629
const channel1 = {
1730
type: NotificationChannelType.EMAIL,
@@ -56,8 +69,18 @@ describe('Notifications', () => {
5669
});
5770

5871
it('Should not send email when notification channel is not verified', async () => {
59-
const dsNotificationChannels =
60-
getDeliveryServiceProperties().notificationChannel;
72+
const dsNotificationChannels: NotificationChannel[] = [
73+
{
74+
type: NotificationChannelType.EMAIL,
75+
config: {
76+
smtpHost: 'smtp.gmail.com',
77+
smtpPort: 587,
78+
smtpEmail: '[email protected]',
79+
smtpUsername: '[email protected]',
80+
smtpPassword: 'abcd1234',
81+
},
82+
},
83+
];
6184

6285
const channel1 = {
6386
type: NotificationChannelType.EMAIL,

0 commit comments

Comments
 (0)