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

99 lines
3.7 KiB
JavaScript
Raw Normal View History

2023-01-05 15:28:24 +03:00
// node ./scripts/commands/parse-channels.js --config=./sites/directv.com/directv.com.config.js --output=./sites/directv.com/directv.com.channels.xml --set=zip:10001
// npx epg-grabber --config=sites/directv.com/directv.com.config.js --channels=sites/directv.com/directv.com.channels.xml --output=guide.xml --days=2
2021-10-31 05:54:45 +03:00
2022-02-01 02:37:15 +03:00
const { parser, url } = require('./directv.com.config.js')
2023-01-15 12:20:49 +00:00
const fs = require('fs')
const path = require('path')
2022-01-19 00:02:44 +03:00
const axios = require('axios')
2021-10-31 05:54:45 +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-01-19 00:02:44 +03:00
jest.mock('axios')
2023-01-15 12:20:49 +00:00
const date = dayjs.utc('2023-01-15', 'YYYY-MM-DD').startOf('d')
2021-10-31 05:54:45 +03:00
const channel = {
2023-01-15 12:20:49 +00:00
site_id: '249#249',
xmltv_id: 'ComedyCentralEast.us'
2021-10-31 05:54:45 +03:00
}
it('can generate valid url', () => {
const result = url({ date, channel })
expect(result).toBe(
2023-01-15 12:20:49 +00:00
'https://www.directv.com/json/channelschedule?channels=249&startTime=2023-01-15T00:00:00Z&hours=24&chId=249'
2021-10-31 05:54:45 +03:00
)
})
2022-01-19 00:02:44 +03:00
it('can parse response', done => {
2023-01-15 12:20:49 +00:00
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
2022-01-19 00:02:44 +03:00
axios.get.mockImplementation(url => {
2023-01-15 12:20:49 +00:00
if (url === 'https://www.directv.com/json/program/flip/MV001173520000') {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program1.json')))
})
} else if (url === 'https://www.directv.com/json/program/flip/EP002298270445') {
2022-01-19 00:02:44 +03:00
return Promise.resolve({
2023-01-15 12:20:49 +00:00
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program2.json')))
2022-01-19 00:02:44 +03:00
})
} else {
return Promise.resolve({ data: '' })
2021-10-31 05:54:45 +03:00
}
2022-01-19 00:02:44 +03:00
})
2023-01-15 12:20:49 +00:00
parser({ content, channel })
2022-01-19 00:02:44 +03:00
.then(result => {
result = result.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
2023-01-15 12:20:49 +00:00
start: '2023-01-14T23:00:00.000Z',
stop: '2023-01-15T01:00:00.000Z',
title: 'Men in Black II',
2022-01-19 00:02:44 +03:00
description:
2023-01-15 12:20:49 +00:00
'Kay (Tommy Lee Jones) and Jay (Will Smith) reunite to provide our best line of defense against a seductress who levels the toughest challenge yet to the MIBs mission statement: protecting the earth from the scum of the universe. While investigating a routine crime, Jay uncovers a plot masterminded by Serleena (Boyle), a Kylothian monster who disguises herself as a lingerie model. When Serleena takes the MIB building hostage, there is only one person Jay can turn to -- his former MIB partner.',
2023-01-15 14:01:43 +00:00
date: '2002',
2023-01-15 12:20:49 +00:00
icon: 'https://www.directv.com/db_photos/movies/AllPhotosAPGI/29160/29160_aa.jpg',
category: ['Comedy', 'Movies Anywhere', 'Action/Adventure', 'Science Fiction'],
2023-01-15 12:20:49 +00:00
rating: {
system: 'MPA',
value: 'TV14'
}
},
2022-01-19 00:02:44 +03:00
{
2023-01-15 12:20:49 +00:00
start: '2023-01-15T06:00:00.000Z',
stop: '2023-01-15T06:30:00.000Z',
title: 'South Park',
sub_title: 'Goth Kids 3: Dawn of the Posers',
description: 'The goth kids are sent to a camp for troubled children.',
icon: 'https://www.directv.com/db_photos/showcards/v5/AllPhotos/184338/p184338_b_v5_aa.jpg',
category: ['Series', 'Animation', 'Comedy'],
season: 17,
2023-01-15 12:20:49 +00:00
episode: 4,
rating: {
system: 'MPA',
value: 'TVMA'
}
2022-01-19 00:02:44 +03:00
}
])
done()
})
.catch(done)
2021-10-31 05:54:45 +03:00
})
2022-01-19 00:02:44 +03:00
it('can handle empty guide', done => {
2023-01-15 12:20:49 +00:00
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no-content.json'))
parser({ content, channel })
2022-01-19 00:02:44 +03:00
.then(result => {
expect(result).toMatchObject([])
done()
})
.catch(done)
2021-10-31 05:54:45 +03:00
})