Files
epg/sites/tvguide.com/tvguide.com.test.js

75 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-01-05 15:28:24 +03:00
// npx epg-grabber --config=sites/tvguide.com/tvguide.com.config.js --channels=sites/tvguide.com/tvguide.com.channels.xml --output=guide.xml --days=2
2022-10-04 16:26:48 +03:00
const { parser, url } = require('./tvguide.com.config.js')
2022-10-30 18:38:56 +03:00
const fs = require('fs')
const path = require('path')
const axios = require('axios')
2022-10-04 16:26:48 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
2022-10-30 18:38:56 +03:00
jest.mock('axios')
const date = dayjs.utc('2022-10-30', 'YYYY-MM-DD').startOf('d')
2022-10-04 16:26:48 +03:00
const channel = {
2022-10-30 18:38:56 +03:00
site_id: '9100001138#9200018514',
xmltv_id: 'CBSEast.us'
2022-10-04 16:26:48 +03:00
}
it('can generate valid url', () => {
expect(url({ date, channel })).toBe(
2022-10-30 18:38:56 +03:00
'https://cmg-prod.apigee.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1667088000&duration=1440&channelSourceIds=9200018514'
2022-10-04 16:26:48 +03:00
)
})
2022-10-30 18:38:56 +03:00
it('can parse response', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
2022-10-04 16:26:48 +03:00
2022-10-30 18:38:56 +03:00
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 => {
2022-10-04 16:26:48 +03:00
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
2022-10-30 18:38:56 +03:00
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'
2022-10-04 16:26:48 +03:00
}
2022-10-30 18:38:56 +03:00
})
2022-10-04 16:26:48 +03:00
})
2022-10-30 18:38:56 +03:00
it('can handle empty guide', async () => {
const results = await parser({
2022-10-04 16:26:48 +03:00
date,
channel,
2022-10-30 18:38:56 +03:00
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.json'))
2022-10-04 16:26:48 +03:00
})
2022-10-30 18:38:56 +03:00
expect(results).toMatchObject([])
2022-10-04 16:26:48 +03:00
})