Update create-database.js

This commit is contained in:
Aleksandr Statciuk
2022-02-05 02:48:48 +03:00
parent d34523641e
commit 1cce1f9173
13 changed files with 48 additions and 159 deletions

View File

@@ -5,42 +5,43 @@ const { execSync } = require('child_process')
beforeEach(() => {
fs.rmdirSync('tests/__data__/output', { recursive: true })
fs.mkdirSync('tests/__data__/output')
const stdout = execSync(
'DB_FILEPATH=tests/__data__/output/channels.db node scripts/commands/create-database.js --input-dir=tests/__data__/input/channels --max-clusters=1',
{ encoding: 'utf8' }
)
})
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' }
)
let output = content('tests/__data__/output/channels.db')
let expected = content('tests/__data__/expected/channels.db')
const database = fs.readFileSync(path.resolve('tests/__data__/output/test.db'), {
output = output.map(i => {
i._id = null
return i
})
expected = expected.map(i => {
i._id = null
return i
})
expect(output).toEqual(
expect.arrayContaining([
expect.objectContaining(expected[0]),
expect.objectContaining(expected[1])
])
)
})
function content(filepath) {
const data = fs.readFileSync(path.resolve(filepath), {
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' },
{ name: 'Worldwide', code: 'INT' }
],
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
})
})
return data
.split('\n')
.filter(l => l)
.map(l => {
return JSON.parse(l)
})
}