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

43 lines
1.0 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')
2022-08-15 01:22:01 +02:00
fs.mkdirSync('tests/__data__/output/database')
2022-02-12 02:27:34 +01:00
const stdout = execSync(
2023-04-27 16:41:38 +02:00
'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data npm run db:create -- --input-dir=tests/__data__/input/streams',
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
})
2022-08-15 01:22:01 +02:00
expect(output).toMatchObject(expect.arrayContaining(expected))
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)
})
}