-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
rotana.net.test.js
107 lines (94 loc) · 3.63 KB
/
rotana.net.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const { parser, url, request } = require('./rotana.net.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)
jest.mock('axios')
const date = dayjs.utc('2024-11-26').startOf('d')
const channel = {
lang: 'en',
site_id: '439',
xmltv_id: 'RotanaCinemaMasr.sa'
}
const channelAr = Object.assign({}, channel, { lang: 'ar' })
axios.get.mockImplementation((url, opts) => {
if (url === 'https://rotana.net/en/streams?channel=439&itemId=736970') {
return Promise.resolve({
data: fs.readFileSync(path.resolve(__dirname, '__data__/program_en.html'))
})
}
if (url === 'https://rotana.net/ar/streams?channel=439&itemId=736970') {
return Promise.resolve({
data: fs.readFileSync(path.resolve(__dirname, '__data__/program_ar.html'))
})
}
return Promise.resolve({ data: '' })
})
it('can use defined user agent', () => {
const result = request.headers['User-Agent']
expect(result).toBe(
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/118.0.0.0 Safari/537.36 OPR/104.0.0.0'
)
})
it('can generate valid english url', () => {
const result = url({ channel, date })
expect(result).toBe('https://rotana.net/en/streams?channel=439&tz=')
})
it('can generate valid arabic url', () => {
const result = url({ channel: channelAr, date })
expect(result).toBe('https://rotana.net/ar/streams?channel=439&tz=')
})
it('can parse english response', async () => {
const result = (await parser({
channel,
date,
content: fs.readFileSync(path.join(__dirname, '/__data__/content_en.html'))
})).map(a => {
a.start = a.start.toJSON()
a.stop = a.stop.toJSON()
return a
})
expect(result.length).toBe(12)
expect(result[11]).toMatchObject({
start: '2024-11-26T20:00:00.000Z',
stop: '2024-11-26T22:00:00.000Z',
title: 'Khiyana Mashroua',
description:
'Hisham knows that his father has given all his wealth to his elder brother. This leads him to plan to kill his brother to make it look like a defense of honor, which he does by killing his wife along...',
image: 'https://s3.eu-central-1.amazonaws.com/rotana.website/spider_storage/1398X1000/1687084565',
category: 'Movie'
})
})
it('can parse arabic response', async () => {
const result = (await parser({
channel: channelAr,
date,
content: fs.readFileSync(path.join(__dirname, '/__data__/content_ar.html'))
})).map(a => {
a.start = a.start.toJSON()
a.stop = a.stop.toJSON()
return a
})
expect(result.length).toBe(12)
expect(result[11]).toMatchObject({
start: '2024-11-26T20:00:00.000Z',
stop: '2024-11-26T22:00:00.000Z',
title: 'خيانة مشروعة',
description:
'يعلم هشام البحيري أن والده قد حرمه من الميراث، ووهب كل ثروته لشقيقه اﻷكبر، وهو ما يدفعه لتدبير جريمة قتل شقيقه لتبدو وكأنها دفاع عن الشرف، وذلك حين يقتل هشام زوجته مع شقيقه.',
image: 'https://s3.eu-central-1.amazonaws.com/rotana.website/spider_storage/1398X1000/1687084565',
category: 'فيلم'
})
})
it('can handle empty guide', async () => {
const result = await parser({
content: '<!DOCTYPE html><html><head></head><body></body></html>',
date,
channel
})
expect(result).toMatchObject([])
})