epg-grabber/tests/index.test.js

69 lines
1.6 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
2022-07-06 18:56:48 +02:00
import { EPGGrabber, Channel } from '../src/index'
2021-10-05 23:39:13 +02:00
import axios from 'axios'
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-13 21:52:46 +02:00
it('return "Connection timeout" error if server does not response', done => {
const config = {
site: 'example.com',
request: {
timeout: 1000
},
url({ date, channel }) {
return `https://www.cosmote.gr/cosmotetv/residential/program/epg/programchannel?p_p_id=channelprogram_WAR_OTETVportlet&p_p_lifecycle=0&_channelprogram_WAR_OTETVportlet_platform=IPTV&_channelprogram_WAR_OTETVportlet_date=${date.format(
'DD-MM-YYYY'
)}&_channelprogram_WAR_OTETVportlet_articleTitleUrl=${channel.site_id}`
},
parser: () => []
}
2022-07-06 18:56:48 +02:00
const channel = new Channel({
2021-10-13 21:52:46 +02:00
site: 'example.com',
site_id: 'cnn',
xmltv_id: 'CNN.us',
lang: 'en',
name: 'CNN'
2022-07-06 18:56:48 +02:00
})
2022-03-29 15:00:00 +02:00
const grabber = new EPGGrabber(config)
grabber.grab(channel, '2022-01-01', (data, err) => {
2021-10-13 21:52:46 +02:00
expect(err.message).toBe('Connection timeout')
done()
})
})
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-13 21:52:46 +02:00
const config = {
site: 'example.com',
url: 'http://example.com/20210319/1tv.json',
parser: () => []
}
2022-07-06 18:56:48 +02:00
const channel = new Channel({
2021-10-05 23:39:13 +02:00
site: 'example.com',
site_id: '1',
xmltv_id: '1TV.fr',
lang: 'fr',
name: '1TV'
2022-07-06 18:56:48 +02:00
})
2022-03-29 15:00:00 +02:00
const grabber = new EPGGrabber(config)
2021-10-06 15:38:22 +02:00
grabber
2022-03-29 15:00:00 +02:00
.grab(channel, '2022-01-01', (data, err) => {
2021-10-06 15:38:22 +02:00
if (err) {
done()
}
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
})