2025-09-28 17:55:05 +03:00
const { parser , url } = require ( './ziggogo.tv.config.js' )
const fs = require ( 'fs' )
const path = require ( 'path' )
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' )
2026-05-30 19:41:49 +07:00
const date = dayjs . utc ( '2026-05-30' ). startOf ( 'd' )
2025-09-28 17:55:05 +03:00
const channel = {
2026-05-30 19:41:49 +07:00
site_id : 'NL_000007_019181' ,
xmltv_id : 'RTL7.nl@SD'
2025-09-28 17:55:05 +03:00
}
axios . get . mockImplementation ( url => {
const urls = {
2026-05-30 19:41:49 +07:00
'https://staticqbr-prod-nl.gnp.cloud.ziggogo.tv/eng/web/epg-service-lite/nl/en/events/segments/20260530000000' :
2025-09-28 17:55:05 +03:00
'content00.json' ,
2026-05-30 19:41:49 +07:00
'https://staticqbr-prod-nl.gnp.cloud.ziggogo.tv/eng/web/epg-service-lite/nl/en/events/segments/20260530060000' :
2025-09-28 17:55:05 +03:00
'content06.json' ,
2026-05-30 19:41:49 +07:00
'https://staticqbr-prod-nl.gnp.cloud.ziggogo.tv/eng/web/epg-service-lite/nl/en/events/segments/20260530120000' :
2025-09-28 17:55:05 +03:00
'content12.json' ,
2026-05-30 19:41:49 +07:00
'https://staticqbr-prod-nl.gnp.cloud.ziggogo.tv/eng/web/epg-service-lite/nl/en/events/segments/20260530180000' :
2025-09-28 17:55:05 +03:00
'content18.json' ,
2026-05-30 19:41:49 +07:00
'https://spark-prod-nl.gnp.cloud.ziggogo.tv/eng/web/linear-service/v2/replayEvent/crid:~~2F~~2Fgn.tv~~2F32036579~~2FSH062278610000~~2F492767862,imi:25ee264da729e66ee9ab4cb70d30ab2d76b661f4?returnLinearContent=true&forceLinearResponse=true&language=nl' :
2025-09-28 17:55:05 +03:00
'program01.json' ,
2026-05-30 19:41:49 +07:00
'https://spark-prod-nl.gnp.cloud.ziggogo.tv/eng/web/linear-service/v2/replayEvent/crid:~~2F~~2Fgn.tv~~2F18311595~~2FEP027840300446,imi:dc898b6240c51d7bb7aa0c13d38409e025ce0a71?returnLinearContent=true&forceLinearResponse=true&language=nl' :
'program02.json'
2025-09-28 17:55:05 +03:00
}
let data = ''
if ( urls [ url ] !== undefined ) {
data = fs . readFileSync ( path . join ( __dirname , '__data__' , urls [ url ])). toString ()
if ( ! urls [ url ]. startsWith ( 'content00' )) {
data = JSON . parse ( data )
}
}
return Promise . resolve ({ data })
})
it ( 'can generate valid url' , () => {
expect ( url ({ date })). toBe (
2026-05-30 19:41:49 +07:00
'https://staticqbr-prod-nl.gnp.cloud.ziggogo.tv/eng/web/epg-service-lite/nl/en/events/segments/20260530000000'
2025-09-28 17:55:05 +03:00
)
})
it ( 'can parse response' , async () => {
const content = await axios
. get ( url ({ date }))
. then ( response => response . data )
. catch ( console . error )
const result = ( await parser ({ content , channel , date })). map ( p => {
p . start = p . start . toJSON ()
p . stop = p . stop . toJSON ()
return p
})
2026-05-30 19:41:49 +07:00
expect ( result . length ). toBe ( 21 )
2025-09-28 17:55:05 +03:00
expect ( result [ 2 ]). toMatchObject ({
2026-05-30 19:41:49 +07:00
start : '2026-05-30T04:00:00.000Z' ,
stop : '2026-05-30T11:03:00.000Z' ,
title : 'Telvero' ,
2025-09-28 17:55:05 +03:00
description :
2026-05-30 19:41:49 +07:00
'Homeshoppingprogramma waarin de kijker via de telefoon allerlei producten kan aanschaffen.' ,
category : [ "Consumentenprogramma's" , 'Shoppen' ],
season : 78610000 ,
episode : 492767862
})
expect ( result [ 19 ]). toMatchObject ({
start : '2026-05-30T22:44:00.000Z' ,
stop : '2026-05-30T23:39:00.000Z' ,
title : 'Pawn Stars' ,
subTitle : 'Mystery Safe' ,
description :
'Rick en Chum onderhandelen over een Superman-pyjama. Rick tikt een vintage industriële snijmachine op de kop. Chum roept de hulp in van Alex als hij een zeldzaam jasje uit de Tweede Wereldoorlog tegenkomt.' ,
category : [ 'Reality' , 'Veiling' ],
season : 17 ,
episode : 24 ,
actor : [ 'Corey Harrison' , 'Rick Harrison' , 'Austin Chumlee Russell' ]
2025-09-28 17:55:05 +03:00
})
})
it ( 'can handle empty guide' , async () => {
const result = await parser ({
content : '' ,
channel ,
date
})
expect ( result ). toMatchObject ([])
})