Add test for saving received email

This commit is contained in:
Hongbo Wu 2023-01-19 10:44:08 +08:00
parent 318a6557a5
commit 83c62c65a3
6 changed files with 28 additions and 6 deletions

View file

@ -94,7 +94,6 @@ export const markEmailAsItemResolver = authorized<
from: recentEmail.from,
email: recentEmail.to,
title: recentEmail.subject,
text: recentEmail.text,
content: recentEmail.html,
url: generateUniqueUrl(),
author: parseEmailAddress(recentEmail.from).name,

View file

@ -41,8 +41,7 @@ function isEmailMessage(data: any): data is EmailMessage {
'to' in data &&
'subject' in data &&
'html' in data &&
'text' in data &&
'receivedEmailId' in data
'text' in data
)
}

View file

@ -23,7 +23,6 @@ export interface NewsletterMessage {
author: string
unsubMailTo?: string
unsubHttpUrl?: string
text: string
receivedEmailId: string
}

View file

@ -13,6 +13,7 @@ import * as sendNotification from '../../src/utils/sendNotification'
import * as sendEmail from '../../src/utils/sendEmail'
import { getRepository } from '../../src/entity/utils'
import { ReceivedEmail } from '../../src/entity/received_email'
import * as jwt from 'jsonwebtoken'
describe('Emails Router', () => {
const newsletterEmail = 'fakeUser@omnivore.app'
@ -122,4 +123,30 @@ describe('Emails Router', () => {
})
})
})
describe('create', () => {
const html = '<html>test html</html>'
const text = 'test text'
const from = 'fake from'
const subject = 'fake subject'
const authToken = jwt.sign(newsletterEmail, process.env.JWT_SECRET || '')
it('saves the email in the database', async () => {
const data = {
html,
text,
from,
to: newsletterEmail,
subject,
}
const res = await request
.post('/svc/pubsub/emails/save')
.set('Authorization', `${authToken}`)
.send(data)
.expect(200)
console.log(res.body)
expect(res.body.id).not.to.be.undefined
})
})
})

View file

@ -56,7 +56,6 @@ describe('saveNewsletterEmail', () => {
await saveNewsletterEmail(
{
from,
text,
email: newsletterEmail.address,
content: `<html><body>${fakeContent}</body></html>`,
url,
@ -102,7 +101,6 @@ describe('saveNewsletterEmail', () => {
title,
author,
from,
text,
receivedEmailId: receivedEmail.id,
},
newsletterEmail,