2025-09-28 17:55:05 +03:00
const { parser , url } = require ( './directv.com.config.js' )
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-06 23:20:33 +02:00
// Mock token fetching
axios . post . mockImplementation ( ( url ) => {
if ( url === 'https://api.cld.dtvce.com/authn-tokengo/v3/v2/tokens?client_id=DTVE_DFW_WEB_Chrome_G' ) {
return Promise . resolve ( { data : '/S2dAVfUtUdnt6adfOBn+QrLZ2GymKSfxIGgfI/tRrOCf22bhs7aLmwmeKTUp0br3aHU2M/Rtv5Y43Kl9unTtNau8w48K3dNjVVH2gyrgvGvUxfVa8rXXuv9RBesXSric6ltlS4yDIjRtuOpmiU5Imt8O1zHWjA9K3/8M84oRQywb0HpE4tkTT3RBG5Cmz+wX5If6Hbb3ndFacEhUjpvCI0mAqPlI2r7x7/73quuoByp0+updUmyjWF+5SVkUBx5.ycdisTLMPpwxjYERYDmA7zm7Pq2ukk5KJk8duRW8lMg=' } )
}
} )
const date = dayjs . utc ( '2026-06-04' , 'YYYY-MM-DD' ) . startOf ( 'd' )
2025-09-28 17:55:05 +03:00
const channel = {
2026-04-06 23:20:33 +02:00
site _id : '5070bc2e-dd69-4dee-98b4-a4c5e3b1fd7b' ,
2025-09-28 17:55:05 +03:00
xmltv _id : 'ComedyCentralEast.us'
}
it ( 'can generate valid url' , ( ) => {
const result = url ( { date , channel } )
expect ( result ) . toBe (
2026-04-06 23:20:33 +02:00
` https://api.cld.dtvce.com/discovery/edge/schedule/v1/service/schedule?startTime= ${ date . valueOf ( ) } &endTime= ${ date . add ( 24 , 'hour' ) . valueOf ( ) } &channelIds=5070bc2e-dd69-4dee-98b4-a4c5e3b1fd7b&include4K=false&is4Kcompatible=false&includeTVOD=true `
2025-09-28 17:55:05 +03:00
)
} )
it ( 'can parse response' , done => {
const content = fs . readFileSync ( path . resolve ( _ _dirname , '__data__/content.json' ) )
parser ( { content , channel } )
. then ( result => {
result = result . map ( p => {
p . start = p . start . toJSON ( )
p . stop = p . stop . toJSON ( )
return p
} )
2026-04-06 23:20:33 +02:00
expect ( result ) . toHaveLength ( 47 )
expect ( result [ 0 ] ) . toMatchObject ( {
start : '2026-04-06T00:00:00.000Z' ,
stop : '2026-04-06T00:30:00.000Z' ,
title : 'Seinfeld' ,
sub _title : 'The Nap' ,
description : 'George finds the ideal napping spot at work; Jerry has his kitchen rebuilt; Elaine meets a new beau (Vince Grant).' ,
date : '1997-04-10' ,
season : 8 ,
episode : 18 ,
category : [ 'Sitcom' ] ,
2025-09-28 17:55:05 +03:00
rating : {
system : 'MPA' ,
2026-04-06 23:20:33 +02:00
value : 'TVPG'
2025-09-28 17:55:05 +03:00
}
2026-04-06 23:20:33 +02:00
} )
expect ( result [ 46 ] ) . toMatchObject ( {
start : '2026-04-06T23:35:00.000Z' ,
stop : '2026-04-07T00:10:00.000Z' ,
title : 'The Office' ,
sub _title : 'The Convention' ,
description : 'Michael organizes a party in his hotel room when he, Dwight and Jan attend the Northeastern Mid-Market Office Supply Convention in Philadelphia.' ,
category : [ 'Comedy' , 'Sitcom' ] ,
season : 3 ,
episode : 2 ,
2025-09-28 17:55:05 +03:00
rating : {
system : 'MPA' ,
2026-04-06 23:20:33 +02:00
value : 'TV14'
2025-09-28 17:55:05 +03:00
}
2026-04-06 23:20:33 +02:00
} )
2025-09-28 17:55:05 +03:00
done ( )
} )
. catch ( done )
} )
it ( 'can handle empty guide' , done => {
const content = fs . readFileSync ( path . resolve ( _ _dirname , '__data__/no-content.json' ) )
parser ( { content , channel } )
. then ( result => {
expect ( result ) . toMatchObject ( [ ] )
done ( )
} )
. catch ( done )
} )