epg-grabber/tests/index.test.js

48 lines
1.0 KiB
JavaScript
Raw Normal View History

2021-10-05 23:39:13 +02:00
/**
* @jest-environment node
*/
2021-09-15 10:19:58 +02:00
2021-10-05 23:39:13 +02:00
import grabber from '../src/index'
import utils from '../src/utils'
import axios from 'axios'
2021-10-06 02:02:36 +02:00
import path from 'path'
2021-09-15 10:19:58 +02:00
2021-10-05 23:39:13 +02:00
jest.mock('axios')
2021-09-15 10:19:58 +02:00
2021-10-05 23:39:13 +02:00
it('can grab single channel programs', done => {
const data = {
data: {
toString: () => 'string'
2021-09-15 10:19:58 +02:00
}
2021-10-05 23:39:13 +02:00
}
axios.mockImplementation(() => Promise.resolve(data))
2021-09-15 10:19:58 +02:00
2021-10-06 02:02:36 +02:00
const config = utils.loadConfig(require(path.resolve('./tests/input/mini.config.js')))
2021-10-05 23:39:13 +02:00
const channel = {
site: 'example.com',
site_id: '1',
xmltv_id: '1TV.fr',
lang: 'fr',
name: '1TV'
}
grabber.grab(channel, config, result => {
result.on('data', function (data) {
console.log(
` ${data.channel.site} - ${data.channel.xmltv_id} - ${data.date.format('MMM D, YYYY')} (${
data.programs.length
} programs)`
)
})
result.on('error', function (err) {
console.log(` Error: ${err.message}`)
done()
})
result.on('done', function (programs) {
expect(programs.length).toBe(0)
done()
})
})
2021-09-15 10:19:58 +02:00
})