const { parser, url } = require('./tv.dir.bg.config.js') const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') const customParseFormat = require('dayjs/plugin/customParseFormat') dayjs.extend(customParseFormat) dayjs.extend(utc) const date = dayjs.utc('2022-01-20', 'YYYY-MM-DD').startOf('d') const channel = { site_id: '12', xmltv_id: 'BTV.bg' } it('can generate valid url', () => { expect(url({ channel, date })).toBe('https://tv.dir.bg/tv_channel.php?id=12&dd=20.01') }) it('can parse response', () => { const content = '
' const result = parser({ content, date }).map(p => { p.start = p.start.toJSON() p.stop = p.stop.toJSON() return p }) expect(result).toMatchObject([ { start: '2022-01-20T04:00:00.000Z', stop: '2022-01-20T13:00:00.000Z', title: '„Тази сутрин” - информационно предаване с водещи Златимир Йочеви Биляна Гавазова' }, { start: '2022-01-20T13:00:00.000Z', stop: '2022-01-21T03:30:00.000Z', title: '„Доктор Чудо” - сериал, еп.71' }, { start: '2022-01-21T03:30:00.000Z', stop: '2022-01-21T04:00:00.000Z', title: '„Лице в лице” /п./' } ]) }) it('can handle empty guide', () => { const result = parser({ date, channel, content: '
    ' }) expect(result).toMatchObject([]) })