mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add test for saving received email
This commit is contained in:
parent
318a6557a5
commit
83c62c65a3
6 changed files with 28 additions and 6 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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
|
||||
)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@ export interface NewsletterMessage {
|
|||
author: string
|
||||
unsubMailTo?: string
|
||||
unsubHttpUrl?: string
|
||||
text: string
|
||||
receivedEmailId: string
|
||||
}
|
||||
|
||||
|
|
|
|||
0
packages/api/test/resolvers/recent_emails.test.ts
Normal file
0
packages/api/test/resolvers/recent_emails.test.ts
Normal 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
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue