From 995d7950a1c4901c2b34d486db6cb40773d608bb Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Mon, 29 Aug 2022 19:37:21 +0300 Subject: [PATCH] Update astro.com.my.test.js --- sites/astro.com.my/astro.com.my.test.js | 49 ++++++++++++------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/sites/astro.com.my/astro.com.my.test.js b/sites/astro.com.my/astro.com.my.test.js index e4fe0327..d8da6982 100644 --- a/sites/astro.com.my/astro.com.my.test.js +++ b/sites/astro.com.my/astro.com.my.test.js @@ -1,41 +1,40 @@ const { parser, url } = require('./astro.com.my.config.js') +const fs = require('fs') +const path = require('path') 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-08-29', 'YYYY-MM-DD').startOf('d') +const date = dayjs.utc('2022-08-30', 'YYYY-MM-DD').startOf('d') const channel = { - site_id: '235', - xmltv_id: 'AstroArena.my' + site_id: '235', + xmltv_id: 'AstroArena.my' } it('can generate valid url', () => { - expect(url({ channel })).toBe( - 'https://contenthub-api.eco.astro.com.my/channel/235.json' - ) + expect(url({ channel })).toBe('https://contenthub-api.eco.astro.com.my/channel/235.json') }) it('can parse response', () => { - const content = `{"responseCode":200,"responseMessage":"Channel Detail","response":{"schedule":{"2022-08-29":[{"eventId":"40182037","title":"Motor: Cub Prix 2022","programmeId":"KAEQR","episodeId":"KAEQY","datetime":"2022-08-29 00:15:00.0","datetimeInUtc":"2022-08-28 16:15:00.0","duration":"02:25:00","siTrafficKey":"1:10000285:47439431","detailUrl":"/details/Motor-Cub-Prix-2022-1:10000285:47439431"}],"2022-08-30":[{"eventId":"40197573","title":"BWF Kejohanan Dunia 2022","programmeId":"KAGFN","episodeId":"KDGUX","datetime":"2022-08-30 00:00:00.0","datetimeInUtc":"2022-08-29 16:00:00.0","duration":"05:15:00","siTrafficKey":"1:10000285:47489961","detailUrl":"/details/BWF-Kejohanan-Dunia-2022-1:10000285:47489961"}]}}}` - const result = parser({ content }).map(p => { - p.start = p.start.toJSON() - p.stop = p.stop.toJSON() - return p - }) + const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json')) + const results = parser({ content, date }).map(p => { + p.start = p.start.toJSON() + p.stop = p.stop.toJSON() + return p + }) + expect(results.length).toBe(14) + expect(results[0]).toMatchObject({ + start: '2022-08-29T16:00:00.000Z', + stop: '2022-08-29T21:15:00.000Z', + title: 'BWF Kejohanan Dunia 2022' + }) +}) - expect(result).toMatchObject([ - { - start: '2022-08-28T16:15:00.000Z', - stop: '2022-08-28T18:40:00.000Z', - title: 'Motor: Cub Prix 2022', - }, - { - start: '2022-08-29T16:00:00.000Z', - stop: '2022-08-29T21:15:00.000Z', - title: 'BWF Kejohanan Dunia 2022', - } - ]) -}) \ No newline at end of file +it('can handle empty guide', () => { + const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html')) + const result = parser({ date, content }) + expect(result).toMatchObject([]) +})