From 2325ac7a2dbb2cc7deb05757391e4901745c592d Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Thu, 25 Nov 2021 04:53:54 +0300 Subject: [PATCH] Create tv.yandex.ru.test.js --- sites/tv.yandex.ru/tv.yandex.ru.test.js | 61 +++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 sites/tv.yandex.ru/tv.yandex.ru.test.js diff --git a/sites/tv.yandex.ru/tv.yandex.ru.test.js b/sites/tv.yandex.ru/tv.yandex.ru.test.js new file mode 100644 index 00000000..37aceb40 --- /dev/null +++ b/sites/tv.yandex.ru/tv.yandex.ru.test.js @@ -0,0 +1,61 @@ +// npx epg-grabber --config=sites/tv.yandex.ru/tv.yandex.ru.config.js --channels=sites/tv.yandex.ru/tv.yandex.ru_kz.channels.xml --output=.gh-pages/guides/kz/tv.yandex.ru.epg.xml --days=2 + +const { parser, url, request, logo } = require('./tv.yandex.ru.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('2021-11-25', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: '162#31-kanal-429', + xmltv_id: '31Kanal.kz' +} +const content = ` ` + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://tv.yandex.ru/162/channel/31-kanal-429?date=2021-11-25' + ) +}) + +it('can generate valid request headers', () => { + expect(request.headers).toMatchObject({ + Cookie: + 'yandexuid=8747786251615498142; Expires=Tue, 11 Mar 2031 21:29:02 GMT; Domain=yandex.ru; Path=/' + }) +}) + +it('can generate valid logo url', () => { + expect(logo({ content })).toBe( + 'https://avatars.mds.yandex.net/get-tv-channel-logos/30303/2a00000170e2a3ef22bf7cfa4ff11e8405de/170x100' + ) +}) + +it('can parse response', () => { + const result = parser({ content }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2021-11-24T23:00:00.000Z', + stop: '2021-11-24T23:58:00.000Z', + title: `Ризамын (каз.).`, + category: 'досуг', + description: 'kLX6FVKAIiDCGBFE' + } + ]) +}) + +it('can handle empty guide', () => { + const result = parser({ + date, + channel, + content: `` + }) + expect(result).toMatchObject([]) +})