Skip to content

Commit e5ce076

Browse files
committed
added DS properties as parameter in notification
1 parent c55360a commit e5ce076

File tree

3 files changed

+39
-39
lines changed

3 files changed

+39
-39
lines changed

packages/backend/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,10 @@ global.logger = winston.createLogger({
7070
app.use('/storage', Storage());
7171
app.use('/auth', Auth());
7272
app.use('/delivery', Delivery());
73-
app.use('/notifications', Notifications(getDeliveryServiceProperties));
73+
app.use(
74+
'/notifications',
75+
Notifications(app.locals.deliveryServiceProperties),
76+
);
7477
app.use('/rpc', RpcProxy(new Axios({ url: process.env.RPC })));
7578
app.use(logError);
7679
app.use(errorHandler);

packages/backend/src/notifications.test.ts

+33-34
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ import express from 'express';
33
import auth from './auth';
44
import request from 'supertest';
55
import notifications from './notifications';
6-
import { NotificationChannelType } from '@dm3-org/dm3-lib-delivery';
6+
import {
7+
DeliveryServiceProperties,
8+
NotificationChannelType,
9+
} from '@dm3-org/dm3-lib-delivery';
710

811
const keysA = {
912
encryptionKeyPair: {
@@ -20,19 +23,17 @@ const keysA = {
2023
};
2124

2225
describe('Notifications', () => {
23-
const getDeliveryServiceProperties = () => {
24-
return {
25-
messageTTL: 12345,
26-
sizeLimit: 456,
27-
notificationChannel: [],
28-
};
26+
const deliveryServiceProperties: DeliveryServiceProperties = {
27+
messageTTL: 12345,
28+
sizeLimit: 456,
29+
notificationChannel: [],
2930
};
3031

3132
describe('get NotificationChannels', () => {
3233
it('Returns empty array as global notification is turned off', async () => {
3334
const app = express();
3435
app.use(bodyParser.json());
35-
app.use(notifications(getDeliveryServiceProperties));
36+
app.use(notifications(deliveryServiceProperties));
3637

3738
const token = await createAuthToken();
3839

@@ -81,7 +82,7 @@ describe('Notifications', () => {
8182
it('Returns 200 with empty notification channels as global notification is turned on', async () => {
8283
const app = express();
8384
app.use(bodyParser.json());
84-
app.use(notifications(getDeliveryServiceProperties));
85+
app.use(notifications(deliveryServiceProperties));
8586

8687
const token = await createAuthToken();
8788

@@ -132,7 +133,7 @@ describe('Notifications', () => {
132133
it('Returns 400 on setup email notifications as email ID is invalid', async () => {
133134
const app = express();
134135
app.use(bodyParser.json());
135-
app.use(notifications(getDeliveryServiceProperties));
136+
app.use(notifications(deliveryServiceProperties));
136137

137138
const token = await createAuthToken();
138139
const addUsersNotificationChannelMock = jest.fn();
@@ -172,7 +173,7 @@ describe('Notifications', () => {
172173
it('Returns 400 on setup email notifications as notificationChannelType is invalid', async () => {
173174
const app = express();
174175
app.use(bodyParser.json());
175-
app.use(notifications(getDeliveryServiceProperties));
176+
app.use(notifications(deliveryServiceProperties));
176177

177178
const token = await createAuthToken();
178179
const addUsersNotificationChannelMock = jest.fn();
@@ -212,7 +213,7 @@ describe('Notifications', () => {
212213
it('Returns 400 on setup email notifications as globalNotifications is turned off', async () => {
213214
const app = express();
214215
app.use(bodyParser.json());
215-
app.use(notifications(getDeliveryServiceProperties));
216+
app.use(notifications(deliveryServiceProperties));
216217

217218
const token = await createAuthToken();
218219
const addUsersNotificationChannelMock = jest.fn();
@@ -252,28 +253,26 @@ describe('Notifications', () => {
252253
});
253254

254255
it('User can setup email notifications', async () => {
255-
const getDeliveryServiceProperties = () => {
256-
return {
257-
messageTTL: 12345,
258-
sizeLimit: 456,
259-
notificationChannel: [
260-
{
261-
type: NotificationChannelType.EMAIL,
262-
config: {
263-
smtpHost: 'smtp.gmail.com',
264-
smtpPort: 587,
265-
smtpEmail: '[email protected]',
266-
smtpUsername: '[email protected]',
267-
smtpPassword: 'abcd1234',
268-
},
256+
const deliveryServiceProperties: DeliveryServiceProperties = {
257+
messageTTL: 12345,
258+
sizeLimit: 456,
259+
notificationChannel: [
260+
{
261+
type: NotificationChannelType.EMAIL,
262+
config: {
263+
smtpHost: 'smtp.gmail.com',
264+
smtpPort: 587,
265+
smtpEmail: '[email protected]',
266+
smtpUsername: '[email protected]',
267+
smtpPassword: 'abcd1234',
269268
},
270-
],
271-
};
269+
},
270+
],
272271
};
273272

274273
const app = express();
275274
app.use(bodyParser.json());
276-
app.use(notifications(getDeliveryServiceProperties));
275+
app.use(notifications(deliveryServiceProperties));
277276

278277
const token = await createAuthToken();
279278

@@ -330,7 +329,7 @@ describe('Notifications', () => {
330329
it('Returns 400 as Email notification channel is not supported in delivery service', async () => {
331330
const app = express();
332331
app.use(bodyParser.json());
333-
app.use(notifications(getDeliveryServiceProperties));
332+
app.use(notifications(deliveryServiceProperties));
334333

335334
const token = await createAuthToken();
336335

@@ -391,7 +390,7 @@ describe('Notifications', () => {
391390
it('Returns 200 and false as global notification is not enabled', async () => {
392391
const app = express();
393392
app.use(bodyParser.json());
394-
app.use(notifications(getDeliveryServiceProperties));
393+
app.use(notifications(deliveryServiceProperties));
395394

396395
const token = await createAuthToken();
397396

@@ -442,7 +441,7 @@ describe('Notifications', () => {
442441
it('Enable global notifications', async () => {
443442
const app = express();
444443
app.use(bodyParser.json());
445-
app.use(notifications(getDeliveryServiceProperties));
444+
app.use(notifications(deliveryServiceProperties));
446445

447446
const token = await createAuthToken();
448447

@@ -484,7 +483,7 @@ describe('Notifications', () => {
484483
it('Disable global notifications', async () => {
485484
const app = express();
486485
app.use(bodyParser.json());
487-
app.use(notifications(getDeliveryServiceProperties));
486+
app.use(notifications(deliveryServiceProperties));
488487

489488
const token = await createAuthToken();
490489

@@ -526,7 +525,7 @@ describe('Notifications', () => {
526525
it('Returns 400 if req.body is invalid', async () => {
527526
const app = express();
528527
app.use(bodyParser.json());
529-
app.use(notifications(getDeliveryServiceProperties));
528+
app.use(notifications(deliveryServiceProperties));
530529

531530
const token = await createAuthToken();
532531

packages/backend/src/notifications.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ import {
1212
import { IDatabase } from './persistance/getDatabase';
1313

1414
// Exporting a function that returns an Express router
15-
export default (
16-
getDeliveryServiceProperties: () => DeliveryServiceProperties,
17-
) => {
15+
export default (deliveryServiceProperties: DeliveryServiceProperties) => {
1816
const router = express.Router();
1917

2018
// Applying CORS middleware to allow cross-origin requests
@@ -104,7 +102,7 @@ export default (
104102
notificationChannelType,
105103
recipientValue,
106104
account,
107-
getDeliveryServiceProperties().notificationChannel,
105+
deliveryServiceProperties.notificationChannel,
108106
req.app.locals.db as IDatabase,
109107
);
110108

0 commit comments

Comments
 (0)