Skip to content

Commit

Permalink
Merge branch 'next' into nv-2745-global-channel-subscriber-preference…
Browse files Browse the repository at this point in the history
…s-api-only
  • Loading branch information
BiswaViraj authored Oct 2, 2023
2 parents 18dcf61 + c13c527 commit dce0952
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 12 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ You can open a new issue with this [issue form](https://github.com/novuhq/novu/i

### Requirements

- Node.js version v14.19.3
- Node.js version v16.15.1
- MongoDB
- Redis. To install Redis on your O.S, please follow the below guides
- [To install Redis on Windows](https://redis.io/docs/getting-started/installation/install-redis-on-windows/)
Expand Down
95 changes: 95 additions & 0 deletions apps/api/src/app/shared/helpers/content.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,4 +335,99 @@ describe('ContentService', function () {
expect(extractVariables[0].name).to.include('lastName');
});
});

describe('extractStepVariables', () => {
it('should not fail if no filters available', () => {
const contentService = new ContentService();
const messages = [
{
template: {
type: StepTypeEnum.EMAIL,
subject: 'Test {{subscriber.firstName}}',
content: [
{
content: 'Test of {{subscriber.firstName}} {{lastName}}',
type: 'text',
},
],
},
},
] as INotificationTemplateStep[];
const variables = contentService.extractStepVariables(messages);

expect(variables.length).to.equal(0);
});

it('should not fail if filters are set as non array', () => {
const contentService = new ContentService();
const messages = [
{
template: {
type: StepTypeEnum.EMAIL,
subject: 'Test {{subscriber.firstName}}',
content: [
{
content: 'Test of {{subscriber.firstName}} {{lastName}}',
type: 'text',
},
],
},
filters: {},
},
] as INotificationTemplateStep[];
const variables = contentService.extractStepVariables(messages);

expect(variables.length).to.equal(0);
});

it('should not fail if filters are an empty array', () => {
const contentService = new ContentService();
const messages = [
{
template: {
type: StepTypeEnum.EMAIL,
subject: 'Test {{subscriber.firstName}}',
content: [
{
content: 'Test of {{subscriber.firstName}} {{lastName}}',
type: 'text',
},
],
},
filters: [],
},
] as INotificationTemplateStep[];
const variables = contentService.extractStepVariables(messages);

expect(variables.length).to.equal(0);
});

it('should not fail if filters have some wrong settings like missing children in filters', () => {
const contentService = new ContentService();
const messages = [
{
template: {
type: StepTypeEnum.EMAIL,
subject: 'Test {{subscriber.firstName}}',
content: [
{
content: 'Test of {{subscriber.firstName}} {{lastName}}',
type: 'text',
},
],
},
filters: [
{
isNegated: false,
type: 'GROUP',
value: 'AND',
},
],
},
] as INotificationTemplateStep[];
const variables = contentService.extractStepVariables(messages);

expect(variables.length).to.equal(0);
});
});
});
24 changes: 13 additions & 11 deletions apps/api/src/app/shared/helpers/content.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,19 @@ export class ContentService {

for (const message of messages) {
if (message.filters) {
const filterVariables = message.filters.flatMap((filter) =>
filter.children
.filter((item) => item.on === FilterPartTypeEnum.PAYLOAD)
.map((item: IFieldFilterPart) => {
return {
name: item.field,
type: TemplateVariableTypeEnum.STRING,
};
})
);
variables.push(...filterVariables);
const filters = Array.isArray(message.filters) ? message.filters : [];
const filteredVariables = filters.flatMap((filter) => {
const filteredChildren = filter.children?.filter((item) => item.on === FilterPartTypeEnum.PAYLOAD) || [];
const mappedChildren = filteredChildren.map((item: IFieldFilterPart) => {
return {
name: item.field,
type: TemplateVariableTypeEnum.STRING,
};
});

return mappedChildren;
});
variables.push(...filteredVariables);
}

if (message.metadata?.type === DelayTypeEnum.SCHEDULED && message.metadata.delayPath) {
Expand Down
1 change: 1 addition & 0 deletions providers/nodemailer/src/lib/nodemailer.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class NodemailerProvider implements IEmailProvider {
const tls: ConnectionOptions = this.getTlsOptions();

const smtpTransportOptions: SMTPTransport.Options = {
name: this.config.host,
host: this.config.host,
port: this.config.port,
secure: this.config.secure,
Expand Down

0 comments on commit dce0952

Please sign in to comment.