epg-grabber/tests/parser.test.js

41 lines
1.2 KiB
JavaScript
Raw Normal View History

2022-06-16 14:07:56 +02:00
import { parseChannels, parsePrograms } from '../src/parser'
import Channel from '../src/Channel'
import Program from '../src/Program'
import fs from 'fs'
it('can parse valid channels.xml', () => {
2022-08-29 03:13:47 +02:00
const file = fs.readFileSync('./tests/__data__/input/example.channels.xml', { encoding: 'utf-8' })
2022-06-16 14:07:56 +02:00
const { channels, site } = parseChannels(file)
expect(typeof site).toBe('string')
expect(channels.length).toBe(2)
expect(channels[0]).toBeInstanceOf(Channel)
expect(channels[1]).toBeInstanceOf(Channel)
})
it('can parse programs', done => {
2022-07-01 01:45:59 +02:00
const channel = new Channel({ xmltv_id: '1tv' })
2022-08-29 03:13:47 +02:00
const config = require('./__data__/input/example.config.js')
2022-06-16 14:07:56 +02:00
parsePrograms({ channel, config })
.then(programs => {
expect(programs.length).toBe(1)
expect(programs[0]).toBeInstanceOf(Program)
done()
})
.catch(done)
})
it('can parse programs async', done => {
2022-07-01 01:45:59 +02:00
const channel = new Channel({ xmltv_id: '1tv' })
2022-08-29 03:13:47 +02:00
const config = require('./__data__/input/async.config.js')
2022-06-16 14:07:56 +02:00
parsePrograms({ channel, config })
.then(programs => {
expect(programs.length).toBe(1)
expect(programs[0]).toBeInstanceOf(Program)
done()
})
.catch(done)
})