diff --git a/sites/dstv.com/dstv.com.test.js b/sites/dstv.com/dstv.com.test.js new file mode 100644 index 00000000..c3a59b1e --- /dev/null +++ b/sites/dstv.com/dstv.com.test.js @@ -0,0 +1,78 @@ +// npm run channels:parse -- --config=./sites/dstv.com/dstv.com.config.js --output=./sites/dstv.com/dstv.com_za.channels.xml --set=country:zaf +// npx epg-grabber --config=sites/dstv.com/dstv.com.config.js --channels=sites/dstv.com/dstv.com_za.channels.xml --output=guide.xml --days=2 + +const { parser, url } = require('./dstv.com.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('2022-03-11', 'YYYY-MM-DD').startOf('d') +const channel = { + site_id: 'zaf#HDT', + xmltv_id: 'MNetWest.za' +} + +it('can generate valid url', () => { + expect(url({ channel, date })).toBe( + 'https://www.dstv.com/umbraco/api/TvGuide/GetProgrammes?d=2022-03-11&country=zaf' + ) +}) + +it('can parse response', done => { + const content = `{"Total":4483,"Channels":[{"Number":"214","Tag":"S34","Name":"TENNIS","Programmes":[{"Id":"5c5a56e8-9959-4305-ae2f-7cc32ec39f5f","StartTime":"2022-03-11T09:00:00","EndTime":"2022-03-11T09:15:00","Title":"WTA 1000 HL '22: Indian Wells D2 M1"}]},{"Number":"101","Tag":"HDT","Name":"M-Net HD","Programmes":[{"Id":"a6ada4cd-93df-4eaf-bab4-041e2537ed23","StartTime":"2022-03-11T00:10:00","EndTime":"2022-03-11T00:50:00","Title":"Curb Your Enthusiasm"}]}]}` + + axios.get.mockImplementation(url => { + if ( + url === + 'https://www.dstv.com/umbraco/api/TvGuide/GetProgramme?id=a6ada4cd-93df-4eaf-bab4-041e2537ed23' + ) { + return Promise.resolve({ + data: JSON.parse( + `{"Id":"a6ada4cd-93df-4eaf-bab4-041e2537ed23","ChannelTag":"HDT","Channel":"M-Net Domestic HD","EventID":"HDT0000109067787","StartTime":"2022-03-11T00:10:00","EndTime":"2022-03-11T00:50:00","Duration":"00:40:00","Language":"eng","Title":"Curb Your Enthusiasm","Synopsis":"'S11/E6 of 10 - Man Fights Tiny Woman'. A general entertainment channel showcasing the best international content, focusing on scripted drama, comedy and talk.","Rating":"16","MainGenres":["Series"],"SubGenres":["Sitcom","Comedy"],"Items":[{"Key":"Year","Value":"2020"},{"Key":"Source Key ID","Value":"100338770"}],"ThumbnailUri":"https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/21893_curb_your_enthusiam169.jpg"}` + ) + }) + } else { + return Promise.resolve({ data: '' }) + } + }) + + parser({ content, channel }) + .then(result => { + result = result.map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + + expect(result).toMatchObject([ + { + start: '2022-03-11T00:10:00.000Z', + stop: '2022-03-11T00:50:00.000Z', + title: 'Curb Your Enthusiasm', + description: + "'S11/E6 of 10 - Man Fights Tiny Woman'. A general entertainment channel showcasing the best international content, focusing on scripted drama, comedy and talk.", + icon: 'https://03mcdecdnimagerepository.blob.core.windows.net/epguideimage/img/21893_curb_your_enthusiam169.jpg', + category: ['Sitcom', 'Comedy'] + } + ]) + done() + }) + .catch(done) +}) + +it('can handle empty guide', done => { + parser({ + content: `{"Total":0,"Channels":[]}`, + channel + }) + .then(result => { + expect(result).toMatchObject([]) + done() + }) + .catch(done) +})