forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rev.bs.test.js
80 lines (73 loc) · 2.24 KB
/
rev.bs.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
const { parser, url } = require('./rev.bs.config.js')
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)
jest.mock('axios')
const date = dayjs.utc('2021-11-21', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '206',
xmltv_id: 'WTVJ.us'
}
it('can generate valid url', () => {
expect(url({ date, channel })).toBe(
'https://www.rev.bs/wp-content/uploads/tv-guide/2021-11-21_0.json'
)
})
it('can parse response', done => {
axios.get.mockImplementation(url => {
if (url === 'https://www.rev.bs/wp-content/uploads/tv-guide/2021-11-21_1.json') {
return Promise.resolve({
data: Buffer.from(
'{"status":"OK","data":{"schedule":{"206":[{"title":"Talk Stoop","sid":43599836,"s":"330.0000","duration":30,"rating":"TVPG"}]}}}'
)
})
} else {
return Promise.resolve({
data: Buffer.from('{"status":"OK","data":{"schedule":{}}}')
})
}
})
const content =
'{"status":"OK","data":{"schedule":{"205":[{"title":"Rev Pulse 5 - Online Classifieds","sid":43576112,"s":"-120.0000","duration":120,"rating":""}],"206":[{"title":"Saturday Night Live","sid":43599827,"s":"-31.0000","duration":93,"rating":"TV14"}]}}}'
parser({ content, channel, date })
.then(result => {
result = result.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(result).toMatchObject([
{
start: '2021-11-21T04:29:00.000Z',
stop: '2021-11-21T06:02:00.000Z',
title: 'Saturday Night Live'
},
{
start: '2021-11-21T10:30:00.000Z',
stop: '2021-11-21T11:00:00.000Z',
title: 'Talk Stoop'
}
])
done()
})
.catch(err => {
done(err)
})
})
it('can handle empty guide', done => {
parser({
date,
channel,
content: '<html lang="en"><head></head><body></body></html>'
})
.then(result => {
expect(result).toMatchObject([])
done()
})
.catch(err => {
done(err)
})
})