Files
epg/sites/movistarplus.es/movistarplus.es.test.js

81 lines
2.2 KiB
JavaScript
Raw Normal View History

2023-10-15 14:08:23 +03:00
const { parser, url } = require('./movistarplus.es.config.js')
2025-01-21 00:21:36 +03:00
const fs = require('fs')
const path = require('path')
2023-10-15 14:08:23 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
2025-05-30 13:44:34 -04:00
const axios = require('axios')
jest.mock('axios')
2023-10-15 14:08:23 +03:00
2025-05-30 13:44:34 -04:00
const date = dayjs.utc('2025-05-30', 'YYYY-MM-DD').startOf('d')
2023-10-15 14:08:23 +03:00
const channel = {
2025-01-21 00:21:36 +03:00
site_id: 'sexta',
xmltv_id: 'LaSexta.es'
2023-10-15 14:08:23 +03:00
}
it('can generate valid url', () => {
2025-01-21 00:21:36 +03:00
expect(url({ channel, date })).toBe(
2025-05-30 13:44:34 -04:00
'https://www.movistarplus.es/programacion-tv/sexta/2025-05-30'
2025-01-21 00:21:36 +03:00
)
2023-10-15 14:08:23 +03:00
})
2025-05-30 13:44:34 -04:00
it('can parse response', async () => {
2025-01-21 00:21:36 +03:00
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
2025-05-30 13:44:34 -04:00
axios.get.mockImplementation(url => {
if (
url ===
'https://www.movistarplus.es/entretenimiento/venta-prime-t1/ficha?tipo=E&id=3414523'
) {
return Promise.resolve({
data: fs.readFileSync(path.resolve(__dirname, '__data__/program1.html'))
})
} else if (
url ===
'https://www.movistarplus.es/deportes/programa/pokerstars-casino-1/ficha?tipo=E&id=2057641'
) {
return Promise.resolve({
data: fs.readFileSync(path.resolve(__dirname, '__data__/program2.html'))
})
} else {
return Promise.resolve({ data: '' })
}
})
let results = await parser({ content, date })
results = results.map(p => {
2023-10-15 14:08:23 +03:00
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
2025-01-21 00:21:36 +03:00
2025-05-30 13:44:34 -04:00
expect(results.length).toBe(23)
2025-01-21 00:21:36 +03:00
expect(results[0]).toMatchObject({
2025-05-30 13:44:34 -04:00
start: '2025-05-30T03:15:00.000Z',
stop: '2025-05-30T04:25:00.000Z',
title: 'Venta Prime',
description:
'Espacio de televenta.'
2025-01-21 00:21:36 +03:00
})
expect(results[19]).toMatchObject({
2025-05-30 13:44:34 -04:00
start: '2025-05-31T00:45:00.000Z',
stop: '2025-05-31T01:25:00.000Z',
title: 'Pokerstars casino',
description:
'El programa trae cada día toda la emoción de su ruleta en vivo, Spin & Win, una versión exclusiva del clásico juego de casino.'
2025-01-21 00:21:36 +03:00
})
2023-10-15 14:08:23 +03:00
})
2025-05-30 13:44:34 -04:00
it('can handle empty guide', async () => {
const results = await parser({
2023-10-15 14:08:23 +03:00
date,
2025-05-30 13:44:34 -04:00
channel,
content: '[]'
2023-10-15 14:08:23 +03:00
})
2025-05-30 13:44:34 -04:00
expect(results).toMatchObject([])
2023-10-15 14:08:23 +03:00
})