Fix some external requests not being mocked

This commit is contained in:
Hongbo Wu
2023-03-06 16:24:25 +08:00
parent 39b79f5cd2
commit 42dc3f7330
4 changed files with 10 additions and 5 deletions

View File

@ -384,7 +384,7 @@ const getJSONLdLinkMetadata = async (
return result
} catch (error) {
logger.warning(`Unable to get JSONLD link of the article`, error)
logger.warning(`Unable to get JSONLD link of the article`, { error })
return result
}
}

View File

@ -11,19 +11,23 @@ import { User } from '../../src/entity/user'
describe('saveEmail', () => {
const fakeContent = 'fake content'
let user: User
let scope: nock.Scope
before(async () => {
// create test user
user = await createTestUser('fakeUser')
scope = nock('https://blog.omnivore.app')
.get('/fake-url')
.reply(200)
.persist()
})
after(async () => {
await deleteTestUser(user.id)
scope.persist(false)
})
it('doesnt fail if saved twice', async () => {
nock('https://blog.omnivore.app').get('/fake-url').reply(200)
const url = 'https://blog.omnivore.app/fake-url'
const title = 'fake title'
const author = 'fake author'

View File

@ -90,6 +90,7 @@ describe('saveNewsletterEmail', () => {
it('adds a Newsletter label to that page', async () => {
nock('https://blog.omnivore.app').get('/new-fake-url').reply(200)
nock('https://blog.omnivore.app').head('/new-fake-url').reply(200)
const url = 'https://blog.omnivore.app/new-fake-url'
const newLabel = {
name: 'Newsletter',

View File

@ -22,9 +22,9 @@ const load = (path: string): string => {
}
describe('parseMetadata', () => {
it('gets author, title, image, description', async () => {
it('gets author, title, image, description', () => {
const html = load('./test/utils/data/substack-post.html')
const metadata = await parsePageMetadata(html)
const metadata = parsePageMetadata(html)
expect(metadata?.author).to.deep.equal('Omnivore')
expect(metadata?.title).to.deep.equal('Code Block Syntax Highlighting')
expect(metadata?.previewImage).to.deep.equal(