From 4af1a455d49a03a5b1323778358309b0bee544d0 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 12 Jan 2023 12:07:00 +0300 Subject: [PATCH] Create tvprofil.com.test.js --- sites/tvprofil.com/tvprofil.com.test.js | 49 +++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 sites/tvprofil.com/tvprofil.com.test.js diff --git a/sites/tvprofil.com/tvprofil.com.test.js b/sites/tvprofil.com/tvprofil.com.test.js new file mode 100644 index 00000000..1796b7eb --- /dev/null +++ b/sites/tvprofil.com/tvprofil.com.test.js @@ -0,0 +1,49 @@ +// npx epg-grabber --config=sites/tvprofil.com/tvprofil.com.config.js --channels=sites/tvprofil.com/tvprofil.com.channels.xml --output=guide.xml --days=2 + +const { parser, url, request } = require('./tvprofil.com.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('2023-01-12', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'bg/tv-programa#24kitchen-bg', + xmltv_id: '24KitchenBulgaria.bg' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + `https://tvprofil.com/bg/tv-programa/program/?datum=2023-01-12&kanal=24kitchen-bg&callback=cb&b55=747917` + ) +}) + +it('can generate valid request headers', () => { + expect(request.headers).toMatchObject({ + 'x-requested-with': 'XMLHttpRequest' + }) +}) + +it('can parse response', () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.txt'), 'utf8') + const results = parser({ content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(results[0]).toMatchObject({ + title: 'Мексиканска кухня с Пати 10, еп. 9', + start: '2023-01-12T04:00:00.000Z', + stop: '2023-01-12T04:30:00.000Z' + }) +}) + +it('can handle empty guide', () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.txt'), 'utf8') + + expect(parser({ content })).toMatchObject([]) +})