Added tests
This commit is contained in:
parent
4d1364ad29
commit
a3e4479dfc
|
@ -5,3 +5,4 @@ node_js:
|
|||
|
||||
script:
|
||||
- npm run lint
|
||||
- npm run test
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -9,7 +9,7 @@
|
|||
},
|
||||
"scripts": {
|
||||
"lint": "npx eslint ./src/**/*.js",
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
"test": "npx jest"
|
||||
},
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
|
@ -33,6 +33,7 @@
|
|||
"xml-js": "^1.6.11"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "^7.22.0"
|
||||
"eslint": "^7.22.0",
|
||||
"jest": "^26.6.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<site site="example.com">
|
||||
<channels>
|
||||
<channel site_id="1" xmltv_id="1TV.com">1 TV</channel>
|
||||
<channel site_id="2" xmltv_id="2TV.com">2 TV</channel>
|
||||
</channels>
|
||||
</site>
|
|
@ -0,0 +1,6 @@
|
|||
module.exports = {
|
||||
site: 'example.com',
|
||||
channels: 'example.com.channels.xml',
|
||||
url: () => 'http://example.com/20210319/1tv.json',
|
||||
parser: () => []
|
||||
}
|
|
@ -0,0 +1,67 @@
|
|||
const utils = require('../src/utils')
|
||||
|
||||
it('can load valid config.js', () => {
|
||||
expect(Object.keys(utils.loadConfig('./tests/input/example.com.config.js')).sort()).toEqual(
|
||||
[
|
||||
'site',
|
||||
'channels',
|
||||
'url',
|
||||
'parser',
|
||||
'cookie',
|
||||
'days',
|
||||
'delay',
|
||||
'lang',
|
||||
'output',
|
||||
'userAgent'
|
||||
].sort()
|
||||
)
|
||||
})
|
||||
|
||||
it('can parse valid channels.xml', () => {
|
||||
expect(utils.parseChannels('./tests/input/example.com.channels.xml')).toEqual([
|
||||
{
|
||||
name: '1 TV',
|
||||
xmltv_id: '1TV.com',
|
||||
site_id: '1',
|
||||
site: 'example.com'
|
||||
},
|
||||
{
|
||||
name: '2 TV',
|
||||
xmltv_id: '2TV.com',
|
||||
site_id: '2',
|
||||
site: 'example.com'
|
||||
}
|
||||
])
|
||||
})
|
||||
|
||||
it('can convert object to xmltv string', () => {
|
||||
const config = { lang: 'en' }
|
||||
const channels = [
|
||||
{
|
||||
name: '1 TV',
|
||||
xmltv_id: '1TV.com',
|
||||
site_id: '1',
|
||||
site: 'example.com'
|
||||
},
|
||||
{
|
||||
name: '2 TV',
|
||||
xmltv_id: '2TV.com',
|
||||
site_id: '2',
|
||||
site: 'example.com'
|
||||
}
|
||||
]
|
||||
const programs = [
|
||||
{
|
||||
title: 'Program 1',
|
||||
description: 'Description for Program 1',
|
||||
start: '2021-03-19 06:00:00 +0000',
|
||||
stop: '2021-03-19 06:30:00 +0000',
|
||||
category: 'Test',
|
||||
channel: '1TV.com'
|
||||
}
|
||||
]
|
||||
const output = utils.convertToXMLTV({ config, channels, programs })
|
||||
expect(output).toBe(
|
||||
'<?xml version="1.0" encoding="UTF-8" ?><tv>\r\n<channel id="1TV.com"><display-name>1 TV</display-name></channel>\r\n<channel id="2TV.com"><display-name>2 TV</display-name></channel>\r\n<programme start="20210319060000 +0000" stop="20210319063000 +0000" channel="1TV.com"><title lang="en">Program 1</title><desc lang="en">Description for Program 1</desc><category lang="en">Test</category></programme>\r\n</tv>'
|
||||
)
|
||||
})
|
Loading…
Reference in New Issue