Files
epg/sites/beinsports.com/beinsports.com.test.js

92 lines
3.2 KiB
JavaScript
Raw Normal View History

2022-05-08 18:17:05 +03:00
// npm run channels:parse -- --config=./sites/beinsports.com/beinsports.com.config.js --output=./sites/beinsports.com/beinsports.com_qa-ar.channels.xml --set=lang:ar --set=region:ar
2022-05-08 16:50:39 +03:00
// npx epg-grabber --config=sites/beinsports.com/beinsports.com.config.js --channels=sites/beinsports.com/beinsports.com_qa-en.channels.xml --output=guide.xml --timeout=30000 --days=2
2022-05-09 15:02:48 +03:00
// npx epg-grabber --config=sites/beinsports.com/beinsports.com.config.js --channels=sites/beinsports.com/beinsports.com_us-en.channels.xml --output=guide.xml --timeout=30000 --days=2
2021-11-04 15:37:57 +03:00
2022-02-01 04:15:12 +03:00
const { parser, url } = require('./beinsports.com.config.js')
2022-05-08 16:26:36 +03:00
const fs = require('fs')
const path = require('path')
2021-11-04 15:37:57 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
2022-05-08 16:26:36 +03:00
const date = dayjs.utc('2022-05-08', 'YYYY-MM-DD').startOf('d')
2022-05-10 14:09:57 +03:00
const channel = { site_id: '#2', xmltv_id: 'BeINSports.qa' }
2021-11-04 15:37:57 +03:00
it('can generate valid url', () => {
2022-05-08 18:17:05 +03:00
const result = url({ date, channel })
2021-11-04 15:37:57 +03:00
expect(result).toBe(
2022-05-08 16:26:36 +03:00
'https://epg.beinsports.com/utctime.php?mins=00&serviceidentity=beinsports.com&cdate=2022-05-08'
2021-11-04 15:37:57 +03:00
)
})
2022-05-08 18:17:05 +03:00
it('can generate valid url for arabic guide', () => {
const channel = { site_id: 'ar#1', xmltv_id: 'BeINSports.qa' }
const result = url({ date, channel })
expect(result).toBe(
'https://epg.beinsports.com/utctime_ar.php?mins=00&serviceidentity=beinsports.com&cdate=2022-05-08'
)
})
2021-11-04 15:37:57 +03:00
it('can parse response', () => {
2022-05-08 16:26:36 +03:00
const content = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/content.html'))
const results = parser({ date, channel, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
2022-05-10 14:09:57 +03:00
start: '2022-05-07T19:30:00.000Z',
stop: '2022-05-07T21:20:00.000Z',
title: 'Lorient vs Marseille',
category: ['Ligue 1 2021/22']
})
})
it('can parse response for tomorrow', () => {
const date = dayjs.utc('2022-05-09', 'YYYY-MM-DD').startOf('d')
const content = fs.readFileSync(
path.resolve('sites/beinsports.com/__data__/content_tomorrow.html')
)
const results = parser({ date, channel, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
start: '2022-05-08T21:20:00.000Z',
stop: '2022-05-08T23:10:00.000Z',
title: 'Celtic vs Hearts',
category: ['SPFL Premiership 2021/22']
2022-05-09 15:02:48 +03:00
})
})
it('can parse US response', () => {
const content = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/content_us.html'))
const results = parser({ date, channel, content }).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results[0]).toMatchObject({
2022-05-10 14:09:57 +03:00
start: '2022-05-07T20:00:00.000Z',
stop: '2022-05-07T22:00:00.000Z',
2022-05-09 15:02:48 +03:00
title: 'Basaksehir vs. Galatasaray',
2022-05-10 14:09:57 +03:00
category: ['Fútbol Turco Superliga', 'Soccer']
2022-05-08 16:26:36 +03:00
})
})
it('can handle empty guide', () => {
const noContent = fs.readFileSync(path.resolve('sites/beinsports.com/__data__/no-content.html'))
const result = parser({
date,
channel,
content: noContent
})
expect(result).toMatchObject([])
2021-11-04 15:37:57 +03:00
})