mirror of
https://github.com/iptv-org/epg
synced 2025-12-16 18:37:01 -05:00
Update dstv.com.test.js
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
|
||||
const { parser, url } = require('./dstv.com.config.js')
|
||||
const axios = require('axios')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const dayjs = require('dayjs')
|
||||
const utc = require('dayjs/plugin/utc')
|
||||
const customParseFormat = require('dayjs/plugin/customParseFormat')
|
||||
@@ -13,68 +15,90 @@ dayjs.extend(utc)
|
||||
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-03-11', 'YYYY-MM-DD').startOf('d')
|
||||
const API_ENDPOINT = 'https://www.dstv.com/umbraco/api/TvGuide'
|
||||
|
||||
const date = dayjs.utc('2022-11-22', 'YYYY-MM-DD').startOf('d')
|
||||
const channelZA = {
|
||||
site_id: 'zaf#101',
|
||||
xmltv_id: 'MNetWest.za'
|
||||
site_id: 'zaf#201',
|
||||
xmltv_id: 'SuperSportGrandstand.za'
|
||||
}
|
||||
const channelNG = {
|
||||
site_id: 'nga#101',
|
||||
xmltv_id: 'MNetWest.za'
|
||||
site_id: 'nga#201',
|
||||
xmltv_id: 'SuperSportGrandstand.za'
|
||||
}
|
||||
|
||||
it('can generate valid url for zaf', () => {
|
||||
expect(url({ channel: channelZA, date })).toBe(
|
||||
'https://www.dstv.com/umbraco/api/TvGuide/GetProgrammes?d=2022-03-11&package=&country=zaf'
|
||||
`${API_ENDPOINT}/GetProgrammes?d=2022-11-22&country=zaf`
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate valid url for nga', () => {
|
||||
expect(url({ channel: channelNG, date })).toBe(
|
||||
'https://www.dstv.com/umbraco/api/TvGuide/GetProgrammes?d=2022-03-11&package=DStv%20Premium&country=nga'
|
||||
`${API_ENDPOINT}/GetProgrammes?d=2022-11-22&package=DStv%20Premium&country=nga`
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse response', done => {
|
||||
const content = `{"Total":4483,"Channels":[{"Number":"214","Tag":"S34","Name":"TENNIS","Programmes":[{"Id":"5c5a56e8-9959-4305-ae2f-7cc32ec39f5f","StartTime":"2022-03-11T09:00:00","EndTime":"2022-03-11T09:15:00","Title":"WTA 1000 HL '22: Indian Wells D2 M1"}]},{"Number":"101","Tag":"HDT","Name":"M-Net HD","Programmes":[{"Id":"a6ada4cd-93df-4eaf-bab4-041e2537ed23","StartTime":"2022-03-11T00:10:00","EndTime":"2022-03-11T00:50:00","Title":"Curb Your Enthusiasm"}]}]}`
|
||||
it('can parse response for ZA', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_zaf.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (
|
||||
url ===
|
||||
'https://www.dstv.com/umbraco/api/TvGuide/GetProgramme?id=a6ada4cd-93df-4eaf-bab4-041e2537ed23'
|
||||
) {
|
||||
if (url === `${API_ENDPOINT}/GetProgramme?id=8b237235-aa17-4bb8-9ea6-097e7a813336`) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(
|
||||
`{"Id":"a6ada4cd-93df-4eaf-bab4-041e2537ed23","ChannelTag":"HDT","Channel":"M-Net Domestic HD","EventID":"HDT0000109067787","StartTime":"2022-03-11T00:10:00","EndTime":"2022-03-11T00:50:00","Duration":"00:40:00","Language":"eng","Title":"Curb Your Enthusiasm","Synopsis":"'S11/E6 of 10 - Man Fights Tiny Woman'. A general entertainment channel showcasing the best international content, focusing on scripted drama, comedy and talk.","Rating":"16","MainGenres":["Series"],"SubGenres":["Sitcom","Comedy"],"Items":[{"Key":"Year","Value":"2020"},{"Key":"Source Key ID","Value":"100338770"}],"ThumbnailUri":"https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/21893_curb_your_enthusiam169.jpg"}`
|
||||
)
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program_zaf.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
parser({ content, channel: channelZA })
|
||||
.then(result => {
|
||||
result = result.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
let results = await parser({ content, channel: channelZA })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(result).toMatchObject([
|
||||
{
|
||||
start: '2022-03-11T00:10:00.000Z',
|
||||
stop: '2022-03-11T00:50:00.000Z',
|
||||
title: 'Curb Your Enthusiasm'
|
||||
// description:
|
||||
// "'S11/E6 of 10 - Man Fights Tiny Woman'. A general entertainment channel showcasing the best international content, focusing on scripted drama, comedy and talk.",
|
||||
// icon: 'https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/21893_curb_your_enthusiam169.jpg',
|
||||
// category: ['Sitcom', 'Comedy']
|
||||
}
|
||||
])
|
||||
done()
|
||||
})
|
||||
.catch(done)
|
||||
expect(results[1]).toMatchObject({
|
||||
start: '2022-11-21T23:00:00.000Z',
|
||||
stop: '2022-11-22T00:00:00.000Z',
|
||||
title: 'UFC FN HL: Nzechukwu v Cutelaba',
|
||||
description:
|
||||
"'UFC Fight Night Highlights - Heavyweight Bout: Kennedy Nzechukwu vs Ion Cutelaba'. From The UFC APEX Center - Las Vegas, USA.",
|
||||
icon: 'https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/271546_UFC Fight Night.png',
|
||||
category: ['All Sport', 'Mixed Martial Arts']
|
||||
})
|
||||
})
|
||||
|
||||
it('can parse response for NG', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_nga.json'))
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (url === `${API_ENDPOINT}/GetProgramme?id=6d58931e-2192-486a-a202-14720136d204`) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program_nga.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, channel: channelNG })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-11-21T23:00:00.000Z',
|
||||
stop: '2022-11-22T00:00:00.000Z',
|
||||
title: 'UFC FN HL: Nzechukwu v Cutelaba',
|
||||
description:
|
||||
"'UFC Fight Night Highlights - Heavyweight Bout: Kennedy Nzechukwu vs Ion Cutelaba'. From The UFC APEX Center - Las Vegas, USA.",
|
||||
icon: 'https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/271546_UFC Fight Night.png',
|
||||
category: ['All Sport', 'Mixed Martial Arts']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', done => {
|
||||
|
||||
Reference in New Issue
Block a user