Files
iptv/tests/commands/database/create.test.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2023-09-15 18:40:14 +03:00
import * as fs from 'fs-extra'
import * as path from 'path'
import { execSync } from 'child_process'
import * as _ from 'lodash'
2022-02-12 04:27:34 +03:00
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
2022-08-15 02:22:01 +03:00
fs.mkdirSync('tests/__data__/output/database')
2022-02-12 04:27:34 +03:00
const stdout = execSync(
2023-09-15 18:40:14 +03:00
'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data STREAMS_DIR=tests/__data__/input/streams npm run db:create',
2022-02-12 04:27:34 +03:00
{ encoding: 'utf8' }
)
})
it('can create database', () => {
let output = content('tests/__data__/output/database/streams.db')
2022-02-13 03:04:25 +03:00
let expected = content('tests/__data__/expected/database/db_create.streams.db')
2022-02-12 04:27:34 +03:00
output = output.map(i => {
i._id = null
return i
})
expected = expected.map(i => {
i._id = null
return i
})
2023-09-15 18:40:14 +03:00
expect(_.orderBy(output, 'name')).toMatchObject(
expect.arrayContaining(_.orderBy(expected, 'name'))
)
2022-02-12 04:27:34 +03:00
})
2023-09-15 18:40:14 +03:00
function content(filepath: string) {
2022-02-12 04:27:34 +03:00
const data = fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
return data
.split('\n')
.filter(l => l)
.map(l => {
return JSON.parse(l)
})
}