epg-grabber/tests/index.test.js

46 lines
1001 B
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'
}
2021-10-06 15:38:22 +02:00
grabber
.grab(channel, config, (data, err) => {
if (err) {
console.log(` Error: ${err.message}`)
done()
} else {
console.log(
` ${data.channel.site} - ${data.channel.xmltv_id} - ${data.date.format(
'MMM D, YYYY'
)} (${data.programs.length} programs)`
)
}
2021-10-05 23:39:13 +02:00
})
2021-10-06 15:38:22 +02:00
.then(programs => {
2021-10-05 23:39:13 +02:00
expect(programs.length).toBe(0)
done()
})
2021-09-15 10:19:58 +02:00
})