iptv/tests/commands/cleanup-database.test.js

38 lines
860 B
JavaScript
Raw Normal View History

2022-02-07 05:12:33 +01:00
const fs = require('fs-extra')
2021-12-12 05:13:02 +01:00
const path = require('path')
const { execSync } = require('child_process')
beforeEach(() => {
2022-02-07 05:12:33 +01:00
fs.emptyDirSync('tests/__data__/output')
fs.copyFileSync(
'tests/__data__/input/database/cleanup-database.streams.db',
'tests/__data__/output/streams.db'
)
2021-12-12 05:13:02 +01:00
2022-02-07 05:12:33 +01:00
const stdout = execSync(
'DB_DIR=tests/__data__/output node scripts/commands/cleanup-database.js',
{
encoding: 'utf8'
}
)
2021-12-12 05:13:02 +01:00
})
it('can remove broken links from database', () => {
2022-02-07 05:12:33 +01:00
expect(content('tests/__data__/output/streams.db')).toEqual(
2022-02-07 06:41:54 +01:00
content('tests/__data__/expected/database/cleanup-database.streams.db')
2021-12-12 05:13:02 +01:00
)
})
2022-02-07 05:12:33 +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)
})
}