diff --git a/sites/tvgid.ua/tvgid.ua.test.js b/sites/tvgid.ua/tvgid.ua.test.js new file mode 100644 index 00000000..8a68ab72 --- /dev/null +++ b/sites/tvgid.ua/tvgid.ua.test.js @@ -0,0 +1,56 @@ +// npx epg-grabber --config=sites/tvgid.ua/tvgid.ua.config.js --channels=sites/tvgid.ua/tvgid.ua_ua.channels.xml --output=.gh-pages/guides/ua/tvgid.ua.epg.xml --days=2 + +const { parser, url } = require('./tvgid.ua.config.js') +const iconv = require('iconv-lite') +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-24', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '1plus1', + xmltv_id: '1Plus1.ua' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe('https://tvgid.ua/channels/1plus1/24112021/tmall/') +}) + +it('can parse response', () => { + const content = `

Телепрограма 1+1 на 24.11.2021

1+1 Обговорити (917)
06:30 "Сніданок з 1+1" 
00:35Х/ф "Біля моря"
03:00 "#Гуднайт_клаб" 
` + const buffer = iconv.encode(Buffer.from(content), 'win1251') + const result = parser({ buffer, date }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2021-11-24T04:30:00.000Z', + stop: '2021-11-24T22:35:00.000Z', + title: `"Сніданок з 1+1"` + }, + { + start: '2021-11-24T22:35:00.000Z', + stop: '2021-11-25T01:00:00.000Z', + title: `Х/ф "Біля моря"` + }, + { + start: '2021-11-25T01:00:00.000Z', + stop: '2021-11-25T02:00:00.000Z', + title: `"#Гуднайт_клаб"` + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `` + }) + expect(result).toMatchObject([]) +})