-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
knr.gl.test.js
67 lines (57 loc) · 2.06 KB
/
knr.gl.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
const { parser, url, request } = require('./knr.gl.config.js')
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)
const date = dayjs.utc('2021-11-22', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '#',
xmltv_id: 'KNR.gl'
}
it('can generate valid url', () => {
expect(url).toBe('https://knr.gl/kl/tv/aallakaatitassat?ajax_form=1')
})
it('can generate valid request method', () => {
expect(request.method).toBe('POST')
})
it('can generate valid request headers', () => {
expect(request.headers).toMatchObject({})
})
it('can generate valid request data', () => {
const params = request.data({ date })
expect(params.get('list_date')).toBe('2021-11-22')
expect(params.get('form_id')).toBe('knr_radio_tv_program_overview_form')
expect(params.get('_triggering_element_name')).toBe('list_date')
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
const results = parser({ content, date }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2021-11-22T11:00:00.000Z',
stop: '2021-11-22T11:30:00.000Z',
title: 'Issittormiuaqqat'
})
expect(results[4]).toMatchObject({
start: '2021-11-22T13:00:00.000Z',
stop: '2021-11-22T13:30:00.000Z',
title: 'KNR2: Tusagassiortunik katersortitsineq - Erik Jensen',
description:
'Naalakkersuisoq Erik Jensen tusagassiortunut 21.november nal. 10.00-11.00 katersortitsissaaq attassisinnaanermut siuariartornermullu pilersaarut pillugu (holdbarheds- og vækstplan).'
})
})
it('can handle empty guide', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
const result = parser({
date,
channel,
content
})
expect(result).toMatchObject([])
})