epg/sites/mytelly.co.uk/mytelly.co.uk.test.js
Toha 4aa23fa862
Update mytelly.co.uk guide.
Test:

```sh
npm test -- mytelly.co.uk

> test
> run-script-os mytelly.co.uk

> test:win32
> SET "TZ=Pacific/Nauru" && npx jest --runInBand mytelly.co.uk

 PASS  sites/mytelly.co.uk/mytelly.co.uk.test.js
  √ can generate valid url (4 ms)
  √ can parse response (135 ms)
  √ can handle empty guide (1 ms)

Test Suites: 1 passed, 1 total
Tests:       3 passed, 3 total
Snapshots:   0 total
Time:        4.146 s, estimated 5 s
Ran all test suites matching /mytelly.co.uk/i.
```

Grab:

```sh
npm run grab -- --site=mytelly.co.uk

> grab
> npx tsx scripts/commands/epg/grab.ts --site=mytelly.co.uk

starting...
config:
  output: guide.xml
  maxConnections: 1
  gzip: false
  site: mytelly.co.uk
loading channels...
  found 488 channel(s)
run #1:
  [1/976] mytelly.co.uk (en) - 63/mtv-xmas - Dec 7, 2024 (14 programs)
  [2/976] mytelly.co.uk (en) - 63/mtv-xmas - Dec 8, 2024 (11 programs)
  ...
  [975/976] mytelly.co.uk (en) - TNTSports6.uk - Dec 8, 2024 (3 programs)
  [976/976] mytelly.co.uk (en) - SkySportsMix.uk - Dec 8, 2024 (17 programs)
  saving to "guide.xml"...
  done in 00h 04m 16s
```

Signed-off-by: Toha <tohenk@yahoo.com>
2024-12-07 21:07:16 +07:00

51 lines
1.5 KiB
JavaScript

const { parser, url } = require('./mytelly.co.uk.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('2024-12-07', 'YYYY-MM-DD').startOf('d')
const channel = {
site_id: '713/bbc-one-london',
xmltv_id: 'BBCOneLondon.uk'
}
it('can generate valid url', () => {
expect(url({ channel, date })).toBe(
'https://www.mytelly.co.uk/tv-guide/listings/channel/713/bbc-one-london.html?dt=2024-12-07'
)
})
it('can parse response', async () => {
const content = fs.readFileSync(path.resolve(__dirname, '__data__/content.html'))
const results = (await parser({ content, channel, date })).map(p => {
p.start = p.start.toJSON()
p.stop = p.stop.toJSON()
return p
})
expect(results.length).toBe(25)
expect(results[0]).toMatchObject({
start: '2024-12-07T00:00:00.000Z',
stop: '2024-12-07T02:05:00.000Z',
title: 'Captain Phillips (2013)'
})
expect(results[24]).toMatchObject({
start: '2024-12-07T23:35:00.000Z',
stop: '2024-12-08T00:05:00.000Z',
title: 'The Rap Game UK',
subTitle: 'Past and Pressure - Season 6, Episode 5'
})
})
it('can handle empty guide', async () => {
const result = await parser({
date,
channel,
content: '<!DOCTYPE html><html><head></head><body></body></html>'
})
expect(result).toMatchObject([])
})