2026-04-19 07:25:42 +03:00
const { parser , url , request } = require ( './tvplus.com.tr.config.js' )
2025-09-28 17:55:05 +03:00
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-19 07:25:42 +03:00
const date = dayjs . utc ( '2026-04-22' , 'YYYY-MM-DD' ) . startOf ( 'd' )
const channel = { site _id : '32' }
2025-09-28 17:55:05 +03:00
2026-04-20 03:46:43 +03:00
axios . post . mockImplementation ( url => {
if ( url === 'https://izmaottvsc14.tvplus.com.tr:33207/EPG/JSON/Authenticate' ) {
2025-09-28 17:55:05 +03:00
return Promise . resolve ( {
2026-04-20 03:46:43 +03:00
headers : {
'set-cookie' : [
'XSESSIONID=05DIPYMD4BHOKRQCZTHF8F5GHMMBCNJ6; Domain=izmaottvsc14.tvplus.com.tr; Path=/; Secure; HttpOnly' ,
'JSESSIONID=05DIPYMD4BHOKRQCZTHF8F5GHMMBCNJ6; Domain=izmaottvsc14.tvplus.com.tr; Path=/; HttpOnly'
]
}
2025-09-28 17:55:05 +03:00
} )
}
} )
2026-04-20 03:46:43 +03:00
it ( 'can generate valid url' , ( ) => {
2026-04-19 07:25:42 +03:00
expect ( url ) . toBe ( 'https://izmaottvsc14.tvplus.com.tr:33207/EPG/JSON/PlayBillList' )
} )
2026-04-20 03:46:43 +03:00
it ( 'can generate valid request method' , ( ) => {
2026-04-19 07:25:42 +03:00
expect ( request . method ) . toBe ( 'POST' )
} )
it ( 'can generate valid request headers' , async ( ) => {
2026-04-20 03:46:43 +03:00
const headers = await request . headers ( )
expect ( headers ) . toMatchObject ( {
cookie :
'XSESSIONID=05DIPYMD4BHOKRQCZTHF8F5GHMMBCNJ6; Domain=izmaottvsc14.tvplus.com.tr; Path=/; Secure; HttpOnly;JSESSIONID=05DIPYMD4BHOKRQCZTHF8F5GHMMBCNJ6; Domain=izmaottvsc14.tvplus.com.tr; Path=/; HttpOnly'
2026-04-19 07:25:42 +03:00
} )
} )
2026-04-20 03:46:43 +03:00
it ( 'can generate valid request data' , ( ) => {
2026-04-19 07:25:42 +03:00
expect ( request . data ( { channel , date } ) ) . toMatchObject ( {
type : '2' ,
channelid : '32' ,
begintime : '20260422000000' ,
endtime : '20260423000000' ,
isFillProgram : 1
} )
2025-09-28 17:55:05 +03:00
} )
it ( 'can parse response' , ( ) => {
const content = fs . readFileSync ( path . join ( _ _dirname , '__data__' , 'content.json' ) )
2026-04-19 07:25:42 +03:00
const results = parser ( { content } ) . map ( p => {
2025-09-28 17:55:05 +03:00
p . start = p . start . toJSON ( )
p . stop = p . stop . toJSON ( )
return p
} )
2026-04-19 07:25:42 +03:00
expect ( results . length ) . toBe ( 18 )
2025-09-28 17:55:05 +03:00
expect ( results [ 0 ] ) . toMatchObject ( {
2026-04-19 07:25:42 +03:00
start : '2026-04-21T23:30:00.000Z' ,
stop : '2026-04-22T01:15:00.000Z' ,
title : 'Bu Ülke' ,
2025-09-28 17:55:05 +03:00
description :
2026-04-19 07:25:42 +03:00
"Türkiye'nin gündemindeki merak edilen ve tartı şı lan sorular, siyaset, ekonomi, toplumsal meseleler ve kültür-eğitim başlı kları yla ele alı nı yor. Uzman konuklar ve sahadan aktarı lan bilgilerle olayları n arka planı izleyiciye aktarı lı yor." ,
icon : 'https://izmaottvsc14.tvplus.com.tr:33207/CPS/images/universal/film/program/202604/20260414/0/0005330799055eb7f426.jpg' ,
2025-09-28 17:55:05 +03:00
image :
2026-04-19 07:25:42 +03:00
'https://izmaottvsc14.tvplus.com.tr:33207/CPS/images/universal/film/program/202604/20260414/10/0005330799045eb7f426.jpg' ,
category : 'Haber'
2025-09-28 17:55:05 +03:00
} )
2026-04-19 07:25:42 +03:00
expect ( results [ 17 ] ) . toMatchObject ( {
start : '2026-04-22T23:00:00.000Z' ,
stop : '2026-04-23T01:15:00.000Z' ,
title : 'Açı k Görüş' ,
2025-09-28 17:55:05 +03:00
description :
2026-04-19 07:25:42 +03:00
'Açı k Görüş, farklı alanlardan uzman konukları ağı rlayarak, güncel politika, ekonomi, kültür ve toplumsal meseleleri kapsamlı bir şekilde ele alan bilgilendirici bir programdı r. Tartı şmalar, izleyicilere olayları çok yönlü değerlendirme imkânı sunar.' ,
icon : 'https://izmaottvsc14.tvplus.com.tr:33207/CPS/images/universal/film/program/202604/20260418/58/0905279525125eb9b42e.jpg' ,
2025-09-28 17:55:05 +03:00
image :
2026-04-19 07:25:42 +03:00
'https://izmaottvsc14.tvplus.com.tr:33207/CPS/images/universal/film/program/202604/20260418/44/0905279525115eb9b42e.jpg' ,
category : 'Magazin'
2025-09-28 17:55:05 +03:00
} )
} )
it ( 'can handle empty guide' , ( ) => {
const result = parser ( {
date ,
channel ,
content : ''
} )
expect ( result ) . toMatchObject ( [ ] )
} )