Update tvguide.com.test.js

This commit is contained in:
Aleksandr Statciuk 2022-10-30 18:38:56 +03:00
parent 5937d8dc46
commit 344b4e0a66

View file

@ -1,47 +1,74 @@
// npx epg-grabber --config=sites/tvguide.com/tvguide.com.config.js --channels=sites/tvguide.com/tvguide.com_us.channels.xml --output=guide.xml --days=2
const { parser, url } = require('./tvguide.com.config.js')
const fs = require('fs')
const path = require('path')
const axios = require('axios')
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-10-04', 'YYYY-MM-DD').startOf('d')
jest.mock('axios')
const date = dayjs.utc('2022-10-30', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '9100001138#9233011874',
xmltv_id: 'ABCEast.us'
site_id: '9100001138#9200018514',
xmltv_id: 'CBSEast.us'
}
it('can generate valid url', () => {
expect(url({ date, channel })).toBe(
'https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1664841600&duration=1439&channelSourceIds=9233011874'
'https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1667088000&duration=1440&channelSourceIds=9200018514'
)
})
it('can parse response', () => {
const content = `{"data":{"duration":"1439","providerId":"9100001138","startTime":"1664841600","items":[{"channel":{"fullName":"ABC","name":"ABC","number":null,"sourceId":9233011874,"legacySourceId":5942,"networkName":"ABC","networkId":2,"logo":"/provider/1/4/1-4124037679.png"},"programSchedules":[{"airingAttrib":533524,"catId":5,"startTime":1664841600,"endTime":1664848800,"programId":6033556709,"title":"Bachelor in Paradise","rating":"TV-14","programDetails":"https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/programdetails/6033556709/web"}]}]}}`
it('can parse response', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
const result = parser({ date, channel, content }).map(p => {
axios.get.mockImplementation(url => {
if (
url ===
'https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/programdetails/6060613824/web'
) {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program.json')))
})
} else {
return Promise.resolve({ data: '' })
}
})
let results = await parser({ content, channel, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2022-10-04T00:00:00.000Z',
stop: '2022-10-04T02:00:00.000Z',
title: 'Bachelor in Paradise'
expect(results[5]).toMatchObject({
start: '2022-10-30T13:00:00.000Z',
stop: '2022-10-30T14:30:00.000Z',
title: 'CBS Sunday Morning',
sub_title: '10-30-2022',
description:
'The Backseat Lovers perform on the "Saturday Sessions"; and Daisy Ryan guests on "The Dish." Also: comedian Fortune Feimster.',
categories: ['Talk & Interview', 'Other'],
season: 40,
episode: 248,
rating: {
system: 'MPA',
value: 'TV-PG'
}
])
})
})
it('can handle empty guide', () => {
const result = parser({
it('can handle empty guide', async () => {
const results = await parser({
date,
channel,
content: `{"data":{"duration":"1439","providerId":"9100001138","startTime":"1664841600","items":[]},"links":{"self":{"href":"https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1664841600&duration=1439&channelSourceIds=923301187"},"prev":{"href":null},"next":{"href":"https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1664841600&duration=1439&channelSourceIds=923301187&offset=1664843039&limit=1664841600"}},"meta":{"componentName":null,"componentDisplayName":null,"componentType":null}}`
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.json'))
})
expect(result).toMatchObject([])
expect(results).toMatchObject([])
})