-
-
Notifications
You must be signed in to change notification settings - Fork 239
/
tvguide.com.test.js
72 lines (64 loc) · 2.12 KB
/
tvguide.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
const { parser, url } = require('./tvguide.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 date = dayjs.utc('2022-10-30', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '9100001138#9200018514',
xmltv_id: 'CBSEast.us'
}
it('can generate valid url', () => {
expect(url({ date, channel })).toBe(
'https://internal-prod.apigee.fandom.net/v1/xapi/tvschedules/tvguide/9100001138/web?start=1667088000&duration=1440&channelSourceIds=9200018514'
)
})
it('can parse response', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
axios.get.mockImplementation(url => {
if (
url ===
'https://fandom-prod.apigee.net/v1/xapi/tvschedules/tvguide/programdetails/6060613824/web'
) {
return Promise.resolve({
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program.json')))
})
} else {
return Promise.resolve({ data: '' })
}
})
let results = await parser({ content, channel, date })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[5]).toMatchObject({
start: '2022-10-30T13:00:00.000Z',
stop: '2022-10-30T14:30:00.000Z',
title: 'CBS Sunday Morning',
sub_title: '10-30-2022',
description:
'The Backseat Lovers perform on the "Saturday Sessions"; and Daisy Ryan guests on "The Dish." Also: comedian Fortune Feimster.',
categories: ['Talk & Interview', 'Other'],
season: 40,
episode: 248,
rating: {
system: 'MPA',
value: 'TV-PG'
}
})
})
it('can handle empty guide', async () => {
const results = await parser({
date,
channel,
content: fs.readFileSync(path.resolve(__dirname, '__data__/no-content.json'))
})
expect(results).toMatchObject([])
})