epg-grabber/tests/Program.test.js

217 lines
5.3 KiB
JavaScript
Raw Normal View History

2022-06-16 14:07:56 +02:00
import Channel from '../src/Channel'
import Program from '../src/Program'
2022-07-01 01:45:59 +02:00
const channel = new Channel({ xmltv_id: '1tv', lang: 'fr', site: 'example.com' })
2022-06-16 14:07:56 +02:00
it('can create new Program', () => {
2022-07-01 01:45:59 +02:00
const program = new Program(
{
title: 'Title',
sub_title: 'Subtitle',
description: 'Description',
icon: 'https://example.com/image.jpg',
season: 9,
episode: 238,
date: '20220506',
start: 1616133600000,
stop: '2021-03-19T06:30:00.000Z',
url: 'http://example.com/title.html',
category: ['Category1', 'Category2'],
rating: {
system: 'MPAA',
value: 'PG',
icon: 'http://example.com/pg_symbol.png'
},
directors: 'Director1',
actors: [
'Actor1',
{ value: 'Actor2', url: 'http://actor2.com', image: 'http://actor2.com/image.png' }
],
writer: {
value: 'Writer1',
url: { system: 'imdb', value: 'http://imdb.com/p/writer1' },
image: {
value: 'https://example.com/image.jpg',
type: 'person',
size: '2',
system: 'TestSystem',
orient: 'P'
}
},
adapters: [
{
value: 'Adapter1',
url: ['http://imdb.com/p/adapter1', 'http://imdb.com/p/adapter2'],
image: ['https://example.com/image1.jpg', 'https://example.com/image2.jpg']
}
]
2022-06-16 14:07:56 +02:00
},
2022-07-01 01:45:59 +02:00
channel
)
2022-06-16 14:07:56 +02:00
expect(program).toMatchObject({
2022-06-16 20:38:26 +02:00
site: 'example.com',
2022-06-16 14:07:56 +02:00
channel: '1tv',
2022-07-01 01:45:59 +02:00
titles: [{ value: 'Title', lang: 'fr' }],
sub_titles: [{ value: 'Subtitle', lang: 'fr' }],
descriptions: [{ value: 'Description', lang: 'fr' }],
2022-06-16 14:07:56 +02:00
urls: [{ system: '', value: 'http://example.com/title.html' }],
2022-07-01 01:45:59 +02:00
categories: [
{ value: 'Category1', lang: 'fr' },
{ value: 'Category2', lang: 'fr' }
],
2022-06-16 14:07:56 +02:00
icon: { src: 'https://example.com/image.jpg' },
episodeNumbers: [
{ system: 'xmltv_ns', value: '8.237.0/1' },
{ system: 'onscreen', value: 'S09E238' }
],
date: 1651795200000,
start: 1616133600000,
stop: 1616135400000,
ratings: [
{
system: 'MPAA',
value: 'PG',
icon: 'http://example.com/pg_symbol.png'
}
],
directors: [{ value: 'Director1', url: [], image: [] }],
actors: [
{ value: 'Actor1', url: [], image: [] },
{
value: 'Actor2',
url: [{ system: '', value: 'http://actor2.com' }],
image: [
{ type: '', size: '', orient: '', system: '', value: 'http://actor2.com/image.png' }
]
}
],
writers: [
{
value: 'Writer1',
url: [{ system: 'imdb', value: 'http://imdb.com/p/writer1' }],
image: [
{
value: 'https://example.com/image.jpg',
type: 'person',
size: '2',
system: 'TestSystem',
orient: 'P'
}
]
}
],
adapters: [
{
value: 'Adapter1',
url: [
{ system: '', value: 'http://imdb.com/p/adapter1' },
{ system: '', value: 'http://imdb.com/p/adapter2' }
],
image: [
{
value: 'https://example.com/image1.jpg',
type: '',
size: '',
system: '',
orient: ''
},
{
value: 'https://example.com/image2.jpg',
type: '',
size: '',
system: '',
orient: ''
}
]
}
],
producers: [],
composers: [],
editors: [],
presenters: [],
commentators: [],
guests: []
})
})
2022-06-16 18:11:11 +02:00
it('can create program from exist object', () => {
2022-07-01 01:45:59 +02:00
const program = new Program(
{
titles: [{ value: 'Program 1', lang: 'de' }],
start: '2021-03-19T06:00:00.000Z',
stop: '2021-03-19T06:30:00.000Z',
ratings: {
system: 'MPAA',
value: 'PG',
icon: 'http://example.com/pg_symbol.png'
},
actors: [{ value: 'Actor1', url: [], image: [] }]
2022-06-16 14:07:56 +02:00
},
2022-07-01 01:45:59 +02:00
channel
)
2022-06-16 18:11:11 +02:00
expect(program).toMatchObject({
channel: '1tv',
2022-07-01 01:45:59 +02:00
titles: [{ value: 'Program 1', lang: 'de' }],
sub_titles: [],
descriptions: [],
2022-06-16 18:11:11 +02:00
urls: [],
categories: [],
icon: {},
episodeNumbers: [],
date: null,
start: 1616133600000,
stop: 1616135400000,
ratings: [
{
system: 'MPAA',
value: 'PG',
icon: 'http://example.com/pg_symbol.png'
}
],
directors: [],
actors: [{ value: 'Actor1', url: [], image: [] }],
writers: [],
adapters: [],
producers: [],
composers: [],
editors: [],
presenters: [],
commentators: [],
guests: []
})
})
it('can create program without season number', () => {
2022-07-01 01:45:59 +02:00
const program = new Program(
{
title: 'Program 1',
start: '2021-03-19T06:00:00.000Z',
stop: '2021-03-19T06:30:00.000Z',
episode: 238
},
channel
)
2022-06-16 14:07:56 +02:00
expect(program.episodeNumbers).toMatchObject([
{ system: 'xmltv_ns', value: '0.237.0/1' },
{ system: 'onscreen', value: 'S01E238' }
])
})
it('can create program without episode number', () => {
2022-07-01 01:45:59 +02:00
const program = new Program(
{
channel: channel.id,
title: 'Program 1',
start: '2021-03-19T06:00:00.000Z',
stop: '2021-03-19T06:30:00.000Z',
season: 3
},
channel
)
2022-06-16 14:07:56 +02:00
expect(program.episodeNumbers).toMatchObject([])
})