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

feat: add ip pool override #3646

Merged
merged 2 commits into from
Jun 22, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ export class SendMessageEmail extends SendMessageBase {
id: message._id,
replyTo: replyToAddress,
},
command.overrides?.email || {}
overrides || {}
);

if (command.overrides?.email?.replyTo) {
Expand Down Expand Up @@ -468,6 +468,7 @@ export const createMailData = (options: IEmailOptions, overrides: Record<string,
text: overrides?.text,
cc: overrides?.cc || [],
bcc: overrides?.bcc || [],
ipPoolName: overrides?.ipPoolName,
};
};

Expand Down
1 change: 1 addition & 0 deletions libs/shared/src/types/events/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export interface IEmailOptions {
bcc?: string[];
payloadDetails?: any;
notificationDetails?: any;
ipPoolName?: string;
}

export interface ITriggerPayload {
Expand Down
1 change: 1 addition & 0 deletions packages/stateless/src/lib/provider/provider.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export interface IEmailOptions {
bcc?: string[];
payloadDetails?: any;
notificationDetails?: any;
ipPoolName?: string;
}

export interface ISmsOptions {
Expand Down
36 changes: 35 additions & 1 deletion providers/sendgrid/src/lib/sendgrid.provider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const mockNovuMessage = {
attachments: [
{ mime: 'text/plain', file: Buffer.from('dGVzdA=='), name: 'test.txt' },
],
id: 'message_id',
};

test('should trigger sendgrid correctly', async () => {
Expand Down Expand Up @@ -47,7 +48,7 @@ test('should trigger sendgrid correctly', async () => {
},
],
customArgs: {
id: undefined,
id: 'message_id',
},
});
});
Expand All @@ -65,3 +66,36 @@ test('should check provider integration correctly', async () => {
expect(spy).toHaveBeenCalled();
expect(response.success).toBe(true);
});

test('should get ip pool name from credentials', async () => {
const provider = new SendgridEmailProvider({
...mockConfig,
...{ ipPoolName: 'config_ip' },
});
const sendMock = jest.fn().mockResolvedValue([{ statusCode: 202 }]);
jest.spyOn(MailService.prototype, 'send').mockImplementation(sendMock);

await provider.sendMessage({
...mockNovuMessage,
});
expect(sendMock).toHaveBeenCalledWith(
expect.objectContaining({ ipPoolName: 'config_ip' })
);
});

test('should override credentials with mail data', async () => {
const provider = new SendgridEmailProvider({
...mockConfig,
...{ ipPoolName: 'config_ip' },
});
const sendMock = jest.fn().mockResolvedValue([{ statusCode: 202 }]);
jest.spyOn(MailService.prototype, 'send').mockImplementation(sendMock);

await provider.sendMessage({
...mockNovuMessage,
...{ ipPoolName: 'ip_from_mail_data' },
});
expect(sendMock).toHaveBeenCalledWith(
expect.objectContaining({ ipPoolName: 'ip_from_mail_data' })
);
});
2 changes: 1 addition & 1 deletion providers/sendgrid/src/lib/sendgrid.provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export class SendgridEmailProvider implements IEmailProvider {
email: options.from || this.config.from,
name: this.config.senderName,
},
ipPoolName: this.config.ipPoolName,
ipPoolName: options.ipPoolName || this.config.ipPoolName,
to: options.to.map((email) => ({ email })),
cc: options.cc?.map((ccItem) => ({ email: ccItem })),
bcc: options.bcc?.map((ccItem) => ({ email: ccItem })),
Expand Down
Loading