Merge pull request #624 from omnivore-app/morning-brew-newsletters
Support morning brew newsletter and add tests
This commit is contained in:
@ -17,6 +17,7 @@ import { SubstackHandler } from './substack-handler'
|
||||
import { AxiosHandler } from './axios-handler'
|
||||
import { BloombergHandler } from './bloomberg-handler'
|
||||
import { GolangHandler } from './golang-handler'
|
||||
import { MorningBrewHandler } from './morning-brew-handler'
|
||||
|
||||
const NON_NEWSLETTER_EMAIL_TOPIC = 'nonNewsletterEmailReceived'
|
||||
const pubsub = new PubSub()
|
||||
@ -26,6 +27,7 @@ const NEWSLETTER_HANDLERS = [
|
||||
new AxiosHandler(),
|
||||
new BloombergHandler(),
|
||||
new GolangHandler(),
|
||||
new MorningBrewHandler(),
|
||||
]
|
||||
|
||||
export const getNewsletterHandler = (
|
||||
|
||||
10
packages/inbound-email-handler/src/morning-brew-handler.ts
Normal file
10
packages/inbound-email-handler/src/morning-brew-handler.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import { NewsletterHandler } from './newsletter'
|
||||
|
||||
export class MorningBrewHandler extends NewsletterHandler {
|
||||
constructor() {
|
||||
super()
|
||||
this.senderRegex = /Morning Brew <crew@morningbrew.com>/
|
||||
this.urlRegex = /<a.* href=["']([^"']*)["'].*>View Online<\/a>/
|
||||
this.defaultUrl = 'https://www.morningbrew.com'
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,7 @@ import { AxiosHandler } from '../src/axios-handler'
|
||||
import { BloombergHandler } from '../src/bloomberg-handler'
|
||||
import { GolangHandler } from '../src/golang-handler'
|
||||
import { getNewsletterHandler } from '../src'
|
||||
import { MorningBrewHandler } from '../src/morning-brew-handler'
|
||||
|
||||
describe('Confirmation email test', () => {
|
||||
describe('#isConfirmationEmail()', () => {
|
||||
@ -77,6 +78,15 @@ describe('Newsletter email test', () => {
|
||||
GolangHandler
|
||||
)
|
||||
})
|
||||
|
||||
it('should return MorningBrewHandler when email is from Morning Brew', () => {
|
||||
const from = 'Morning Brew <crew@morningbrew.com>'
|
||||
const unSubRawUrl = '<https://morningbrew.com/unsubscribe>'
|
||||
|
||||
expect(getNewsletterHandler('', from, unSubRawUrl)).to.be.instanceof(
|
||||
MorningBrewHandler
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('#getNewsletterUrl()', () => {
|
||||
@ -114,6 +124,17 @@ describe('Newsletter email test', () => {
|
||||
|
||||
expect(new GolangHandler().parseNewsletterUrl('', html)).to.equal(url)
|
||||
})
|
||||
|
||||
it('returns url when email is from Morning Brew', () => {
|
||||
const url = 'https://www.morningbrew.com/daily/issues/first'
|
||||
const html = `
|
||||
<a style="color: #000000; text-decoration: none;" target="_blank" rel="noopener" href="${url}">View Online</a>
|
||||
`
|
||||
|
||||
expect(new MorningBrewHandler().parseNewsletterUrl('', html)).to.equal(
|
||||
url
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
describe('get author from email address', () => {
|
||||
|
||||
Reference in New Issue
Block a user