Update tvtv.us.test.js

This commit is contained in:
freearhey 2025-01-27 04:50:07 +03:00
parent cb10f7a162
commit c0d4c631f8

View file

@ -1,52 +1,48 @@
const { parser, url } = require('./tvtv.us.config.js') const { parser, url } = require('./tvtv.us.config.js')
const fs = require('fs')
const path = require('path')
const dayjs = require('dayjs') const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc') const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat') const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat) dayjs.extend(customParseFormat)
dayjs.extend(utc) dayjs.extend(utc)
const date = dayjs.utc('2022-09-20', 'YYYY-MM-DD').startOf('d') const date = dayjs.utc('2025-01-30', 'YYYY-MM-DD').startOf('d')
const channel = { const channel = { site_id: '20373' }
site_id: '62670',
xmltv_id: 'AMITV.ca',
logo: 'https://tvtv.us/gn/i/assets/s62670_ll_h15_ab.png?w=360&h=270'
}
it('can generate valid url', () => { it('can generate valid url', () => {
expect(url({ channel, date })).toBe( expect(url({ channel, date })).toBe(
'https://www.tvtv.us/api/v1/lineup/USA-NY71652-X/grid/2022-09-20T00:00:00.000Z/2022-09-21T00:00:00.000Z/62670' 'https://www.tvtv.us/api/v1/lineup/USA-NY71652-X/grid/2025-01-30T00:00:00.000Z/2025-01-31T00:00:00.000Z/20373'
) )
}) })
it('can parse response', () => { it('can parse response', () => {
const content = const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
'[[{"programId":"EP039131940001","title":"Beyond the Field","subtitle":"Diversity in Sport","flags":["CC","DVS"],"type":"O","startTime":"2022-09-20T00:00Z","start":0,"duration":30,"runTime":30},{"programId":"EP032368970002","title":"IGotThis","subtitle":"Listen to Dis","flags":["CC","DVS"],"type":"O","startTime":"2022-09-20T00:30Z","start":120,"duration":30,"runTime":30}]]'
const result = parser({ content }).map(p => { const results = parser({ content }).map(p => {
p.start = p.start.toJSON() p.start = p.start.toJSON()
p.stop = p.stop.toJSON() p.stop = p.stop.toJSON()
return p return p
}) })
expect(result).toMatchObject([ expect(results.length).toBe(33)
{ expect(results[0]).toMatchObject({
start: '2022-09-20T00:00:00.000Z', start: '2025-01-30T00:00:00.000Z',
stop: '2022-09-20T00:30:00.000Z', stop: '2025-01-30T00:30:00.000Z',
title: 'Beyond the Field', title: 'NY Sports Nation Nightly',
description: 'Diversity in Sport' subtitle: null
}, })
{ expect(results[1]).toMatchObject({
start: '2022-09-20T00:30:00.000Z', start: '2025-01-30T00:30:00.000Z',
stop: '2022-09-20T01:00:00.000Z', stop: '2025-01-30T01:00:00.000Z',
title: 'IGotThis', title: 'The Big Bang Theory',
description: 'Listen to Dis' subtitle: 'The Bow Tie Asymmetry'
} })
])
}) })
it('can handle empty guide', () => { it('can handle empty guide', () => {
const result = parser({ const results = parser({
content: '[]' content: '[]'
}) })
expect(result).toMatchObject([]) expect(results).toMatchObject([])
}) })