// npm run grab -- --site=guide.dstv.com // npm run channels:parse -- --config=./sites/guide.dstv.com/guide.dstv.com.config.js --output=./sites/guide.dstv.com/guide.dstv.com.channels.xml --set=bouquet:c35aaecd-5dd1-480b-ae24-357e600a0e4d const { parser, url } = require('./guide.dstv.com.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('2021-11-24', 'YYYY-MM-DD').startOf('d') const channel = { site_id: 'b0dc42b8-c651-4c3c-8713-a7fcd04744ee#M4H', xmltv_id: 'MNetMovies4.za' } it('can generate valid url', () => { const result = url({ date, channel }) expect(result).toBe( 'https://guide.dstv.com/api/gridview/page?bouquetId=b0dc42b8-c651-4c3c-8713-a7fcd04744ee&genre=all&date=2021-11-24' ) }) it('can parse response', () => { const content = "{\"M4H\": \"
  • 21:30

    Deadly Flight

  • 08:25

    I Still Believe

  • 15:50

    Despicable Me

  • 20:35

    The Foreigner

  • \"}" const result = parser({ date, channel, content }).map(p => { p.start = p.start.toJSON() p.stop = p.stop.toJSON() return p }) expect(result).toMatchObject([ { start: '2021-11-23T21:30:00.000Z', stop: '2021-11-24T08:25:00.000Z', title: 'Deadly Flight' }, { start: '2021-11-24T08:25:00.000Z', stop: '2021-11-24T15:50:00.000Z', title: 'I Still Believe' }, { start: '2021-11-24T15:50:00.000Z', stop: '2021-11-24T20:35:00.000Z', title: 'Despicable Me' }, { start: '2021-11-24T20:35:00.000Z', stop: '2021-11-24T21:35:00.000Z', title: 'The Foreigner' } ]) }) it('can handle empty guide', () => { const result = parser({ date, channel, content: '{}' }) expect(result).toMatchObject([]) })