const utils = require('../src/utils') it('can load valid config.js', () => { expect(Object.keys(utils.loadConfig('./tests/input/example.com.config.js')).sort()).toEqual( [ 'site', 'channels', 'url', 'logo', 'parser', 'cookie', 'days', 'delay', 'timeout', 'lang', 'output', 'userAgent' ].sort() ) }) it('can parse valid channels.xml', () => { expect(utils.parseChannels('./tests/input/example.com.channels.xml')).toEqual([ { name: '1 TV', xmltv_id: '1TV.com', site_id: '1', site: 'example.com' }, { name: '2 TV', xmltv_id: '2TV.com', site_id: '2', site: 'example.com' } ]) }) it('can convert object to xmltv string', () => { const config = { lang: 'en' } const channels = [ { name: '1 TV', xmltv_id: '1TV.com', site_id: '1', site: 'example.com', logo: 'http://example.com/logos/1TV.png' }, { name: '2 TV', xmltv_id: '2TV.com', site_id: '2', site: 'example.com' } ] const programs = [ { title: 'Program 1', description: 'Description for Program 1', start: '2021-03-19 06:00:00 +0000', stop: '2021-03-19 06:30:00 +0000', category: 'Test', channel: '1TV.com' } ] const output = utils.convertToXMLTV({ config, channels, programs }) expect(output).toBe( '\r\n1 TV\r\n2 TV\r\nProgram 1Description for Program 1Test\r\n' ) }) it('can escape string', () => { const string = 'Música тест dun. &<>"\'\r\n' expect(utils.escapeString(string)).toBe('Música тест dun. &<>"'') }) it('can escape url', () => { const string = 'http://example.com/logos/1TV.png?param1=val¶m2=val' expect(utils.escapeString(string)).toBe( 'http://example.com/logos/1TV.png?param1=val&param2=val' ) })