forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dstv.com.test.js
109 lines (95 loc) · 3.49 KB
/
dstv.com.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
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')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
jest.mock('axios')
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#201',
xmltv_id: 'SuperSportGrandstand.za'
}
const channelNG = {
site_id: 'nga#201',
xmltv_id: 'SuperSportGrandstand.za'
}
it('can generate valid url for zaf', () => {
expect(url({ channel: channelZA, date })).toBe(
`${API_ENDPOINT}/GetProgrammes?d=2022-11-22&country=zaf`
)
})
it('can generate valid url for nga', () => {
expect(url({ channel: channelNG, date })).toBe(
`${API_ENDPOINT}/GetProgrammes?d=2022-11-22&package=DStv%20Premium&country=nga`
)
})
it('can parse response for ZA', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content_zaf.json'))
axios.get.mockImplementation(url => {
if (url === `${API_ENDPOINT}/GetProgramme?id=8b237235-aa17-4bb8-9ea6-097e7a813336`) {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program_zaf.json')))
})
} else {
return Promise.resolve({ data: '' })
}
})
let results = await parser({ content, channel: channelZA })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
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 => {
parser({
content: '{"Total":0,"Channels":[]}',
channel: channelZA
})
.then(result => {
expect(result).toMatchObject([])
done()
})
.catch(done)
})