// node ./scripts/channels.js --config=./sites/mncvision.id/mncvision.id.config.js --output=./sites/mncvision.id/mncvision.id_id.channels.xml // npx epg-grabber --config=sites/mncvision.id/mncvision.id.config.js --channels=sites/mncvision.id/mncvision.id_id.channels.xml --output=.gh-pages/guides/id/mncvision.id.epg.xml --days=2 const { parser, url, request, logo } = require('./mncvision.id.config.js') const axios = require('axios') const dayjs = require('dayjs') const utc = require('dayjs/plugin/utc') const customParseFormat = require('dayjs/plugin/customParseFormat') dayjs.extend(customParseFormat) dayjs.extend(utc) jest.mock('axios') const date = dayjs.utc('2021-11-12', 'YYYY-MM-DD').startOf('d') const channel = { site_id: '203', xmltv_id: 'AnimalPlanetSoutheastAsia.us' } const content = `
Jam Tayang Program Acara Durasi
00:00African Wild S1: Seals01:00
` it('can generate valid url', () => { expect(url).toBe('https://mncvision.id/schedule/table') }) it('can generate valid request headers', () => { expect(request.headers).toMatchObject({ 'Content-Type': 'multipart/form-data; boundary=X-EPG-BOUNDARY' }) }) it('can generate valid request data', () => { const result = request.data({ channel, date }) expect(result._boundary).toBe('X-EPG-BOUNDARY') }) it('can get logo url', () => { expect(logo({ content, channel })).toBe( 'https://www.mncvision.id/userfiles/image/channel/channel_203.png' ) }) it('can parse response', done => { axios.get.mockImplementation(() => Promise.resolve({ data: `
Nikmati suasana kehidupan koloni anjing laut di kawasan pantai barat Afrika Selatan.
` }) ) parser({ date, channel, content }) .then(result => { expect(result).toMatchObject([ { start: '2021-11-11T17:00:00.000Z', stop: '2021-11-11T18:00:00.000Z', title: 'African Wild S1: Seals', description: 'Nikmati suasana kehidupan koloni anjing laut di kawasan pantai barat Afrika Selatan.' } ]) done() }) .catch(error => { done(error) }) }) it('can parse response with empty description', done => { axios.get.mockImplementation(() => Promise.resolve({ data: `
-
` }) ) parser({ date, channel, content }) .then(result => { expect(result).toMatchObject([ { start: '2021-11-11T17:00:00.000Z', stop: '2021-11-11T18:00:00.000Z', title: 'African Wild S1: Seals', description: null } ]) done() }) .catch(error => { done(error) }) }) it('can handle empty guide', done => { parser({ date, channel, content: `` }) .then(result => { expect(result).toMatchObject([]) done() }) .catch(error => { done(error) }) })