mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 09:00:07 -04:00
Update astro.com.my.test.js
This commit is contained in:
parent
42fe404041
commit
eead93dea1
1 changed files with 43 additions and 13 deletions
|
@ -3,40 +3,70 @@
|
|||
const { parser, url } = require('./astro.com.my.config.js')
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
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)
|
||||
|
||||
const date = dayjs.utc('2022-08-30', 'YYYY-MM-DD').startOf('d')
|
||||
jest.mock('axios')
|
||||
|
||||
const date = dayjs.utc('2022-10-31', 'YYYY-MM-DD').startOf('d')
|
||||
const channel = {
|
||||
site_id: '235',
|
||||
xmltv_id: 'AstroArena.my'
|
||||
site_id: '425',
|
||||
xmltv_id: 'TVBClassic.hk'
|
||||
}
|
||||
|
||||
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/425.json')
|
||||
})
|
||||
|
||||
it('can parse response', () => {
|
||||
it('can parse response', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.json'))
|
||||
const results = parser({ content, date }).map(p => {
|
||||
|
||||
axios.get.mockImplementation(url => {
|
||||
if (
|
||||
url ===
|
||||
'https://contenthub-api.eco.astro.com.my/api/v1/linear-detail?siTrafficKey=1:10000526:47979653'
|
||||
) {
|
||||
return Promise.resolve({
|
||||
data: JSON.parse(fs.readFileSync(path.resolve(__dirname, '__data__/program.json')))
|
||||
})
|
||||
} else {
|
||||
return Promise.resolve({ data: '' })
|
||||
}
|
||||
})
|
||||
|
||||
let results = await parser({ content, channel, date })
|
||||
results = results.map(p => {
|
||||
p.start = p.start.toJSON()
|
||||
p.stop = p.stop.toJSON()
|
||||
return p
|
||||
})
|
||||
|
||||
expect(results.length).toBe(14)
|
||||
expect(results.length).toBe(31)
|
||||
expect(results[0]).toMatchObject({
|
||||
start: '2022-08-29T16:00:00.000Z',
|
||||
stop: '2022-08-29T21:15:00.000Z',
|
||||
title: 'BWF Kejohanan Dunia 2022'
|
||||
start: '2022-10-30T16:10:00.000Z',
|
||||
stop: '2022-10-30T17:02:00.000Z',
|
||||
title: 'Triumph in the Skies Ep06',
|
||||
description:
|
||||
'This classic drama depicts the many aspects of two complicated relationships set against an airline company. Will those involved ever find true love?',
|
||||
actors: ['Francis Ng Chun Yu', 'Joe Ma Tak Chung', 'Flora Chan Wai San'],
|
||||
directors: ['Joe Ma Tak Chung'],
|
||||
icon: 'https://s3-ap-southeast-1.amazonaws.com/ams-astro/production/images/1035X328883.jpg',
|
||||
rating: {
|
||||
system: 'LPF',
|
||||
value: 'U'
|
||||
},
|
||||
episode: 6,
|
||||
categories: ['Drama']
|
||||
})
|
||||
})
|
||||
|
||||
it('can handle empty guide', () => {
|
||||
it('can handle empty guide', async () => {
|
||||
const content = fs.readFileSync(path.resolve(__dirname, '__data__/no_content.html'))
|
||||
const result = parser({ date, content })
|
||||
expect(result).toMatchObject([])
|
||||
const results = await parser({ date, content })
|
||||
|
||||
expect(results).toMatchObject([])
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue