iptv/tests/commands/generate-playlists.test.js

124 lines
4.0 KiB
JavaScript
Raw Normal View History

2021-12-12 05:13:02 +01:00
const fs = require('fs')
const path = require('path')
const { execSync } = require('child_process')
function content(filepath) {
2022-01-12 13:02:45 +01:00
return fs.readFileSync(`tests/__data__/${filepath}`, {
2021-12-12 05:13:02 +01:00
encoding: 'utf8'
})
}
beforeEach(() => {
fs.rmdirSync('tests/__data__/output', { recursive: true })
2021-12-31 09:06:36 +01:00
fs.copyFileSync('tests/__data__/input/generate-playlists.test.db', 'tests/__data__/temp/test.db')
2021-12-12 05:13:02 +01:00
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', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/categories/general.m3u'))
.toBe(content('expected/.gh-pages/categories/general.m3u'))
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/categories/legislative.m3u'))
.toBe(content('expected/.gh-pages/categories/legislative.m3u'))
2021-12-12 05:13:02 +01:00
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/categories/news.m3u'))
.toBe(content('expected/.gh-pages/categories/news.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate countries', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/countries/ru.m3u'))
.toBe(content('expected/.gh-pages/countries/ru.m3u'))
expect(content('output/.gh-pages/countries/uk.m3u'))
.toBe(content('expected/.gh-pages/countries/uk.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate languages', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/languages/rus.m3u'))
.toBe(content('expected/.gh-pages/languages/rus.m3u'))
2021-12-12 05:13:02 +01:00
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/languages/eng.m3u'))
.toBe(content('expected/.gh-pages/languages/eng.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate regions', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/regions/asia.m3u'))
.toBe(content('expected/.gh-pages/regions/asia.m3u'))
expect(content('output/.gh-pages/regions/cis.m3u'))
.toBe(content('expected/.gh-pages/regions/cis.m3u'))
expect(content('output/.gh-pages/regions/emea.m3u'))
.toBe(content('expected/.gh-pages/regions/emea.m3u'))
expect(content('output/.gh-pages/regions/eur.m3u'))
.toBe(content('expected/.gh-pages/regions/eur.m3u'))
expect(content('output/.gh-pages/regions/int.m3u'))
.toBe(content('expected/.gh-pages/regions/int.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate channels.json', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/channels.json'))
.toBe(content('expected/.gh-pages/channels.json'))
2021-12-12 05:13:02 +01:00
})
it('can generate index.category.m3u', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/index.category.m3u'))
.toBe(content('expected/.gh-pages/index.category.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate index.country.m3u', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/index.country.m3u'))
.toBe(content('expected/.gh-pages/index.country.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate index.language.m3u', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/index.language.m3u'))
.toBe(content('expected/.gh-pages/index.language.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate index.region.m3u', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/index.region.m3u'))
.toBe(content('expected/.gh-pages/index.region.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate index.m3u', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/index.m3u'))
.toBe(content('expected/.gh-pages/index.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate index.nsfw.m3u', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/.gh-pages/index.nsfw.m3u'))
.toBe(content('expected/.gh-pages/index.nsfw.m3u'))
2021-12-12 05:13:02 +01:00
})
it('can generate logs categories', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/logs/generate-playlists/categories.log'))
.toBe(content('expected/logs/generate-playlists/categories.log'))
2021-12-12 05:13:02 +01:00
})
it('can generate logs countries', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/logs/generate-playlists/countries.log'))
.toBe(content('expected/logs/generate-playlists/countries.log'))
2021-12-12 05:13:02 +01:00
})
it('can generate logs languages', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/logs/generate-playlists/languages.log'))
.toBe(content('expected/logs/generate-playlists/languages.log'))
2021-12-12 05:13:02 +01:00
})
it('can generate logs regions', () => {
2022-01-12 13:02:45 +01:00
expect(content('output/logs/generate-playlists/regions.log'))
.toBe(content('expected/logs/generate-playlists/regions.log'))
2021-12-12 05:13:02 +01:00
})