2023-01-05 15:28:24 +03:00
// npx epg-grabber --config=sites/astro.com.my/astro.com.my.config.js --channels=sites/astro.com.my/astro.com.my.channels.xml --output=guide.xml --timeout=30000 --days=2
2022-08-29 19:38:19 +03:00
2022-08-29 10:39:33 +01:00
const { parser , url } = require ( './astro.com.my.config.js' )
2022-08-29 19:37:21 +03:00
const fs = require ( 'fs' )
const path = require ( 'path' )
2022-10-31 02:45:11 +03:00
const axios = require ( 'axios' )
2022-08-29 10:39:33 +01:00
const dayjs = require ( 'dayjs' )
const utc = require ( 'dayjs/plugin/utc' )
const customParseFormat = require ( 'dayjs/plugin/customParseFormat' )
dayjs . extend ( customParseFormat )
dayjs . extend ( utc )
2022-10-31 02:45:11 +03:00
jest . mock ( 'axios' )
const date = dayjs . utc ( '2022-10-31' , 'YYYY-MM-DD' ) . startOf ( 'd' )
2022-08-29 10:39:33 +01:00
const channel = {
2022-10-31 02:45:11 +03:00
site _id : '425' ,
xmltv _id : 'TVBClassic.hk'
2022-08-29 10:39:33 +01:00
}
it ( 'can generate valid url' , ( ) => {
2022-10-31 02:45:11 +03:00
expect ( url ( { channel } ) ) . toBe ( 'https://contenthub-api.eco.astro.com.my/channel/425.json' )
2022-08-29 10:39:33 +01:00
} )
2022-10-31 02:45:11 +03:00
it ( 'can parse response' , async ( ) => {
2022-08-29 19:37:21 +03:00
const content = fs . readFileSync ( path . resolve ( _ _dirname , '__data__/content.json' ) )
2022-10-31 02:45:11 +03:00
axios . get . mockImplementation ( url => {
if (
url ===
'https://contenthub-api.eco.astro.com.my/api/v1/linear-detail?siTrafficKey=1:10000526:47979653'
) {
return Promise . resolve ( {
data : JSON . parse ( fs . readFileSync ( path . resolve ( _ _dirname , '__data__/program.json' ) ) )
} )
} else {
return Promise . resolve ( { data : '' } )
}
} )
let results = await parser ( { content , channel , date } )
results = results . map ( p => {
2022-08-29 19:37:21 +03:00
p . start = p . start . toJSON ( )
p . stop = p . stop . toJSON ( )
return p
} )
2022-08-29 10:39:33 +01:00
2022-10-31 02:45:11 +03:00
expect ( results . length ) . toBe ( 31 )
2022-08-29 19:37:21 +03:00
expect ( results [ 0 ] ) . toMatchObject ( {
2022-10-31 02:45:11 +03:00
start : '2022-10-30T16:10:00.000Z' ,
stop : '2022-10-30T17:02:00.000Z' ,
title : 'Triumph in the Skies Ep06' ,
description :
'This classic drama depicts the many aspects of two complicated relationships set against an airline company. Will those involved ever find true love?' ,
actors : [ 'Francis Ng Chun Yu' , 'Joe Ma Tak Chung' , 'Flora Chan Wai San' ] ,
directors : [ 'Joe Ma Tak Chung' ] ,
icon : 'https://s3-ap-southeast-1.amazonaws.com/ams-astro/production/images/1035X328883.jpg' ,
rating : {
system : 'LPF' ,
value : 'U'
} ,
episode : 6 ,
categories : [ 'Drama' ]
2022-08-29 19:37:21 +03:00
} )
} )
2022-08-29 10:39:33 +01:00
2022-10-31 02:45:11 +03:00
it ( 'can handle empty guide' , async ( ) => {
2022-08-29 19:37:21 +03:00
const content = fs . readFileSync ( path . resolve ( _ _dirname , '__data__/no_content.html' ) )
2022-10-31 02:45:11 +03:00
const results = await parser ( { date , content } )
expect ( results ) . toMatchObject ( [ ] )
2022-08-29 19:37:21 +03:00
} )