2025-12-15 00:45:10 +01:00
const { parser , url , request } = require ( './sky.co.nz.config.js' )
2025-09-28 17:55:05 +03:00
const fs = require ( 'fs' )
const path = require ( 'path' )
const dayjs = require ( 'dayjs' )
const utc = require ( 'dayjs/plugin/utc' )
2025-12-15 00:45:10 +01:00
const tz = require ( 'dayjs/plugin/timezone' )
2025-09-28 17:55:05 +03:00
dayjs . extend ( utc )
2025-12-15 00:45:10 +01:00
dayjs . extend ( tz )
2025-09-28 17:55:05 +03:00
const channel = {
2025-12-15 00:45:10 +01:00
site _id : '1' ,
xmltv _id : 'TVNZ 1'
2025-09-28 17:55:05 +03:00
}
it ( 'can generate valid url' , ( ) => {
2025-12-15 00:45:10 +01:00
expect ( url ) . toBe ( 'https://api.skyone.co.nz/exp/graph' )
} )
it ( 'can generate valid request method' , ( ) => {
expect ( request . method ) . toBe ( 'POST' )
2025-09-28 17:55:05 +03:00
} )
it ( 'can parse response' , ( ) => {
const content = fs . readFileSync ( path . resolve ( _ _dirname , '__data__/content.json' ) )
2025-12-15 00:45:10 +01:00
const result = parser ( { content , channel } ) . map ( p => {
2025-09-28 17:55:05 +03:00
p . start = p . start . toJSON ( )
p . stop = p . stop . toJSON ( )
return p
} )
expect ( result [ 0 ] ) . toMatchObject ( {
2025-12-15 00:45:10 +01:00
title : 'Hard Quiz' ,
2025-09-28 17:55:05 +03:00
description :
2025-12-15 00:45:10 +01:00
"What do King Henry VII, Shaquille O'Neal, dinosaurs and The Adventures of Priscilla, Queen of the Desert have in common? They're all expert topics on tonight's #HardQuiz!" ,
2025-09-28 17:55:05 +03:00
rating : { system : 'OFLC' , value : 'PG' } ,
2025-12-15 00:45:10 +01:00
start : '2025-12-12T10:40:00.000Z' ,
stop : '2025-12-12T11:15:00.000Z'
2025-09-28 17:55:05 +03:00
} )
2025-12-15 00:45:10 +01:00
expect ( result [ 33 ] ) . toMatchObject ( {
title : 'Obituary' ,
2025-09-28 17:55:05 +03:00
description :
2025-12-15 00:45:10 +01:00
'Season Finale: When Ward reveals what really happened the night Maria Riedle was killed, Elvira sets about framing Hughie for the crime. S1 E6' ,
rating : { system : 'OFLC' , value : '16' } ,
start : '2025-12-13T10:55:00.000Z' ,
stop : '2025-12-13T11:50:00.000Z'
2025-09-28 17:55:05 +03:00
} )
} )
2025-12-15 00:45:10 +01:00
// Not easy to mock this case, as it's the same repeated message (for all channels ?)
// with the time space in the message. Only what doesn't change is provided, but will still pass the test out.
2025-09-28 17:55:05 +03:00
it ( 'can handle empty guide' , ( ) => {
2025-12-15 00:45:10 +01:00
const result = parser ( {
content : ` {
"locations" : [
{
"line" : 14 ,
"column" : 11
}
] ,
"path" : [
"experience" ,
"channelGroup" ,
"channels" ,
0 ,
"slotsForDay"
] ,
"extensions" : {
"classification" : "DataFetchingException"
}
} ` ,
2025-09-28 17:55:05 +03:00
channel
2025-12-15 00:45:10 +01:00
} )
2025-09-28 17:55:05 +03:00
expect ( result ) . toMatchObject ( [ ] )
} )