2023-10-15 14:08:23 +03:00
const { parser , url } = require ( './sky.com.config.js' )
2024-12-15 03:46:36 +07:00
const fs = require ( 'fs' )
const path = require ( 'path' )
2023-10-15 14:08:23 +03:00
const dayjs = require ( 'dayjs' )
const utc = require ( 'dayjs/plugin/utc' )
const customParseFormat = require ( 'dayjs/plugin/customParseFormat' )
2024-12-15 03:46:36 +07:00
2023-10-15 14:08:23 +03:00
dayjs . extend ( customParseFormat )
dayjs . extend ( utc )
2024-12-15 03:46:36 +07:00
const date = dayjs . utc ( '2024-12-14' , 'YYYY-MM-DD' ) . startOf ( 'd' )
2023-10-15 14:08:23 +03:00
const channel = {
2024-12-15 03:46:36 +07:00
site _id : '4086' ,
xmltv _id : 'SkyHistoryHD.uk'
2023-10-15 14:08:23 +03:00
}
it ( 'can generate valid url' , ( ) => {
expect ( url ( { channel , date } ) ) . toBe (
2024-12-15 03:46:36 +07:00
'https://awk.epgsky.com/hawk/linear/schedule/20241214/4086'
2023-10-15 14:08:23 +03:00
)
} )
it ( 'can parse response' , ( ) => {
2024-12-15 03:46:36 +07:00
const content = fs . readFileSync ( path . join ( _ _dirname , '__data__' , 'content.json' ) )
2023-10-15 14:08:23 +03:00
const result = parser ( { content , channel , date } ) . map ( p => {
p . start = p . start . toJSON ( )
p . stop = p . stop . toJSON ( )
return p
} )
2024-12-15 03:46:36 +07:00
expect ( result . length ) . toBe ( 33 )
expect ( result [ 0 ] ) . toMatchObject ( {
start : '2024-12-13T22:00:00.000Z' ,
stop : '2024-12-13T23:00:00.000Z' ,
title : 'The UnXplained With...' ,
description :
'The Hunt for Jack the Ripper: Jack the Ripper\'s identity has eluded police, historians and armchair detectives for over a century. What do we know about the notorious killer? (S3, ep 21)' ,
season : 4 ,
episode : 14
} )
expect ( result [ 4 ] ) . toMatchObject ( {
start : '2024-12-14T01:00:00.000Z' ,
stop : '2024-12-14T01:30:00.000Z' ,
title : 'Storage Wars' ,
description :
'Not All That Glitters Is Gourd: Back in the city of Orange, the Vegas Ladies arrive in vintage style - though not everyone agrees. (S12, ep 6)' ,
season : 12 ,
episode : 6
} )
2023-10-15 14:08:23 +03:00
} )
it ( 'can handle empty guide' , ( ) => {
const result = parser ( {
date ,
channel ,
2024-12-15 03:46:36 +07:00
content : ''
2023-10-15 14:08:23 +03:00
} )
expect ( result ) . toMatchObject ( [ ] )
} )