2025-09-28 17:55:05 +03:00
const { parser , url } = require ( './sky.com.config.js' )
const fs = require ( 'fs' )
const path = require ( 'path' )
2026-06-08 19:04:43 +07:00
const axios = require ( 'axios' )
2025-09-28 17:55:05 +03:00
const dayjs = require ( 'dayjs' )
const utc = require ( 'dayjs/plugin/utc' )
const customParseFormat = require ( 'dayjs/plugin/customParseFormat' )
dayjs . extend ( customParseFormat )
dayjs . extend ( utc )
2026-06-08 19:04:43 +07:00
jest . mock ( 'axios' )
const date = dayjs . utc ( '2026-06-08' ) . startOf ( 'd' )
2025-09-28 17:55:05 +03:00
const channel = {
site _id : '4086' ,
2026-06-08 19:04:43 +07:00
xmltv _id : 'SkyHistory.uk@HD'
2025-09-28 17:55:05 +03:00
}
2026-06-08 19:04:43 +07:00
axios . get . mockImplementation ( url => {
const urls = {
'https://awk.epgsky.com/hawk/linear/schedule/20260608/4086' : 'content1.json' ,
'https://awk.epgsky.com/hawk/linear/schedule/20260609/4086' : 'content2.json'
}
let data = ''
if ( urls [ url ] !== undefined ) {
data = fs . readFileSync ( path . join ( _ _dirname , '__data__' , urls [ url ] ) ) . toString ( )
}
return Promise . resolve ( { data } )
} )
2025-09-28 17:55:05 +03:00
it ( 'can generate valid url' , ( ) => {
2026-06-08 19:04:43 +07:00
expect ( url ( { channel , date } ) ) . toBe ( 'https://awk.epgsky.com/hawk/linear/schedule/20260608/4086' )
2025-09-28 17:55:05 +03:00
} )
2026-06-08 19:04:43 +07:00
it ( 'can parse response' , async ( ) => {
const content = fs . readFileSync ( path . join ( _ _dirname , '__data__' , 'content1.json' ) )
const result = ( await parser ( { content , channel , date } ) )
. map ( p => {
p . start = p . start . toJSON ( )
p . stop = p . stop . toJSON ( )
return p
} )
2025-09-28 17:55:05 +03:00
2026-06-08 19:04:43 +07:00
expect ( result . length ) . toBe ( 30 )
2025-09-28 17:55:05 +03:00
expect ( result [ 0 ] ) . toMatchObject ( {
2026-06-08 19:04:43 +07:00
start : '2026-06-07T23:45:00.000Z' ,
stop : '2026-06-08T00:45:00.000Z' ,
title : 'The UnBelievable With Dan Aykroyd' ,
2025-09-28 17:55:05 +03:00
description :
2026-06-08 19:04:43 +07:00
'Bizarre Innovations: Discover bizarre innovations like a fully functioning car that hovers in midair. Or clothing made out of everyone\'s favorite source of calcium. (S2, ep 6)' ,
season : 2 ,
2025-09-28 17:55:05 +03:00
episode : 6 ,
2026-06-08 19:04:43 +07:00
icon : 'https://images.metadata.sky.com/pd-image/007ade72-3239-47d7-a452-3070eb8e591d/16-9/640' ,
image : 'https://images.metadata.sky.com/pd-image/007ade72-3239-47d7-a452-3070eb8e591d/16-9/640'
2025-09-28 17:55:05 +03:00
} )
2026-06-08 19:04:43 +07:00
expect ( result [ 29 ] ) . toMatchObject ( {
start : '2026-06-08T23:00:00.000Z' ,
stop : '2026-06-09T00:00:00.000Z' ,
title : 'Digging For Britain' ,
2026-04-19 02:00:35 +03:00
description :
2026-06-08 19:04:43 +07:00
'The Tudors: Dr Alice Roberts pays tribute to the Bard, visiting Shakespeare\'s first theatre in London\'s Shoreditch and sifting through the poet\'s rubbish! (S1, ep 4)' ,
2026-04-19 02:00:35 +03:00
season : 1 ,
2026-06-08 19:04:43 +07:00
episode : 4 ,
icon : 'https://images.metadata.sky.com/pd-image/68152ae7-97d6-44c8-8a54-e78710b94a76/16-9/640' ,
image : 'https://images.metadata.sky.com/pd-image/68152ae7-97d6-44c8-8a54-e78710b94a76/16-9/640'
2026-04-19 02:00:35 +03:00
} )
2025-09-28 17:55:05 +03:00
} )
2026-06-08 19:04:43 +07:00
it ( 'can handle empty guide' , async ( ) => {
const result = await parser ( {
2025-09-28 17:55:05 +03:00
date ,
channel ,
content : ''
} )
expect ( result ) . toMatchObject ( [ ] )
} )