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 = {
|
2026-01-15 13:24:50 +05:30
|
|
|
|
site_id: '5eea605674085f0040ddc7a6',
|
2026-02-15 13:57:45 +05:30
|
|
|
|
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({
|
2026-02-15 13:57:45 +05:30
|
|
|
|
'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
|
|
|
|
|
|
})
|
|
|
|
|
|
|
2026-02-15 13:57:45 +05:30
|
|
|
|
// Testing first item: "Cowgirls Don’t Cry"
|
2025-09-28 17:55:05 +03:00
|
|
|
|
expect(results[0]).toMatchObject({
|
2026-02-15 13:57:45 +05:30
|
|
|
|
title: 'Heartland',
|
|
|
|
|
|
subTitle: 'Cowgirls Don’t 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
|
|
|
|
})
|
|
|
|
|
|
|
2026-02-15 13:57:45 +05:30
|
|
|
|
// Testing another item: "Riders on the Storm"
|
2026-01-15 17:53:47 +05:30
|
|
|
|
expect(results[1]).toMatchObject({
|
2026-02-15 13:57:45 +05:30
|
|
|
|
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', () => {
|
2026-02-15 13:57:45 +05:30
|
|
|
|
const content = JSON.stringify({ MediaContainer: { Metadata: [] } })
|
2025-09-28 17:55:05 +03:00
|
|
|
|
const results = parser({ content })
|
|
|
|
|
|
|
|
|
|
|
|
expect(results).toMatchObject([])
|
|
|
|
|
|
})
|
2026-01-15 13:24:50 +05:30
|
|
|
|
|
|
|
|
|
|
it('can parse channel list', async () => {
|
|
|
|
|
|
const axios = require('axios')
|
|
|
|
|
|
axios.get.mockResolvedValue({
|
|
|
|
|
|
data: {
|
|
|
|
|
|
MediaContainer: {
|
|
|
|
|
|
Channel: [
|
|
|
|
|
|
{
|
2026-02-15 13:57:45 +05:30
|
|
|
|
title: 'Heartland TV',
|
|
|
|
|
|
gridKey: 'heartland-key',
|
|
|
|
|
|
id: '12345'
|
2026-01-15 13:24:50 +05:30
|
|
|
|
}
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
const { channels } = require('./plex.tv.config.js')
|
|
|
|
|
|
const results = await channels({ token: 'TEST_TOKEN' })
|
|
|
|
|
|
|
|
|
|
|
|
expect(results[0]).toMatchObject({
|
|
|
|
|
|
lang: 'en',
|
2026-02-15 13:57:45 +05:30
|
|
|
|
site_id: 'heartland-key',
|
|
|
|
|
|
name: 'Heartland TV'
|
2026-01-15 13:24:50 +05:30
|
|
|
|
})
|
|
|
|
|
|
})
|