mirror of
https://github.com/iptv-org/iptv
synced 2026-04-22 10:47:16 -04:00
Create tests
This commit is contained in:
44
tests/commands/check-streams.test.js
Normal file
44
tests/commands/check-streams.test.js
Normal file
@@ -0,0 +1,44 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/output')
|
||||
fs.copyFileSync('tests/__data__/input/test.db', 'tests/__data__/temp/test.db')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmdirSync('tests/__data__/temp', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/temp')
|
||||
})
|
||||
|
||||
it('return results if stream with error', () => {
|
||||
const result = execSync(
|
||||
'DB_FILEPATH=tests/__data__/temp/test.db LOGS_PATH=tests/__data__/output/logs node scripts/commands/check-streams.js --cluster-id=1 --timeout=1',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
const logs = fs.readFileSync(
|
||||
path.resolve('tests/__data__/output/logs/check-streams/cluster_1.log'),
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
const lines = logs.split('\n')
|
||||
expect(JSON.parse(lines[0])).toMatchObject({
|
||||
_id: '2ST8btby3mmsgPF0',
|
||||
url: 'http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8',
|
||||
http: { referrer: '', 'user-agent': '' },
|
||||
error: 'Operation timed out',
|
||||
streams: [],
|
||||
requests: []
|
||||
})
|
||||
expect(JSON.parse(lines[1])).toMatchObject({
|
||||
_id: 'I6cjG2xCBRFFP4sz',
|
||||
url: 'https://iptv-all.lanesh4d0w.repl.co/andorra/atv',
|
||||
http: { referrer: '', 'user-agent': '' },
|
||||
error: 'Operation timed out',
|
||||
streams: [],
|
||||
requests: []
|
||||
})
|
||||
})
|
||||
25
tests/commands/cleanup-database.test.js
Normal file
25
tests/commands/cleanup-database.test.js
Normal file
@@ -0,0 +1,25 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.copyFileSync('tests/__data__/input/test.db', 'tests/__data__/temp/test.db')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmdirSync('tests/__data__/temp', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/temp')
|
||||
})
|
||||
|
||||
it('can remove broken links from database', () => {
|
||||
const result = execSync(
|
||||
'DB_FILEPATH=tests/__data__/temp/test.db node scripts/commands/cleanup-database.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
|
||||
const database = fs.readFileSync('tests/__data__/temp/test.db', { encoding: 'utf8' })
|
||||
const lines = database.split('\n')
|
||||
expect(lines[0]).toBe(
|
||||
`{"name":"ЛДПР ТВ","id":"LDPRTV.ru","filepath":"tests/__data__/output/channels/ru.m3u","src_country":{"name":"Russia","code":"RU","lang":"rus"},"tvg_country":"RU","countries":[{"name":"Russia","code":"RU","lang":"rus"}],"regions":[{"name":"Asia","code":"ASIA"},{"name":"Commonwealth of Independent States","code":"CIS"},{"name":"Europe, the Middle East and Africa","code":"EMEA"},{"name":"Europe","code":"EUR"}],"languages":[{"name":"Russian","code":"rus"}],"categories":[{"name":"General","slug":"general","nsfw":false}],"tvg_url":"","guides":["https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"],"logo":"https://iptvx.one/icn/ldpr-tv.png","resolution":{"height":1080,"width":null},"status":{"label":"","code":"online","level":1},"url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","http":{"referrer":"","user-agent":""},"is_nsfw":false,"is_broken":false,"updated":false,"cluster_id":1,"_id":"2ST8btby3mmsgPF0"}`
|
||||
)
|
||||
})
|
||||
45
tests/commands/create-database.test.js
Normal file
45
tests/commands/create-database.test.js
Normal file
@@ -0,0 +1,45 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/output')
|
||||
})
|
||||
|
||||
it('can create database', () => {
|
||||
execSync(
|
||||
'DB_FILEPATH=tests/__data__/output/test.db node scripts/commands/create-database.js --input-dir=tests/__data__/input/channels --max-clusters=1',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
|
||||
const database = fs.readFileSync(path.resolve('tests/__data__/output/test.db'), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
const item = database.split('\n').find(i => i.includes('ATV.ad'))
|
||||
expect(JSON.parse(item)).toMatchObject({
|
||||
name: 'ATV',
|
||||
id: 'ATV.ad',
|
||||
filepath: 'tests/__data__/input/channels/ad_example.m3u',
|
||||
src_country: { name: 'Andorra', code: 'AD', lang: 'cat' },
|
||||
tvg_country: 'AD',
|
||||
countries: [{ name: 'Andorra', code: 'AD', lang: 'cat' }],
|
||||
regions: [
|
||||
{ name: 'Europe, the Middle East and Africa', code: 'EMEA' },
|
||||
{ name: 'Europe', code: 'EUR' }
|
||||
],
|
||||
languages: [{ name: 'Catalan', code: 'cat' }],
|
||||
categories: [{ name: 'General', slug: 'general', nsfw: false }],
|
||||
tvg_url: '',
|
||||
guides: [],
|
||||
logo: 'https://i.imgur.com/kJCjeQ4.png',
|
||||
resolution: { height: 720, width: null },
|
||||
status: { label: 'Offline', code: 'offline', level: 5 },
|
||||
url: 'https://iptv-all.lanesh4d0w.repl.co/andorra/atv',
|
||||
http: { referrer: '', 'user-agent': '' },
|
||||
is_nsfw: false,
|
||||
is_broken: true,
|
||||
updated: false,
|
||||
cluster_id: 1
|
||||
})
|
||||
})
|
||||
20
tests/commands/create-matrix.test.js
Normal file
20
tests/commands/create-matrix.test.js
Normal file
@@ -0,0 +1,20 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.copyFileSync('tests/__data__/input/test.db', 'tests/__data__/temp/test.db')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmdirSync('tests/__data__/temp', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/temp')
|
||||
})
|
||||
|
||||
it('can create valid matrix', () => {
|
||||
const result = execSync(
|
||||
'DB_FILEPATH=tests/__data__/temp/test.db node scripts/commands/create-matrix.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
expect(result).toBe('::set-output name=matrix::{"cluster_id":[1,3]}\n')
|
||||
})
|
||||
204
tests/commands/generate-playlists.test.js
Normal file
204
tests/commands/generate-playlists.test.js
Normal file
@@ -0,0 +1,204 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
function content(filepath) {
|
||||
return fs.readFileSync(`tests/__data__/output/${filepath}`, {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||
fs.copyFileSync('tests/__data__/input/test.db', 'tests/__data__/temp/test.db')
|
||||
|
||||
execSync(
|
||||
'DB_FILEPATH=tests/__data__/temp/test.db PUBLIC_PATH=tests/__data__/output/.gh-pages LOGS_PATH=tests/__data__/output/logs node scripts/commands/generate-playlists.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmdirSync('tests/__data__/temp', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/temp')
|
||||
})
|
||||
|
||||
it('can generate categories', () => {
|
||||
expect(content('.gh-pages/categories/general.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
|
||||
expect(content('.gh-pages/categories/news.m3u')).toBe(`#EXTM3U x-tvg-url=""
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="News",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate countries', () => {
|
||||
expect(content('.gh-pages/countries/ru.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
|
||||
expect(content('.gh-pages/countries/uk.m3u')).toBe(`#EXTM3U x-tvg-url=""
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="News",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate languages', () => {
|
||||
expect(content('.gh-pages/languages/rus.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
|
||||
expect(content('.gh-pages/languages/eng.m3u')).toBe(`#EXTM3U x-tvg-url=""
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="News",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate regions', () => {
|
||||
expect(content('.gh-pages/regions/asia.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
|
||||
expect(content('.gh-pages/regions/cis.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
|
||||
expect(content('.gh-pages/regions/emea.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="News",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
|
||||
expect(content('.gh-pages/regions/eur.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="News",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate channels.json', () => {
|
||||
expect(content('.gh-pages/channels.json')).toBe(
|
||||
`[{"name":"BBC News HD","logo":"https://i.imgur.com/eNPIQ9f.png","url":"http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8","categories":[{"name":"News","slug":"news"}],"countries":[{"name":"United Kingdom","code":"UK"}],"languages":[{"name":"English","code":"eng"}],"tvg":{"id":"BBCNews.uk","name":"BBC News HD","url":""}},{"name":"ЛДПР ТВ","logo":"https://iptvx.one/icn/ldpr-tv.png","url":"http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8","categories":[{"name":"General","slug":"general"}],"countries":[{"name":"Russia","code":"RU"}],"languages":[{"name":"Russian","code":"rus"}],"tvg":{"id":"LDPRTV.ru","name":"ЛДПР ТВ","url":"https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"}}]`
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate index.category.m3u', () => {
|
||||
expect(content('.gh-pages/index.category.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="News",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate index.country.m3u', () => {
|
||||
expect(content('.gh-pages/index.country.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="Russia",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="United Kingdom",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate index.language.m3u', () => {
|
||||
expect(content('.gh-pages/index.language.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="English",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="Russian",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate index.region.m3u', () => {
|
||||
expect(content('.gh-pages/index.region.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="Asia",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="Commonwealth of Independent States",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="Europe",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="Europe",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="Europe, the Middle East and Africa",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="Europe, the Middle East and Africa",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate index.m3u', () => {
|
||||
expect(content('.gh-pages/index.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="News",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate index.nsfw.m3u', () => {
|
||||
expect(content('.gh-pages/index.nsfw.m3u'))
|
||||
.toBe(`#EXTM3U x-tvg-url="https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml"
|
||||
#EXTINF:-1 tvg-id="BBCNews.uk" tvg-country="UK" tvg-language="English" tvg-logo="https://i.imgur.com/eNPIQ9f.png" group-title="News",BBC News HD (720p) [Not 24/7]
|
||||
http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate logs categories', () => {
|
||||
expect(content('logs/generate-playlists/categories.log'))
|
||||
.toBe(`{"name":"General","slug":"general","count":1}
|
||||
{"name":"News","slug":"news","count":1}
|
||||
{"name":"Other","slug":"other","count":0}
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate logs countries', () => {
|
||||
expect(content('logs/generate-playlists/countries.log'))
|
||||
.toBe(`{"name":"Andorra","code":"AD","count":0}
|
||||
{"name":"Russia","code":"RU","count":1}
|
||||
{"name":"United Kingdom","code":"UK","count":1}
|
||||
{"name":"International","code":"INT","count":0}
|
||||
{"name":"Undefined","code":"UNDEFINED","count":0}
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate logs languages', () => {
|
||||
expect(content('logs/generate-playlists/languages.log'))
|
||||
.toBe(`{"name":"Catalan","code":"cat","count":0}
|
||||
{"name":"English","code":"eng","count":1}
|
||||
{"name":"Russian","code":"rus","count":1}
|
||||
{"name":"Undefined","code":"undefined","count":0}
|
||||
`)
|
||||
})
|
||||
|
||||
it('can generate logs regions', () => {
|
||||
expect(content('logs/generate-playlists/regions.log'))
|
||||
.toBe(`{"name":"Asia","code":"ASIA","count":1}
|
||||
{"name":"Commonwealth of Independent States","code":"CIS","count":1}
|
||||
{"name":"Europe","code":"EUR","count":2}
|
||||
{"name":"Europe, the Middle East and Africa","code":"EMEA","count":2}
|
||||
{"name":"Undefined","code":"UNDEFINED","count":0}
|
||||
`)
|
||||
})
|
||||
100
tests/commands/update-database.test.js
Normal file
100
tests/commands/update-database.test.js
Normal file
@@ -0,0 +1,100 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.copyFileSync('tests/__data__/input/test.db', 'tests/__data__/temp/test.db')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmdirSync('tests/__data__/temp', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/temp')
|
||||
})
|
||||
|
||||
it('can update database', () => {
|
||||
const result = execSync(
|
||||
'DB_FILEPATH=tests/__data__/temp/test.db LOGS_PATH=tests/__data__/input/logs EPG_CODES_FILEPATH=tests/__data__/input/codes.json node scripts/commands/update-database.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
const database = fs.readFileSync('tests/__data__/temp/test.db', { encoding: 'utf8' })
|
||||
const lines = database.split('\n')
|
||||
expect(JSON.parse(lines[0])).toMatchObject({
|
||||
name: 'ЛДПР ТВ',
|
||||
id: 'LDPRTV.ru',
|
||||
filepath: 'tests/__data__/output/channels/ru.m3u',
|
||||
src_country: { name: 'Russia', code: 'RU', lang: 'rus' },
|
||||
tvg_country: 'RU',
|
||||
countries: [{ name: 'Russia', code: 'RU', lang: 'rus' }],
|
||||
regions: [
|
||||
{ name: 'Asia', code: 'ASIA' },
|
||||
{ name: 'Commonwealth of Independent States', code: 'CIS' },
|
||||
{ name: 'Europe, the Middle East and Africa', code: 'EMEA' },
|
||||
{ name: 'Europe', code: 'EUR' }
|
||||
],
|
||||
languages: [{ name: 'Russian', code: 'rus' }],
|
||||
categories: [{ name: 'General', slug: 'general', nsfw: false }],
|
||||
tvg_url: '',
|
||||
guides: ['https://iptv-org.github.io/epg/guides/ru/tv.yandex.ru.epg.xml'],
|
||||
logo: 'https://iptvx.one/icn/ldpr-tv.png',
|
||||
resolution: { height: 1080, width: 1920 },
|
||||
status: { label: '', code: 'online', level: 1 },
|
||||
url: 'http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8',
|
||||
http: { referrer: '', 'user-agent': '' },
|
||||
is_nsfw: false,
|
||||
is_broken: false,
|
||||
updated: true,
|
||||
cluster_id: 1,
|
||||
_id: '2ST8btby3mmsgPF0'
|
||||
})
|
||||
expect(JSON.parse(lines[1])).toMatchObject({
|
||||
name: 'BBC News HD',
|
||||
id: 'BBCNews.uk',
|
||||
filepath: 'tests/__data__/output/channels/uk.m3u',
|
||||
src_country: { name: 'United Kingdom', code: 'UK', lang: 'eng' },
|
||||
tvg_country: 'UK',
|
||||
countries: [{ name: 'United Kingdom', code: 'UK', lang: 'eng' }],
|
||||
regions: [
|
||||
{ name: 'Europe, the Middle East and Africa', code: 'EMEA' },
|
||||
{ name: 'Europe', code: 'EUR' }
|
||||
],
|
||||
languages: [{ name: 'English', code: 'eng' }],
|
||||
categories: [{ name: 'News', slug: 'news', nsfw: false }],
|
||||
tvg_url: '',
|
||||
guides: [],
|
||||
logo: 'https://i.imgur.com/eNPIQ9f.png',
|
||||
resolution: { height: 720, width: null },
|
||||
status: { label: 'Not 24/7', code: 'not_247', level: 3 },
|
||||
url: 'http://1111296894.rsc.cdn77.org/LS-ATL-54548-6/index.m3u8',
|
||||
http: { referrer: '', 'user-agent': '' },
|
||||
is_nsfw: false,
|
||||
is_broken: false,
|
||||
updated: false,
|
||||
cluster_id: 3,
|
||||
_id: '3TbieV1ptnZVCIdn'
|
||||
})
|
||||
expect(JSON.parse(lines[2])).toMatchObject({
|
||||
name: 'ATV',
|
||||
id: 'AndorraTV.ad',
|
||||
filepath: 'tests/__data__/output/channels/ad.m3u',
|
||||
src_country: { name: 'Andorra', code: 'AD', lang: 'cat' },
|
||||
tvg_country: 'AD',
|
||||
countries: [{ name: 'Andorra', code: 'AD', lang: 'cat' }],
|
||||
regions: [
|
||||
{ name: 'Europe, the Middle East and Africa', code: 'EMEA' },
|
||||
{ name: 'Europe', code: 'EUR' }
|
||||
],
|
||||
languages: [{ name: 'Catalan', code: 'cat' }],
|
||||
categories: [{ name: 'General', slug: 'general', nsfw: false }],
|
||||
tvg_url: '',
|
||||
guides: ['https://iptv-org.github.io/epg/guides/ad/andorradifusio.ad.epg.xml'],
|
||||
logo: 'https://i.imgur.com/kJCjeQ4.png',
|
||||
resolution: { height: 720, width: null },
|
||||
status: { label: 'Timeout', code: 'timeout', level: 4 },
|
||||
url: 'https://iptv-all.lanesh4d0w.repl.co/andorra/atv',
|
||||
http: { referrer: '', 'user-agent': '' },
|
||||
is_nsfw: false,
|
||||
is_broken: true,
|
||||
updated: true,
|
||||
cluster_id: 1
|
||||
})
|
||||
})
|
||||
37
tests/commands/update-playlists.test.js
Normal file
37
tests/commands/update-playlists.test.js
Normal file
@@ -0,0 +1,37 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.copyFileSync('tests/__data__/input/test.db', 'tests/__data__/temp/test.db')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmdirSync('tests/__data__/temp', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/temp')
|
||||
})
|
||||
|
||||
it('can update playlist', () => {
|
||||
const result = execSync(
|
||||
'DB_FILEPATH=tests/__data__/temp/test.db node scripts/commands/update-playlists.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
|
||||
const adPlaylist = fs.readFileSync('tests/__data__/output/channels/ad.m3u', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
|
||||
expect(adPlaylist).toBe(`#EXTM3U
|
||||
#EXTINF:-1 tvg-id="AndorraTV.ad" tvg-country="AD" tvg-language="Catalan" tvg-logo="https://i.imgur.com/kJCjeQ4.png" group-title="General",ATV (720p) [Offline]
|
||||
https://iptv-all.lanesh4d0w.repl.co/andorra/atv
|
||||
`)
|
||||
|
||||
const ruPlaylist = fs.readFileSync('tests/__data__/output/channels/ru.m3u', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
|
||||
expect(ruPlaylist).toBe(`#EXTM3U
|
||||
#EXTINF:-1 tvg-id="LDPRTV.ru" tvg-country="RU" tvg-language="Russian" tvg-logo="https://iptvx.one/icn/ldpr-tv.png" group-title="General",ЛДПР ТВ (1080p)
|
||||
http://46.46.143.222:1935/live/mp4:ldpr.stream/playlist.m3u8
|
||||
`)
|
||||
})
|
||||
23
tests/commands/update-readme.test.js
Normal file
23
tests/commands/update-readme.test.js
Normal file
@@ -0,0 +1,23 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
beforeEach(() => {
|
||||
fs.rmdirSync(path.resolve('tests/__data__/output'), { recursive: true })
|
||||
})
|
||||
|
||||
it('can update readme.md', () => {
|
||||
const result = execSync(
|
||||
'LOGS_PATH=tests/__data__/input/logs node scripts/commands/update-readme.js --config=tests/__data__/input/readme.json',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
|
||||
const readme = fs.readFileSync(path.resolve('tests/__data__/output/readme.md'), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
const expected = fs.readFileSync(path.resolve('tests/__data__/input/readme.md'), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
|
||||
expect(readme).toBe(expected)
|
||||
})
|
||||
16
tests/commands/validate.test.js
Normal file
16
tests/commands/validate.test.js
Normal file
@@ -0,0 +1,16 @@
|
||||
const fs = require('fs')
|
||||
const path = require('path')
|
||||
const { execSync } = require('child_process')
|
||||
|
||||
it('can validate channels name', () => {
|
||||
try {
|
||||
execSync('node scripts/commands/validate.js --input-dir=tests/__data__/input/channels', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
} catch (err) {
|
||||
expect(err.status).toBe(1)
|
||||
expect(err.stdout).toBe(
|
||||
`tests/__data__/input/channels/us_blocked.m3u:2 'Fox Sports' is on the blocklist due to claims of copyright holders (https://github.com/github/dmca/blob/master/2020/09/2020-09-16-dfl.md)\n\n`
|
||||
)
|
||||
}
|
||||
})
|
||||
Reference in New Issue
Block a user