import fs from 'fs' import xmltv from '../src/xmltv' jest.useFakeTimers('modern').setSystemTime(new Date('2022-05-05')) const channels = [ { xmltv_id: '1TV.com', name: '1 TV', logo: 'https://example.com/logos/1TV.png', site: 'example.com' }, { xmltv_id: '2TV.com', name: '2 TV', site: 'example.com' } ] fit('can generate xmltv', () => { const programs = [ { title: 'Program 1', sub_title: 'Sub-title & 1', description: 'Description for Program 1', url: 'http://example.com/title.html', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', category: 'Test', season: 9, episode: 239, icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777', channel: '1TV.com', lang: 'it', rating: { system: 'MPAA', value: 'PG', icon: 'http://example.com/pg_symbol.png' }, director: [ { value: 'Director 1', url: { value: 'http://example.com/director1.html', system: 'TestSystem' }, image: [ 'https://example.com/image1.jpg', { value: 'https://example.com/image2.jpg', type: 'person', size: '2', system: 'TestSystem', orient: 'P' } ] }, 'Director 2' ], actor: ['Actor 1', 'Actor 2'], writer: 'Writer 1' } ] const output = xmltv.generate({ channels, programs }) const expected = fs.readFileSync('./tests/expected/guide.xml', { encoding: 'utf-8' }) expect(output).toBe(expected) }) it('can generate xmltv without season number', () => { const programs = [ { title: 'Program 1', description: 'Description for Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', category: 'Test', episode: 239, icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777', channel: '1TV.com', lang: 'it' } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1Description for Program 1Test0.238.0/1S01E239\r\n' ) }) it('can generate xmltv without episode number', () => { const programs = [ { title: 'Program 1', description: 'Description for Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', category: 'Test', season: 1, icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777', channel: '1TV.com', lang: 'it' } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1Description for Program 1Test\r\n' ) }) it('can generate xmltv without categories', () => { const programs = [ { title: 'Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', channel: '1TV.com', lang: 'it' } ] const config = { site: 'example.com' } const output = xmltv.generate({ config, channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1\r\n' ) }) it('can generate xmltv with multiple categories', () => { const programs = [ { title: 'Program 1', description: 'Description for Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', category: ['Test1', 'Test2'], icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777', channel: '1TV.com', lang: 'it' } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1Description for Program 1Test1Test2\r\n' ) }) it('can generate xmltv with multiple urls', () => { const programs = [ { title: 'Program 1', description: 'Description for Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', category: ['Test1', 'Test2'], url: [ 'https://example.com/noattr.html', { value: 'https://example.com/attr.html', system: 'TestSystem' } ], icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777', channel: '1TV.com', lang: 'it' } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1Description for Program 1Test1Test2https://example.com/noattr.htmlhttps://example.com/attr.html\r\n' ) }) it('can generate xmltv with multiple images', () => { const programs = [ { title: 'Program 1', description: 'Description for Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', category: ['Test1', 'Test2'], url: [ 'https://example.com/noattr.html', { value: 'https://example.com/attr.html', system: 'TestSystem' } ], actor: { value: 'Actor 1', image: [ 'https://example.com/image1.jpg', { value: 'https://example.com/image2.jpg', type: 'person', size: '2', system: 'TestSystem', orient: 'P' } ] }, icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777', channel: '1TV.com', lang: 'it' } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1Description for Program 1Test1Test2https://example.com/noattr.htmlhttps://example.com/attr.htmlActor 1https://example.com/image1.jpghttps://example.com/image2.jpg\r\n' ) }) it('can generate xmltv with multiple credits member', () => { const programs = [ { title: 'Program 1', sub_title: 'Sub-title 1', description: 'Description for Program 1', url: 'http://example.com/title.html', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', category: 'Test', season: 9, episode: 239, icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777', channel: '1TV.com', lang: 'it', director: { value: 'Director 1', url: { value: 'http://example.com/director1.html', system: 'TestSystem' } }, actor: { value: 'Actor 1', role: 'Manny', guest: 'yes', url: { value: 'http://example.com/actor1.html', system: 'TestSystem' } }, writer: [ { value: 'Writer 1', url: { value: 'http://example.com/w1.html', system: 'TestSystem' } }, { value: 'Writer 2', url: { value: 'http://example.com/w2.html', system: 'TestSystem' } } ] } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1Sub-title 1Description for Program 1Testhttp://example.com/title.html8.238.0/1S09E23920220505Director 1http://example.com/director1.htmlActor 1http://example.com/actor1.htmlWriter 1http://example.com/w1.htmlWriter 2http://example.com/w2.html\r\n' ) })