Accept null value for text in an email

This commit is contained in:
Hongbo Wu 2023-02-01 13:44:27 +08:00
parent c4905aaba8
commit ac6f5b497c
2 changed files with 18 additions and 9 deletions

View file

@ -36,13 +36,7 @@ interface EmailMessage {
}
function isEmailMessage(data: any): data is EmailMessage {
return (
'from' in data &&
'to' in data &&
'subject' in data &&
'html' in data &&
'text' in data
)
return 'from' in data && 'to' in data && 'subject' in data
}
const logger = buildLogger('app.dispatch')

View file

@ -125,6 +125,7 @@ describe('Emails Router', () => {
})
describe('create', () => {
const url = '/svc/pubsub/emails/save'
const html = '<html>test html</html>'
const text = 'test text'
const from = 'fake from'
@ -140,12 +141,26 @@ describe('Emails Router', () => {
subject,
}
const res = await request
.post('/svc/pubsub/emails/save')
.post(url)
.set('Authorization', `${authToken}`)
.send(data)
.expect(200)
expect(res.body.id).not.to.be.undefined
})
it('saves the email if body is empty', async () => {
const data = {
from,
to: newsletterEmail,
subject,
}
const res = await request
.post(url)
.set('Authorization', `${authToken}`)
.send(data)
.expect(200)
console.log(res.body)
expect(res.body.id).not.to.be.undefined
})
})