iptv/tests/commands/database/create.test.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-02-12 02:27:34 +01:00
const fs = require('fs-extra')
const path = require('path')
const { execSync } = require('child_process')
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
const stdout = execSync(
2022-02-15 00:46:08 +01:00
'DB_DIR=tests/__data__/output/database npm run db:create -- --input-dir=tests/__data__/input/streams --max-clusters=1',
2022-02-12 02:27:34 +01:00
{ encoding: 'utf8' }
)
})
it('can create database', () => {
let output = content('tests/__data__/output/database/streams.db')
2022-02-13 01:04:25 +01:00
let expected = content('tests/__data__/expected/database/db_create.streams.db')
2022-02-12 02:27:34 +01:00
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]),
2022-02-13 01:04:25 +01:00
expect.objectContaining(expected[2]),
expect.objectContaining(expected[3])
2022-02-12 02:27:34 +01:00
])
)
})
function content(filepath) {
const data = fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
return data
.split('\n')
.filter(l => l)
.map(l => {
return JSON.parse(l)
})
}