-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add unit tests for nodemailer * Make adjustments to Nodemailer module to work wiht Unit Tests * Add Nodemailer env vars to CI * Add nodemailer env vars to docker compose * Add env vars in right place in CI * Remove nodemailer env vars * Add dotenv to test script * Remove dotenv import * return a promise with resolve/reject * Use objectContaining/arrayContaining to read response * Add mailhog under services
- Loading branch information
1 parent
aa9a70d
commit 7481522
Showing
4 changed files
with
51 additions
and
13 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
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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import sendNotification from '../../app/lib/notifications.server'; | ||
const { NOTIFICATIONS_EMAIL_USER } = process.env; | ||
describe('Notification server lib function test', () => { | ||
const recipient: string = '[email protected]'; | ||
const subject: string = 'Sample subject'; | ||
const text: string = 'Sample text'; | ||
|
||
test('sending email notification using sendNotification() ', async () => { | ||
const response = await sendNotification(recipient, subject, text); | ||
expect(response).toBe(`Sent notification to ${recipient}`); | ||
}); | ||
|
||
test('verifying MailHog received test email notification via SendNotification() ', async () => { | ||
const response = await fetch(`http://localhost:8025/api/v2/search?kind=to&query=${recipient}`); | ||
const responseToJSON = await response.json(); | ||
const mostRecentMessage = responseToJSON.items[0]; | ||
expect(mostRecentMessage).toEqual( | ||
expect.objectContaining({ | ||
Content: expect.objectContaining({ | ||
Headers: expect.objectContaining({ | ||
To: expect.arrayContaining([recipient]), | ||
From: expect.arrayContaining([NOTIFICATIONS_EMAIL_USER]), | ||
}), | ||
Body: expect.stringMatching(text), | ||
}), | ||
}) | ||
); | ||
}); | ||
}); |