2025-09-28 17:55:05 +03:00
const { parser , url } = require ( './tivie.id.config' )
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-04-30 09:45:38 +07:00
const date = dayjs . utc ( '2026-04-29' ) . startOf ( 'd' )
2025-09-28 17:55:05 +03:00
const channel = {
site _id : 'axn' ,
xmltv _id : 'AXN.id' ,
lang : 'id'
}
axios . get . mockImplementation ( url => {
const urls = {
2026-04-30 09:45:38 +07:00
'https://tivie.id/program/the-hunting-party-e3-nwzDnwrCmAnB?utm_source=tivie&utm_medium=referral&utm_campaign=channel_detail&utm_content=button' : 'program01.html' ,
'https://tivie.id/program/the-rookie-s7-e6-nwzDnwv6mwzC?utm_source=tivie&utm_medium=referral&utm_campaign=channel_detail&utm_content=button' : 'program02.html'
2025-09-28 17:55:05 +03:00
}
let data = ''
if ( urls [ url ] !== undefined ) {
data = fs . readFileSync ( path . join ( _ _dirname , '__data__' , urls [ url ] ) ) . toString ( )
}
return Promise . resolve ( { data } )
} )
it ( 'can generate valid url' , ( ) => {
2026-04-30 09:45:38 +07:00
expect ( url ( { channel , date } ) ) . toBe ( 'https://tivie.id/channel/axn/20260429' )
2025-09-28 17:55:05 +03:00
} )
it ( 'can parse response' , async ( ) => {
const content = fs . readFileSync ( path . join ( _ _dirname , '__data__' , 'content.html' ) )
const results = ( await parser ( { date , content , channel } ) ) . map ( p => {
p . start = p . start . toJSON ( )
p . stop = p . stop . toJSON ( )
return p
} )
2026-04-30 09:45:38 +07:00
expect ( results . length ) . toBe ( 28 )
2025-09-28 17:55:05 +03:00
expect ( results [ 0 ] ) . toMatchObject ( {
2026-04-30 09:45:38 +07:00
start : '2026-04-28T17:00:00.000Z' ,
stop : '2026-04-28T17:25:00.000Z' ,
title : 'The Hunting Party S1, Ep. 3' ,
2025-09-28 17:55:05 +03:00
description :
2026-04-30 09:45:38 +07:00
'Di pedalaman Montana, tim memburu seorang pembunuh berantai nan kejam bernama Lowe yang terobsesi dengan kawanan serigala.' ,
2025-09-28 17:55:05 +03:00
image :
2026-04-30 09:45:38 +07:00
'https://i0.wp.com/is3.cloudhost.id/tivie/poster/2025/10/68e9d54962c8f-1760154953.jpg?resize=480,270' ,
categories : [ 'Serial' ] ,
season : 1 ,
episode : 3
2025-09-28 17:55:05 +03:00
} )
expect ( results [ 2 ] ) . toMatchObject ( {
2026-04-30 09:45:38 +07:00
start : '2026-04-28T18:20:00.000Z' ,
stop : '2026-04-28T19:15:00.000Z' ,
title : 'The Rookie S7, Ep. 6' ,
2025-09-28 17:55:05 +03:00
description :
2026-04-30 09:45:38 +07:00
'Grey memberi Tim dan Lucy suatu tugas yang tak menyenangkan, sementara John dan Celina melacak keberadaan seorang gadis yang menghilang. Beberapa hubungan asmara berakhir di suatu acara amal.' ,
2025-09-28 17:55:05 +03:00
image :
2026-04-30 09:45:38 +07:00
'https://i0.wp.com/is3.cloudhost.id/tivie/poster/2025/01/677a9f2fb4b5f-1736089391.jpg?resize=480,270' ,
categories : [ 'Serial' ] ,
season : 7 ,
episode : 6
2025-09-28 17:55:05 +03:00
} )
} )
it ( 'can handle empty guide' , async ( ) => {
const results = await parser ( {
date ,
channel ,
content : ''
} )
expect ( results ) . toMatchObject ( [ ] )
} )