Skip to content

Commit

Permalink
Update user.test.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
aelassas committed Dec 14, 2024
1 parent 81a47c2 commit 20d57fe
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions api/__tests__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

0 comments on commit 20d57fe

Please sign in to comment.