-
-
Notifications
You must be signed in to change notification settings - Fork 212
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1860,20 +1860,40 @@ describe('POST /api/verify-recaptcha/:token/:ip', () => { | |
|
||
describe('POST /api/send-email', () => { | ||
it('should send an email', async () => { | ||
// test failure (recaptcha not valid) | ||
const ip = '134.236.60.166' | ||
const recaptchaToken = 'XXXXXX' | ||
const payload = { | ||
from: '[email protected]', | ||
// test success (contact form) | ||
const payload: bookcarsTypes.SendEmailPayload = { | ||
from: '[email protected]', | ||
to: '[email protected]', | ||
subject: 'test', | ||
message: 'test message', | ||
recaptchaToken, | ||
ip, | ||
isContactForm: true, | ||
} | ||
const res = await request(app) | ||
let res = await request(app) | ||
.post('/api/send-email') | ||
.set('Origin', env.FRONTEND_HOST) | ||
.send(payload) | ||
expect(res.statusCode).toBe(200) | ||
|
||
// test success (newsletter form) | ||
payload.isContactForm = false | ||
payload.message = '' | ||
res = await request(app) | ||
.post('/api/send-email') | ||
.set('Origin', env.FRONTEND_HOST) | ||
.send(payload) | ||
expect(res.statusCode).toBe(200) | ||
|
||
// test failure (no Origin) | ||
res = await request(app) | ||
.post('/api/send-email') | ||
.send(payload) | ||
expect(res.statusCode).toBe(400) | ||
|
||
// test failure (Not allowed by CORS) | ||
res = await request(app) | ||
.post('/api/send-email') | ||
.set('Origin', 'https://unknown.com') | ||
.send(payload) | ||
expect(res.statusCode).toBe(500) | ||
}) | ||
}) |