From 12b051e1f9fdcd359dc82424b7c95f55364d719d Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 29 Aug 2022 03:41:02 +0300 Subject: [PATCH] Create sjonvarp.is.test.js --- sites/sjonvarp.is/sjonvarp.is.test.js | 50 +++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 sites/sjonvarp.is/sjonvarp.is.test.js diff --git a/sites/sjonvarp.is/sjonvarp.is.test.js b/sites/sjonvarp.is/sjonvarp.is.test.js new file mode 100644 index 00000000..3a655e70 --- /dev/null +++ b/sites/sjonvarp.is/sjonvarp.is.test.js @@ -0,0 +1,50 @@ +// npx epg-grabber --config=sites/sjonvarp.is/sjonvarp.is.config.js --channels=sites/sjonvarp.is/sjonvarp.is_is.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./sjonvarp.is.config.js') +const fs = require('fs') +const path = require('path') +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-08-28', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'RUV', + xmltv_id: 'RUV.is' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'http://www.sjonvarp.is/index.php?Tm=%3F&p=idag&c=RUV&y=2022&m=08&d=28' + ) +}) + +it('can parse response', () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html')) + const results = parser({ content, date }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(results[0]).toMatchObject({ + start: '2022-08-28T07:15:00.000Z', + stop: '2022-08-28T07:16:00.000Z', + title: 'KrakkaRÚV' + }) + + expect(results[1]).toMatchObject({ + start: '2022-08-28T07:16:00.000Z', + stop: '2022-08-28T07:21:00.000Z', + title: 'Tölukubbar', + description: 'Lærið um tölustafina með Tölukubbunum! e.' + }) +}) + +it('can handle empty guide', () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html')) + const result = parser({ content, date }) + expect(result).toMatchObject([]) +})