forked from iptv-org/epg
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtoonamiaftermath.com.test.js
More file actions
61 lines (52 loc) · 1.83 KB
/
toonamiaftermath.com.test.js
File metadata and controls
61 lines (52 loc) · 1.83 KB
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
const { parser, url } = require('./toonamiaftermath.com.config.js')
const fs = require('fs')
const path = require('path')
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 API_ENDPOINT = 'https://api.toonamiaftermath.com'
const date = dayjs.utc('2022-11-29', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: 'Toonami Aftermath EST',
xmltv_id: 'ToonamiAftermathEast.us'
}
it('can generate valid url', async () => {
axios.get.mockImplementation(url => {
if (
url ===
`${API_ENDPOINT}/playlists?scheduleName=Toonami Aftermath EST&startDate=2022-11-30T00:00:00.000Z&thisWeek=true&weekStartDay=monday`
) {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/playlists.json')))
})
} else {
return Promise.resolve({ data: '' })
}
})
const result = await url({ channel, date })
expect(result).toBe(`${API_ENDPOINT}/playlist?id=635fbd8117f6824d953a216e&addInfo=true`)
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
let results = parser({ content, channel, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(62)
expect(results[0]).toMatchObject({
start: '2022-11-29T17:00:30.231Z',
stop: '2022-11-29T17:20:54.031Z',
title: 'X-Men',
sub_title: 'Reunion (Part 1)',
image: 'https://i.imgur.com/ZSZ0x1m.gif'
})
})
it('can handle empty guide', () => {
const result = parser({ content: '', date })
expect(result).toMatchObject([])
})