Files
epg/sites/plex.tv/plex.tv.test.js
StrangeDrVN 1be21bcf90 updated plex.tv
changed site_id logic
fixed site_id in *.channels.xml
added test for channels list
added logo and url to channels function
2026-01-15 13:24:50 +05:30

94 lines
3.0 KiB
JavaScript

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: 'DarkMatterTV.us'
}
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': '5.1'
})
})
it('can parse response', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
let results = parser({ content })
results = results.map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
// expect(results.length).toBe(15)
expect(results[0]).toMatchObject({
start: '2023-02-04T23:31:14.000Z',
stop: '2023-02-05T01:10:45.000Z',
title: 'Violet & Daisy',
description:
'Two teenage assassins accept what they think will be a quick-and-easy job, until an unexpected target throws them off their plan.',
image: 'https://provider-static.plex.tv/epg/images/ott_channels/arts/darkmatter-tv-about.jpg',
categories: ['Movies']
})
})
it('can handle empty guide', () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.json'))
const results = parser({ content })
expect(results).toMatchObject([])
})
it('can parse channel list', async () => {
const axios = require('axios')
axios.get.mockResolvedValue({
data: {
MediaContainer: {
Channel: [
{
title: 'The World Poker Tour',
gridKey: '5f6b8e7900b0950040d0f2b2',
id: '5e20b730f2f8d5003d739db7-5f6b8e7900b0950040d0f2b2',
thumb: 'https://provider-static.plex.tv/epg/cms/production/c40e4f88-6f5c-4f2a-8d54-e6812e25771c/wpt_logo.png',
Media: [
{
Part: [
{
key: '/library/parts/5e20b730f2f8d5003d739db7-5f6b8e7900b0950040d0f2b2.m3u8'
}
]
}
]
}
]
}
}
})
const { channels } = require('./plex.tv.config.js')
const results = await channels({ token: 'TEST_TOKEN' })
expect(results[0]).toMatchObject({
lang: 'en',
site_id: '5f6b8e7900b0950040d0f2b2',
name: 'The World Poker Tour',
// logo: 'https://provider-static.plex.tv/epg/cms/production/c40e4f88-6f5c-4f2a-8d54-e6812e25771c/wpt_logo.png',
// url: 'https://epg.provider.plex.tv/library/parts/5e20b730f2f8d5003d739db7-5f6b8e7900b0950040d0f2b2.m3u8?X-Plex-Token=TEST_TOKEN'
})
})