Files
epg/sites/andorradifusio.ad/andorradifusio.ad.test.js

50 lines
1.3 KiB
JavaScript
Raw Normal View History

2023-10-02 06:35:33 +03:00
// npm run grab -- --site=andorradifusio.ad
2021-11-25 01:28:18 +03:00
const { parser, url } = require('./andorradifusio.ad.config.js')
2023-06-07 06:42:15 +03:00
const fs = require('fs')
const path = require('path')
2021-11-25 01:28:18 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
2023-06-07 06:42:15 +03:00
const date = dayjs.utc('2023-06-07', 'YYYY-MM-DD').startOf('d')
2021-11-25 01:28:18 +03:00
const channel = {
site_id: 'atv',
xmltv_id: 'AndorraTV.ad'
}
it('can generate valid url', () => {
expect(url({ channel })).toBe('https://www.andorradifusio.ad/programacio/atv')
})
it('can parse response', () => {
2023-06-07 06:42:15 +03:00
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
const results = parser({ content, date }).map(p => {
2021-11-25 01:28:18 +03:00
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
2023-06-07 06:42:15 +03:00
expect(results[0]).toMatchObject({
start: '2023-06-07T05:00:00.000Z',
stop: '2023-06-07T06:00:00.000Z',
2023-10-02 06:35:33 +03:00
title: 'Club Piolet'
2023-06-07 06:42:15 +03:00
})
expect(results[20]).toMatchObject({
start: '2023-06-07T23:00:00.000Z',
stop: '2023-06-08T00:00:00.000Z',
2023-10-02 06:35:33 +03:00
title: 'Àrea Andorra Difusió'
2023-06-07 06:42:15 +03:00
})
2021-11-25 01:28:18 +03:00
})
it('can handle empty guide', () => {
const result = parser({
date,
2023-10-02 06:35:33 +03:00
content: '<!DOCTYPE html><html><head></head><body></body></html>'
2021-11-25 01:28:18 +03:00
})
expect(result).toMatchObject([])
})