2022-03-10 14:01:57 +03:00
// npm run channels:parse -- --config=./sites/magentatv.at/magentatv.at.config.js --output=./sites/magentatv.at/magentatv.at_at.channels.xml
// npx epg-grabber --config=sites/magentatv.at/magentatv.at.config.js --channels=sites/magentatv.at/magentatv.at_at.channels.xml --output=guide.xml --days=2
2022-03-09 22:26:42 +00:00
const { parser , url } = require ( './magentatv.at.config.js' )
const axios = require ( 'axios' )
const dayjs = require ( 'dayjs' )
const utc = require ( 'dayjs/plugin/utc' )
const customParseFormat = require ( 'dayjs/plugin/customParseFormat' )
dayjs . extend ( customParseFormat )
dayjs . extend ( utc )
jest . mock ( 'axios' )
const date = dayjs . utc ( '2022-03-09' , 'YYYY-MM-DD' ) . startOf ( 'd' )
const channel = {
2022-03-10 14:01:57 +03:00
site _id : '13TH_Street_HD' ,
2022-03-19 01:42:18 +03:00
xmltv _id : '13thStreet.de'
2022-03-09 22:26:42 +00:00
}
it ( 'can generate valid url' , ( ) => {
expect ( url ( { date } ) ) . toBe (
'https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules/20220309/1'
)
} )
it ( 'can parse response' , done => {
2022-03-10 14:01:57 +03:00
const content = ` {"entries":[{"o":"lgi-at-prodobo-master:13TH_Street_HD","l":[{"i":"crid:~~2F~~2Fbds.tv~~2F1870513,imi:c83a0bf1b04d6610d0517e63647772c1c8725693","t":"Law & Order: Special Victims Unit","s":1646778600000,"e":1646781300000,"c":"lgi-at-prodobo-master:genre-9","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]} `
2022-03-09 22:26:42 +00:00
axios . get . mockImplementation ( url => {
2022-03-10 14:01:57 +03:00
if ( url === 'https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules/20220309/2' ) {
2022-03-09 22:26:42 +00:00
return Promise . resolve ( {
data : JSON . parse (
2022-03-10 14:01:57 +03:00
` {"entries":[{"o":"lgi-at-prodobo-master:13TH_Street_HD","l":[{"i":"crid:~~2F~~2Fmedia-press.tv~~2F217048123,imi:ee14cfe306cb50502b03c96d58851c32345a9391","t":"FBI: Special Crime Unit","s":1646781300000,"e":1646784000000,"c":"lgi-at-prodobo-master:genre-9","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]} `
2022-03-09 22:26:42 +00:00
)
} )
} else if (
url === 'https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules/20220309/3'
) {
return Promise . resolve ( {
data : JSON . parse (
2022-03-10 14:01:57 +03:00
` {"entries":[{"o":"lgi-at-prodobo-master:13TH_Street_HD","l":[{"i":"crid:~~2F~~2Fmedia-press.tv~~2F224431085,imi:805c5a9b6610edb65cdff319a9b080ab5f65a6c8","t":"FBI: Special Crime Unit","s":1646784000000,"e":1646786700000,"c":"lgi-at-prodobo-master:genre-9","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]} `
2022-03-09 22:26:42 +00:00
)
} )
} else if (
url === 'https://prod.oesp.magentatv.at/oesp/v4/AT/deu/web/programschedules/20220309/4'
) {
return Promise . resolve ( {
data : JSON . parse (
2022-03-10 14:01:57 +03:00
` {"entries":[{"o":"lgi-at-prodobo-master:13TH_Street_HD","l":[{"i":"crid:~~2F~~2Fbds.tv~~2F918961,imi:f27353bf910e8849d60e0381fdb2d1f7518ef7a2","t":"Law & Order","s":1646786700000,"e":1646789400000,"c":"lgi-at-prodobo-master:genre-9","a":false,"r":false,"rm":false,"ad":[],"sl":[]}]}]} `
2022-03-09 22:26:42 +00:00
)
} )
} else {
return Promise . resolve ( { data : '' } )
}
} )
parser ( { content , channel , date } )
. then ( result => {
result = result . map ( p => {
p . start = p . start . toJSON ( )
p . stop = p . stop . toJSON ( )
return p
} )
expect ( result ) . toMatchObject ( [
{
2022-03-10 14:01:57 +03:00
start : '2022-03-08T22:30:00.000Z' ,
stop : '2022-03-08T23:15:00.000Z' ,
title : 'Law & Order: Special Victims Unit'
2022-03-09 22:26:42 +00:00
} ,
{
2022-03-10 14:01:57 +03:00
start : '2022-03-08T23:15:00.000Z' ,
stop : '2022-03-09T00:00:00.000Z' ,
title : 'FBI: Special Crime Unit'
2022-03-09 22:26:42 +00:00
} ,
{
2022-03-10 14:01:57 +03:00
start : '2022-03-09T00:00:00.000Z' ,
stop : '2022-03-09T00:45:00.000Z' ,
title : 'FBI: Special Crime Unit'
2022-03-09 22:26:42 +00:00
} ,
{
2022-03-10 14:01:57 +03:00
start : '2022-03-09T00:45:00.000Z' ,
stop : '2022-03-09T01:30:00.000Z' ,
title : 'Law & Order'
2022-03-09 22:26:42 +00:00
}
] )
done ( )
} )
. catch ( done )
} )
it ( 'can handle empty guide' , done => {
parser ( {
content : ` [{"type":"PATH_PARAM","code":"period","reason":"INVALID"}] ` ,
channel ,
date
} )
. then ( result => {
expect ( result ) . toMatchObject ( [ ] )
done ( )
} )
. catch ( done )
} )