Files
epg/sites/plex.tv/plex.tv.test.js

92 lines
2.5 KiB
JavaScript
Raw Normal View History

2025-09-28 17:55:05 +03:00
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'
2025-09-28 17:55:05 +03:00
}
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
2025-09-28 17:55:05 +03:00
})
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
let results = parser({ content })
results = results.map(p => {
2026-01-15 17:53:47 +05:30
if (p.start) p.start = p.start.toJSON()
if (p.stop) p.stop = p.stop.toJSON()
2025-09-28 17:55:05 +03:00
return p
})
// Testing first item: "Cowgirls Dont Cry"
2025-09-28 17:55:05 +03:00
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,
2026-02-15 14:06:15 +05:30
date: '2015-02-15T00:00:00Z'
2026-01-15 17:53:47 +05:30
})
// Testing another item: "Riders on the Storm"
2026-01-15 17:53:47 +05:30
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')
2025-09-28 17:55:05 +03:00
})
})
it('can handle empty guide', () => {
const content = JSON.stringify({ MediaContainer: { Metadata: [] } })
2025-09-28 17:55:05 +03:00
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'
})
})