-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UBERF-9577: Fix using default from address in emails (#8163)
Signed-off-by: Artem Savchenko <[email protected]>
- Loading branch information
1 parent
14a6a3a
commit 427ef59
Showing
4 changed files
with
98 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,15 @@ jest.mock('../mail', () => ({ | |
sendMessage: jest.fn() | ||
})) | ||
})) | ||
jest.mock('../config', () => ({})) | ||
jest.mock('../config', () => ({ | ||
source: '[email protected]' | ||
})) | ||
|
||
describe('handleSendMail', () => { | ||
let req: Request | ||
let res: Response | ||
let sendMailMock: jest.Mock | ||
let mailClient: MailClient | ||
|
||
beforeEach(() => { | ||
// eslint-disable-next-line @typescript-eslint/consistent-type-assertions | ||
|
@@ -44,7 +47,8 @@ describe('handleSendMail', () => { | |
send: jest.fn() | ||
} as unknown as Response | ||
|
||
sendMailMock = (new MailClient().sendMessage as jest.Mock).mockResolvedValue({}) | ||
mailClient = new MailClient() | ||
sendMailMock = (mailClient.sendMessage as jest.Mock).mockResolvedValue({}) | ||
}) | ||
|
||
it('should return 400 if text is missing', async () => { | ||
|
@@ -84,4 +88,45 @@ describe('handleSendMail', () => { | |
|
||
expect(res.send).toHaveBeenCalled() // Check that a response is still sent | ||
}) | ||
|
||
it('should use source from config if from is not provided', async () => { | ||
await handleSendMail(mailClient, req, res) | ||
|
||
expect(sendMailMock).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
from: '[email protected]', // Verify that the default source from config is used | ||
to: '[email protected]', | ||
subject: 'Test Subject', | ||
text: 'Hello, world!' | ||
}) | ||
) | ||
}) | ||
|
||
it('should use from if it is provided', async () => { | ||
req.body.from = '[email protected]' | ||
await handleSendMail(mailClient, req, res) | ||
|
||
expect(sendMailMock).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
from: '[email protected]', // Verify that the from is used | ||
to: '[email protected]', | ||
subject: 'Test Subject', | ||
text: 'Hello, world!' | ||
}) | ||
) | ||
}) | ||
|
||
it('should send to multiple addresses', async () => { | ||
req.body.to = ['[email protected]', '[email protected]'] | ||
await handleSendMail(mailClient, req, res) | ||
|
||
expect(sendMailMock).toHaveBeenCalledWith( | ||
expect.objectContaining({ | ||
from: '[email protected]', | ||
to: ['[email protected]', '[email protected]'], // Verify that multiple addresses are passed | ||
subject: 'Test Subject', | ||
text: 'Hello, world!' | ||
}) | ||
) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters