Files
epg/sites/plex.tv/plex.tv.test.js
StrangeDrVN 61a9346568 date fix?
2026-02-15 14:06:15 +05:30

92 lines
2.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const { parser, url, request } = require('./plex.tv.config.js')
const fs = require('fs')
const path = require('path')
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')
const date = dayjs.utc('2023-02-05', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '5eea605674085f0040ddc7a6',
xmltv_id: 'Heartland.ca'
}
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
'https://epg.provider.plex.tv/grid?channelGridKey=5eea605674085f0040ddc7a6&date=2023-02-05'
)
})
it('can generate valid request headers', () => {
expect(request.headers).toMatchObject({
'x-plex-provider-version': '7.2' // Updated to match config.js
})
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
let results = parser({ content })
results = results.map(p => {
if (p.start) p.start = p.start.toJSON()
if (p.stop) p.stop = p.stop.toJSON()
return p
})
// Testing first item: "Cowgirls Dont Cry"
expect(results[0]).toMatchObject({
title: 'Heartland',
subTitle: 'Cowgirls Dont Cry',
description: expect.stringContaining('Tim ouvre une école de rodéo'),
rating: 'TV-PG',
season: 8,
episode: 13,
date: '2015-02-15T00:00:00Z'
})
// Testing another item: "Riders on the Storm"
expect(results[1]).toMatchObject({
title: 'Heartland',
subTitle: 'Riders on the Storm',
description: expect.stringContaining('Amy et Ty aident le neveu de Scott'),
season: 8,
episode: 14,
image: expect.stringContaining('Heartland_landscape.jpg')
})
})
it('can handle empty guide', () => {
const content = JSON.stringify({ MediaContainer: { Metadata: [] } })
const results = parser({ content })
expect(results).toMatchObject([])
})
it('can parse channel list', async () => {
const axios = require('axios')
axios.get.mockResolvedValue({
data: {
MediaContainer: {
Channel: [
{
title: 'Heartland TV',
gridKey: 'heartland-key',
id: '12345'
}
]
}
}
})
const { channels } = require('./plex.tv.config.js')
const results = await channels({ token: 'TEST_TOKEN' })
expect(results[0]).toMatchObject({
lang: 'en',
site_id: 'heartland-key',
name: 'Heartland TV'
})
})