mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-10 00:50:09 -04:00
wip
This commit is contained in:
parent
299cf26cd6
commit
ce525ed13c
13 changed files with 199 additions and 207 deletions
|
@ -5,26 +5,32 @@ const { execSync } = require('child_process')
|
|||
beforeEach(() => {
|
||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/output')
|
||||
})
|
||||
|
||||
it('can create channels database', () => {
|
||||
const results = execSync(
|
||||
execSync(
|
||||
'DB_DIR=tests/__data__/output/database node scripts/commands/create-database.js --channels=tests/__data__/input/site.channels.xml --max-clusters=1',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
})
|
||||
|
||||
const database = fs.readFileSync(path.resolve('tests/__data__/output/database/channels.db'), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
const item = database.split('\n').find(i => i.includes('AndorraTV.ad'))
|
||||
expect(JSON.parse(item)).toMatchObject({
|
||||
name: 'Andorra TV',
|
||||
it('can create channels database', () => {
|
||||
const output = content('tests/__data__/output/database/channels.db')
|
||||
|
||||
expect(output).toMatchObject({
|
||||
lang: 'ca',
|
||||
xmltv_id: 'AndorraTV.ad',
|
||||
site_id: 'atv',
|
||||
name: 'Andorra TV',
|
||||
site: 'andorradifusio.ad',
|
||||
channelsPath: 'tests/__data__/input/site.channels.xml',
|
||||
configPath: 'tests/__data__/input/andorradifusio.ad.config.js',
|
||||
cluster_id: 1
|
||||
})
|
||||
})
|
||||
|
||||
function content(filepath) {
|
||||
const data = fs.readFileSync(path.resolve(filepath), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
|
||||
return JSON.parse(data)
|
||||
}
|
||||
|
|
|
@ -5,17 +5,15 @@ const { execSync } = require('child_process')
|
|||
beforeEach(() => {
|
||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/output')
|
||||
fs.copyFileSync('tests/__data__/input/channels.db', 'tests/__data__/temp/channels.db')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
fs.rmdirSync('tests/__data__/temp', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/temp')
|
||||
})
|
||||
|
||||
it('can create valid matrix', () => {
|
||||
const result = execSync('DB_DIR=tests/__data__/temp node scripts/commands/create-matrix.js', {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
const result = execSync(
|
||||
'DB_DIR=tests/__data__/input/database node scripts/commands/create-matrix.js',
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
|
||||
expect(result).toBe('::set-output name=matrix::{"cluster_id":[1]}\n')
|
||||
})
|
||||
|
|
|
@ -5,47 +5,38 @@ const { execSync } = require('child_process')
|
|||
beforeEach(() => {
|
||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/output')
|
||||
fs.mkdirSync('tests/__data__/output/api')
|
||||
|
||||
execSync(
|
||||
'PUBLIC_DIR=tests/__data__/output DB_DIR=tests/__data__/input/database node scripts/commands/generate-guides.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate channels.json', () => {
|
||||
const result = execSync(
|
||||
'PUBLIC_DIR=tests/__data__/output DB_DIR=tests/__data__/input/database node scripts/commands/generate-guides.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
const json = fs.readFileSync(path.resolve('tests/__data__/output/api/channels.json'), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
const parsed = JSON.parse(json)
|
||||
expect(parsed[0]).toMatchObject({
|
||||
id: 'AndorraTV.ad',
|
||||
name: ['Andorra TV'],
|
||||
logo: null,
|
||||
country: 'AD'
|
||||
})
|
||||
const output = content('tests/__data__/output/api/channels.json')
|
||||
const expected = content('tests/__data__/expected/api/channels.json')
|
||||
|
||||
expect(output).toBe(expected)
|
||||
})
|
||||
|
||||
it('can generate programs.json', () => {
|
||||
const result = execSync(
|
||||
'PUBLIC_DIR=tests/__data__/output DB_DIR=tests/__data__/input/database node scripts/commands/generate-guides.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
const json = fs.readFileSync(path.resolve('tests/__data__/output/api/programs.json'), {
|
||||
const output = content('tests/__data__/output/api/programs.json')
|
||||
const expected = content('tests/__data__/expected/api/programs.json')
|
||||
|
||||
expect(output).toBe(expected)
|
||||
})
|
||||
|
||||
it('can generate epg.xml', () => {
|
||||
const output = content('tests/__data__/output/guides/epg.xml')
|
||||
const expected = content('tests/__data__/expected/guides/epg.xml')
|
||||
|
||||
expect(output).toBe(expected)
|
||||
})
|
||||
|
||||
function content(filepath) {
|
||||
const data = fs.readFileSync(path.resolve(filepath), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
const parsed = JSON.parse(json)
|
||||
const program = parsed['AndorraTV.ad'][0]
|
||||
expect(Object.keys(program).sort()).toEqual([
|
||||
'categories',
|
||||
'channel',
|
||||
'description',
|
||||
'image',
|
||||
'start',
|
||||
'stop',
|
||||
'title'
|
||||
])
|
||||
expect(Array.isArray(program.title)).toBe(true)
|
||||
expect(Array.isArray(program.description)).toBe(true)
|
||||
expect(Array.isArray(program.categories)).toBe(true)
|
||||
expect(program.image === null || typeof program.image === 'string').toBe(true)
|
||||
})
|
||||
|
||||
return JSON.stringify(data)
|
||||
}
|
||||
|
|
|
@ -5,20 +5,22 @@ const { execSync } = require('child_process')
|
|||
beforeEach(() => {
|
||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/output')
|
||||
})
|
||||
|
||||
it('can load cluster', () => {
|
||||
const result = execSync(
|
||||
execSync(
|
||||
'DB_DIR=tests/__data__/input/database LOGS_DIR=tests/__data__/output/logs node scripts/commands/load-cluster.js --cluster-id=1',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
const logs = fs.readFileSync(
|
||||
})
|
||||
|
||||
it('can load cluster', () => {
|
||||
const output = fs.readFileSync(
|
||||
path.resolve('tests/__data__/output/logs/load-cluster/cluster_1.log'),
|
||||
{
|
||||
encoding: 'utf8'
|
||||
}
|
||||
)
|
||||
const lines = logs.split('\n')
|
||||
const lines = output.split('\n')
|
||||
const parsed = JSON.parse(lines[0])
|
||||
|
||||
expect(parsed._id).toBe('K1kaxwsWVjsRIZL6')
|
||||
})
|
||||
|
|
|
@ -5,20 +5,20 @@ const { execSync } = require('child_process')
|
|||
beforeEach(() => {
|
||||
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
||||
fs.mkdirSync('tests/__data__/output')
|
||||
fs.mkdirSync('tests/__data__/output/database')
|
||||
fs.copyFileSync('tests/__data__/input/programs.db', 'tests/__data__/output/database/programs.db')
|
||||
})
|
||||
|
||||
it('can save results', () => {
|
||||
const result = execSync(
|
||||
execSync(
|
||||
'DB_DIR=tests/__data__/output/database LOGS_PATH=tests/__data__/input/logs node scripts/commands/save-results.js',
|
||||
{ encoding: 'utf8' }
|
||||
)
|
||||
const logs = fs.readFileSync(path.resolve('tests/__data__/output/database/programs.db'), {
|
||||
})
|
||||
|
||||
it('can save results', () => {
|
||||
const output = fs.readFileSync(path.resolve('tests/__data__/output/database/programs.db'), {
|
||||
encoding: 'utf8'
|
||||
})
|
||||
const lines = logs.split('\n')
|
||||
const lines = output.split('\n')
|
||||
const parsed = JSON.parse(lines[0])
|
||||
|
||||
expect(Object.keys(parsed).sort()).toEqual([
|
||||
'_id',
|
||||
'category',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue