Files
epg/sites/rts.ch/rts.ch.test.js

79 lines
2.6 KiB
JavaScript
Raw Normal View History

2026-03-20 22:57:38 +01:00
const { parser, url } = require('./rts.ch.config.js')
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
const customParseFormat = require('dayjs/plugin/customParseFormat')
dayjs.extend(customParseFormat)
dayjs.extend(utc)
2026-03-21 09:10:12 +01:00
const date = dayjs.utc('2026-03-21', 'YYYY-MM-DD').startOf('d')
const channel = { site_id: '5d332a26e06d08eec8ad385d566187df72955623', name: 'RTS Info', lang: 'fr' }
2026-03-20 22:57:38 +01:00
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
2026-03-21 09:10:12 +01:00
'https://il.srgssr.ch/integrationlayer/2.0/rts/programGuide/tv/byDate/2026-03-21?reduced=false&channelId=5d332a26e06d08eec8ad385d566187df72955623'
2026-03-20 22:57:38 +01:00
)
})
it('can parse response', () => {
const content = JSON.stringify({
2026-03-21 09:10:12 +01:00
programGuide: [
2026-03-20 22:57:38 +01:00
{
2026-03-21 09:10:12 +01:00
channel: { id: '5d332a26e06d08eec8ad385d566187df72955623', title: 'RTS Info' },
2026-03-20 22:57:38 +01:00
programList: [
{
2026-03-21 09:10:12 +01:00
title: "L'essentiel de l'actualité",
startTime: '2026-03-21T07:00:00+01:00',
endTime: '2026-03-21T19:00:00+01:00',
imageUrl: 'https://kingfisher.rts.ch/res/img/cdns3/sherlock/urn:orphea-image:1043433',
2026-03-20 22:57:38 +01:00
genre: 'Actualité',
},
{
2026-03-21 09:10:12 +01:00
title: 'Forum',
startTime: '2026-03-21T19:00:00+01:00',
endTime: '2026-03-21T20:00:00+01:00',
imageUrl: 'https://kingfisher.rts.ch/res/img/cdns3/sherlock/urn:orphea-image:1831387',
2026-03-20 22:57:38 +01:00
genre: 'Actualité',
2026-03-21 09:10:12 +01:00
description: 'Le magazine du soir.',
2026-03-20 22:57:38 +01:00
},
],
},
],
})
2026-03-21 09:10:12 +01:00
const results = parser({ content })
2026-03-20 22:57:38 +01:00
expect(results[0]).toMatchObject({
2026-03-21 09:10:12 +01:00
title: "L'essentiel de l'actualité",
start: '2026-03-21T06:00:00.000Z',
stop: '2026-03-21T18:00:00.000Z',
2026-03-20 22:57:38 +01:00
category: 'Actualité',
2026-03-21 09:10:12 +01:00
icon: { src: 'https://kingfisher.rts.ch/res/img/cdns3/sherlock/urn:orphea-image:1043433' },
2026-03-20 22:57:38 +01:00
})
expect(results[1]).toMatchObject({
2026-03-21 09:10:12 +01:00
title: 'Forum',
start: '2026-03-21T18:00:00.000Z',
stop: '2026-03-21T19:00:00.000Z',
description: 'Le magazine du soir.',
2026-03-20 22:57:38 +01:00
})
})
2026-03-21 09:10:12 +01:00
it('can handle empty programList', () => {
2026-03-20 22:57:38 +01:00
const content = JSON.stringify({
2026-03-21 09:10:12 +01:00
programGuide: [
{ channel: { id: '5d332a26e06d08eec8ad385d566187df72955623', title: 'RTS Info' }, programList: [] },
2026-03-20 22:57:38 +01:00
],
})
2026-03-21 09:10:12 +01:00
const results = parser({ content })
2026-03-20 22:57:38 +01:00
expect(results).toMatchObject([])
})
it('can handle empty guide', () => {
2026-03-21 09:10:12 +01:00
const results = parser({ content: '' })
2026-03-20 22:57:38 +01:00
expect(results).toMatchObject([])
})
it('can handle malformed JSON', () => {
2026-03-21 09:10:12 +01:00
const results = parser({ content: 'not-json' })
2026-03-20 22:57:38 +01:00
expect(results).toMatchObject([])
})