From 6233a9c4ac2873376f4b0412a64136825d4fdaea Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 20 Jan 2022 03:34:36 +0300 Subject: [PATCH] Create tv.dir.bg.test.js --- sites/tv.dir.bg/tv.dir.bg.test.js | 55 +++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 sites/tv.dir.bg/tv.dir.bg.test.js diff --git a/sites/tv.dir.bg/tv.dir.bg.test.js b/sites/tv.dir.bg/tv.dir.bg.test.js new file mode 100644 index 00000000..bef02cba --- /dev/null +++ b/sites/tv.dir.bg/tv.dir.bg.test.js @@ -0,0 +1,55 @@ +// node ./scripts/commands/parse-channels.js --config=./sites/tv.dir.bg/tv.dir.bg.config.js --output=./sites/tv.dir.bg/tv.dir.bg_bg.channels.xml +// npx epg-grabber --config=sites/tv.dir.bg/tv.dir.bg.config.js --channels=sites/tv.dir.bg/tv.dir.bg_bg.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./tv.dir.bg.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('2022-01-20', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '12', + xmltv_id: 'BTV.bg' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe('https://tv.dir.bg/tv_channel.php?id=12&dd=20.01') +}) + +it('can parse response', () => { + const content = `
` + const result = parser({ content, date }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-01-20T04:00:00.000Z', + stop: '2022-01-20T13:00:00.000Z', + title: `„Тази сутрин” - информационно предаване с водещи Златимир Йочеви Биляна Гавазова` + }, + { + start: '2022-01-20T13:00:00.000Z', + stop: '2022-01-21T03:30:00.000Z', + title: `„Доктор Чудо” - сериал, еп.71` + }, + { + start: '2022-01-21T03:30:00.000Z', + stop: '2022-01-21T04:00:00.000Z', + title: `„Лице в лице” /п./` + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `
    ` + }) + expect(result).toMatchObject([]) +})