From 641f52b8a31e22d6d8c97de7c7d748290eecbb92 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Tue, 3 May 2022 16:51:34 +0300 Subject: [PATCH] Create i.mjh.nz.test.js --- sites/i.mjh.nz/i.mjh.nz.test.js | 53 +++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 sites/i.mjh.nz/i.mjh.nz.test.js diff --git a/sites/i.mjh.nz/i.mjh.nz.test.js b/sites/i.mjh.nz/i.mjh.nz.test.js new file mode 100644 index 00000000..eec79db1 --- /dev/null +++ b/sites/i.mjh.nz/i.mjh.nz.test.js @@ -0,0 +1,53 @@ +// npm run channels:parse -- --config=./sites/i.mjh.nz/i.mjh.nz.config.js --output=./sites/i.mjh.nz/i.mjh.nz_us-pluto.channels.xml --set=service:PlutoTV --set=region:us +// npm run channels:parse -- --config=./sites/i.mjh.nz/i.mjh.nz.config.js --output=./sites/i.mjh.nz/i.mjh.nz_us-stirr.channels.xml --set=service:Stirr +// npx epg-grabber --config=sites/i.mjh.nz/i.mjh.nz.config.js --channels=sites/i.mjh.nz/i.mjh.nz_us-pluto.channels.xml --output=guide.xml --days=2 +// npx epg-grabber --config=sites/i.mjh.nz/i.mjh.nz.config.js --channels=sites/i.mjh.nz/i.mjh.nz_us-stirr.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./i.mjh.nz.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-05-03', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'PlutoTV/us#51c75f7bb6f26ba1cd00002f', + xmltv_id: 'LittleStarsUniverse.us', + lang: 'en' +} + +it('can generate valid url', () => { + expect(url({ channel })).toBe( + 'https://raw.githubusercontent.com/matthuisman/i.mjh.nz/master/PlutoTV/us.xml' + ) +}) + +it('can parse response', () => { + const content = ` Little Stars Universe Barney and Friends Baby Bop forgets to say "please" and "thank you". Riff shares his dream of becoming an inventor. Children & Family Barney and Friends Baby Bop forgets to say "please" and "thank you". Riff shares his dream of becoming an inventor. Children & Family ` + const result = parser({ content, channel, date }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-05-03T10:49:22.000Z', + stop: '2022-05-03T11:21:22.000Z', + title: 'Barney and Friends', + description: + 'Baby Bop forgets to say "please" and "thank you". Riff shares his dream of becoming an inventor.', + category: ['Children', 'Family'] + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + content: `404: Not Found`, + channel, + date + }) + expect(result).toMatchObject([]) +})