Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

741 otp #747

Merged
merged 20 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 50 additions & 35 deletions packages/backend/src/config/getDeliveryServiceProperties.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,12 @@ describe('ReadDeliveryServiceProperties', () => {
messageTTL: 12345,
sizeLimit: 456,
notificationChannel: [],
smtpHost: 'smtp.host',
smtpPort: 587,
smtpEmail: '[email protected]',
smtpUsername: '[email protected]',
smtpPassword: 'dm312345',
});

expect(config).toStrictEqual({
messageTTL: 12345,
sizeLimit: 456,
notificationChannel: [],
smtpHost: 'smtp.host',
smtpPort: 587,
smtpEmail: '[email protected]',
smtpUsername: '[email protected]',
smtpPassword: 'dm312345',
});
});

Expand All @@ -46,6 +36,23 @@ describe('ReadDeliveryServiceProperties', () => {
stringify({
messageTTL: 12345,
sizeLimit: 456,
notificationChannel: [],
}),
{ encoding: 'utf-8' },
);
const config = getDeliveryServiceProperties(path);

expect(config).toStrictEqual({
messageTTL: 12345,
sizeLimit: 456,
notificationChannel: [],
});
});
it('Adds default properties if config.yml is not fully specified', () => {
writeFileSync(
path,
stringify({
messageTTL: 12345,
notificationChannel: [
{
type: NotificationChannelType.EMAIL,
Expand All @@ -61,19 +68,14 @@ describe('ReadDeliveryServiceProperties', () => {
},
},
],
smtpHost: 'smtp.host',
smtpPort: 587,
smtpEmail: '[email protected]',
smtpUsername: '[email protected]',
smtpPassword: 'dm312345',
}),
{ encoding: 'utf-8' },
);
const config = getDeliveryServiceProperties(path);

expect(config).toStrictEqual({
messageTTL: 12345,
sizeLimit: 456,
sizeLimit: 100000,
notificationChannel: [
{
type: NotificationChannelType.EMAIL,
Expand All @@ -89,37 +91,50 @@ describe('ReadDeliveryServiceProperties', () => {
},
},
],
smtpHost: 'smtp.host',
smtpPort: 587,
smtpEmail: '[email protected]',
smtpUsername: '[email protected]',
smtpPassword: 'dm312345',
});
});
it('Adds default properties if config.yml is not fully specified', () => {
it('Adds email channel from config.yml file & rest from default properties', () => {
writeFileSync(
path,
stringify({
messageTTL: 12345,
smtpHost: 'smtp.host',
smtpPort: 587,
smtpEmail: '[email protected]',
smtpUsername: '[email protected]',
smtpPassword: 'dm312345',
notificationChannel: [
{
type: NotificationChannelType.EMAIL,
config: {
host: 'mail.alice.com',
port: 465,
secure: true,
auth: {
user: 'foo',
pass: 'bar',
},
senderAddress: '[email protected]',
},
},
],
}),
{ encoding: 'utf-8' },
);
const config = getDeliveryServiceProperties(path);

expect(config).toStrictEqual({
messageTTL: 12345,
messageTTL: 0,
sizeLimit: 100000,
notificationChannel: [],
smtpHost: 'smtp.host',
smtpPort: 587,
smtpEmail: '[email protected]',
smtpUsername: '[email protected]',
smtpPassword: 'dm312345',
notificationChannel: [
{
type: NotificationChannelType.EMAIL,
config: {
host: 'mail.alice.com',
port: 465,
secure: true,
auth: {
user: 'foo',
pass: 'bar',
},
senderAddress: '[email protected]',
},
},
],
});
});
});
6 changes: 1 addition & 5 deletions packages/backend/src/config/getDeliveryServiceProperties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@ const DEFAULT_DELIVERY_SERVICE_PROPERTIES: DeliveryServiceProperties = {
//100Kb
sizeLimit: 100000,
notificationChannel: [],
smtpHost: '',
smtpPort: 0,
smtpEmail: '',
smtpUsername: '',
smtpPassword: '',
};

export function getDeliveryServiceProperties(
Expand All @@ -25,6 +20,7 @@ export function getDeliveryServiceProperties(
logInfo('Config file not found. Default Config is used');
return defaultDeliveryServiceProperties;
}

const yamlString = readFileSync(path, { encoding: 'utf-8' });

const deliveryServiceProfile = parse(yamlString);
Expand Down
5 changes: 4 additions & 1 deletion packages/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ global.logger = winston.createLogger({
app.use('/storage', Storage());
app.use('/auth', Auth());
app.use('/delivery', Delivery());
app.use('/notifications', Notifications());
app.use(
'/notifications',
Notifications(app.locals.deliveryServiceProperties),
);
app.use('/rpc', RpcProxy(new Axios({ url: process.env.RPC })));
app.use(logError);
app.use(errorHandler);
Expand Down
Loading
Loading