|
1 | 1 | const { url, parser } = require('./www3.nhk.or.jp.config.js') |
| 2 | +const fs = require('fs') |
| 3 | +const path = require('path') |
2 | 4 | const dayjs = require('dayjs') |
3 | 5 | const utc = require('dayjs/plugin/utc') |
4 | 6 | dayjs.extend(utc) |
5 | 7 |
|
6 | | -const date = dayjs.utc('2023-04-29', 'YYYY-MM-DD').startOf('d') |
| 8 | +const date = dayjs.utc('2025-10-20', 'YYYY-MM-DD').startOf('d') |
| 9 | + |
7 | 10 | const channel = { |
8 | 11 | site_id: '0', |
9 | 12 | xmltv_id: 'NHKWorldJapan.jp', |
10 | 13 | lang: 'en', |
11 | 14 | logo: 'https://www3.nhk.or.jp/nhkworld/common/site_images/nw_webapp_1024x1024.png' |
12 | 15 | } |
13 | 16 |
|
| 17 | +const content = fs.readFileSync(path.resolve(__dirname, '__data__/schedule.json'), 'utf8') |
| 18 | + |
| 19 | +const context = { channel: channel, content: content, date: date } |
| 20 | + |
14 | 21 | it('can generate valid url', () => { |
15 | | - expect(url({ channel, date })).toBe( |
16 | | - 'https://nwapi.nhk.jp/nhkworld/epg/v7b/world/s1682726400000-e1682812800000.json' |
| 22 | + expect(url({ date })).toBe( |
| 23 | + 'https://masterpl.hls.nhkworld.jp/epg/w/20251020.json' |
17 | 24 | ) |
18 | 25 | }) |
19 | 26 |
|
20 | | -it('can parse response', () => { |
21 | | - const content = |
22 | | - '{"channel":{"item":[{"seriesId":"1007","airingId":"000","title":"NHK NEWSLINE","description":"NHK WORLD-JAPAN\'s flagship hourly news program delivers the latest world news, business and weather, with a focus on Japan and the rest of Asia.","link":"/nhkworld/en/news/","pubDate":"1682726400000","endDate":"1682727000000","vodReserved":false,"jstrm":"1","wstrm":"1","subtitle":"","content":"","content_clean":"","pgm_gr_id":"","thumbnail":"/nhkworld/upld/thumbnails/en/tv/regular_program/340aed63308aafd1178172abf6325231_large.jpg","thumbnail_s":"/nhkworld/upld/thumbnails/en/tv/regular_program/340aed63308aafd1178172abf6325231_small.jpg","showlist":"0","internal":"0","genre":{"TV":"11","Top":"","LC":""},"vod_id":"","vod_url":"","analytics":"[nhkworld]simul;NHK NEWSLINE;w02,001;1007-000-2023;2023-04-29T09:00:00+09:00"}]}}' |
23 | | - const results = parser({ content }) |
| 27 | +it('can handle empty guide', async () => { |
| 28 | + const results = await parser({ content: '' }) |
| 29 | + expect(results).toMatchObject([]) |
| 30 | +}) |
| 31 | + |
| 32 | +it('can parse response', async () => { |
| 33 | + const results = await parser(context) |
24 | 34 |
|
25 | | - expect(results).toMatchObject([ |
| 35 | + expect(results[0]).toMatchObject( |
26 | 36 | { |
27 | 37 | title: 'NHK NEWSLINE', |
28 | | - start: dayjs(1682726400000), |
29 | | - stop: dayjs(1682727000000), |
30 | | - description: |
31 | | - "NHK WORLD-JAPAN's flagship hourly news program delivers the latest world news, business and weather, with a focus on Japan and the rest of Asia.", |
32 | | - image: |
33 | | - 'https://www.nhk.or.jp/nhkworld/upld/thumbnails/en/tv/regular_program/340aed63308aafd1178172abf6325231_large.jpg', |
34 | | - sub_title: '' |
| 38 | + sub_title: '', |
| 39 | + start: dayjs('2025-10-19T15:00:00.000Z'), |
| 40 | + stop: dayjs('2025-10-19T15:10:00.000Z'), |
| 41 | + description: 'NHK NEWSLINE brings you up to date with the latest from Japan, Asia and around the world. Our team covers breaking news and major developments, with trusted anchors to tie it all together.', |
| 42 | + image: '', |
35 | 43 | } |
36 | | - ]) |
37 | | -}) |
| 44 | + ) |
38 | 45 |
|
39 | | -it('can handle empty guide', () => { |
40 | | - const results = parser({ content: '' }) |
| 46 | + expect(results[1]).toMatchObject( |
| 47 | + { |
| 48 | + title: 'J-MELO', |
| 49 | + sub_title: 'Furui Riho and shallm', |
| 50 | + start: dayjs('2025-10-19T15:10:00.000Z'), |
| 51 | + stop: dayjs('2025-10-19T15:38:00.000Z'), |
| 52 | + description: '*This program was first broadcast on April 13, 2025. \nJoin May J. for Japanese music! This week: Furui Riho (a singer-songwriter with gospel roots) and shallm (a band project from vocalist, lyricist, and composer lia).\nOn Demand until October 26, 2025', |
| 53 | + image: 'https://www3.nhk.or.jp/nhkworld/en/shows/2004445/images/wide_l_7eJOqZrlZQFF8GEPfH0emqOOlggwyC543Cv71Oou.jpg', |
| 54 | + } |
| 55 | + ) |
41 | 56 |
|
42 | | - expect(results).toMatchObject([]) |
| 57 | + expect(results[2]).toMatchObject( |
| 58 | + { |
| 59 | + title: 'INFO', |
| 60 | + sub_title: '', |
| 61 | + start: dayjs('2025-10-19T15:38:00.000Z'), |
| 62 | + stop: dayjs('2025-10-19T15:40:00.000Z'), |
| 63 | + description: ' ', |
| 64 | + image: '', |
| 65 | + } |
| 66 | + ) |
43 | 67 | }) |
0 commit comments