const { expect } = require('chai')
const parseUsingDOM = require('../../lib/services/dom-parser')
const MockLogger = require('../../mocks/logger.mock')
describe(parseUsingDOM, () => {
let logger
beforeEach(() => {
logger = new MockLogger()
})
describe('results', () => {
it('should return page title', () => {
const html = `
`
const { location } = parseUsingDOM(html, { logger })
expect(location).to.equal('')
})
})
})
describe('logging', () => {
it('should log parsing', (callback) => {
logger.on('test:log', () => {
callback()
})
parseUsingDOM('', { logger })
})
it('should log with message', (callback) => {
logger.on('test:log', ({ message }) => {
expect(message).to.equal('Using fallback DOM parser')
callback()
})
parseUsingDOM('', { logger })
})
it('should log with log level', (callback) => {
logger.on('test:log', ({ level }) => {
expect(level).to.equal('info')
callback()
})
parseUsingDOM('', { logger })
})
it('should log with service description', (callback) => {
logger.on('test:log', ({ service }) => {
expect(service).to.equal('parser')
callback()
})
parseUsingDOM('', { logger })
})
})
describe('null results', () => {
it('should return null if no title is present in page', () => {
const html = `
`
const eventData = parseUsingDOM(html, { logger })
expect(eventData).to.be.null
})
it('should return null if title was blacklisted', () => {
const html = `
Content Not Found
`
const eventData = parseUsingDOM(html, { logger })
expect(eventData).to.be.null
})
it('should NOT return start time without title', () => {
const html = `
`
const eventData = parseUsingDOM(html, { logger })
expect(eventData).to.be.null
})
})
})