// npm run channels:parse -- --config=./sites/clickthecity.com/clickthecity.com.config.js --output=./sites/clickthecity.com/clickthecity.com.channels.xml // npx epg-grabber --config=sites/clickthecity.com/clickthecity.com.config.js --channels=sites/clickthecity.com/clickthecity.com.channels.xml --output=guide.xml --days=2 const { parser, url, request } = require('./clickthecity.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('2022-03-05', 'YYYY-MM-DD').startOf('d') const channel = { site_id: 'tv5', xmltv_id: 'TV5.ph' } it('can generate valid url', () => { expect(url({ channel })).toBe('https://www.clickthecity.com/tv/network/tv5') }) it('can generate valid request method', () => { expect(request.method).toBe('POST') }) it('can generate valid request headers', () => { expect(request.headers).toMatchObject({ 'content-type': 'application/x-www-form-urlencoded' }) }) it('can generate valid request data', () => { const result = request.data({ date }) expect(result.get('optDate')).toBe('2022-03-05') expect(result.get('optTime')).toBe('00:00:00') }) 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-03-04T16:00:00.000Z', stop: '2022-03-04T17:00:00.000Z', title: `CCF Worship Service` }, { start: '2022-03-04T22:30:00.000Z', stop: '2022-03-04T23:30:00.000Z', title: `Word Of God` }, { start: '2022-03-05T12:00:00.000Z', stop: '2022-03-05T13:00:00.000Z', title: `Rated Korina S2` } ]) }) it('can handle empty guide', () => { const result = parser({ date, channel, content: `` }) expect(result).toMatchObject([]) })