const { parser, url } = require('./ontvtonight.com.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
const date = dayjs.utc('2021-11-25', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'au#1692/7two',
xmltv_id: '7two.au'
}
const content =
'
12:10 am | |
12:50 am | The Devil In The Details |
10:50 pm | |
'
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
'https://www.ontvtonight.com/au/guide/listings/channel/1692/7two.html?dt=2021-11-25'
)
})
it('can parse response', () => {
const result = parser({ content, channel, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2021-11-24T13:10:00.000Z',
stop: '2021-11-24T13:50:00.000Z',
title: 'What A Carry On'
},
{
start: '2021-11-24T13:50:00.000Z',
stop: '2021-11-25T11:50:00.000Z',
title: 'Bones',
description: 'The Devil In The Details'
},
{
start: '2021-11-25T11:50:00.000Z',
stop: '2021-11-25T12:50:00.000Z',
title: 'Inspector Morse: The Remorseful Day'
}
])
})
it('can handle empty guide', () => {
const result = parser({
date,
channel,
content: ''
})
expect(result).toMatchObject([])
})