import xmltv from '../src/xmltv' jest.useFakeTimers('modern').setSystemTime(new Date('2022-05-05')) const channels = [ { xmltv_id: '1TV.co', name: '1 TV', logo: 'https://example.com/logos/1TV.png', site: 'example.com' }, { xmltv_id: '2TV.co', name: '2 TV', site: 'example.com' } ] it('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', date: '2022-05-06', season: 9, episode: 239, icon: 'https://example.com/images/Program1.png?x=шеллы&sid=777', channel: '1TV.co', 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 }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1Sub-title & 1Description for Program 1Director 1http://example.com/director1.htmlhttps://example.com/image1.jpghttps://example.com/image2.jpgDirector 2Actor 1Actor 2Writer 120220506Testhttp://example.com/title.html8.238.0/1S09E239PG' ) }) it('can generate xmltv without season number', () => { const programs = [ { channel: '1TV.co', title: 'Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', episode: 239 } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 10.238.0/1S01E239' ) }) it('can generate xmltv without episode number', () => { const programs = [ { channel: '1TV.co', title: 'Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', season: 1 } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1' ) }) it('can generate xmltv without categories', () => { const programs = [ { channel: '1TV.co', title: 'Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z' } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1' ) }) it('can generate xmltv with multiple categories', () => { const programs = [ { channel: '1TV.co', title: 'Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', category: ['Category 1', 'Category 2'] } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1Category 1Category 2' ) }) it('can generate xmltv with multiple urls', () => { const programs = [ { channel: '1TV.co', title: 'Program 1', start: '2021-03-19T06:00:00.000Z', stop: '2021-03-19T06:30:00.000Z', url: [ 'https://example.com/noattr.html', { value: 'https://example.com/attr.html', system: 'TestSystem' } ] } ] const output = xmltv.generate({ channels, programs }) expect(output).toBe( '\r\n1 TVhttps://example.com\r\n2 TVhttps://example.com\r\nProgram 1https://example.com/noattr.htmlhttps://example.com/attr.html' ) })