2022-02-12 02:27:41 +01:00
|
|
|
const { execSync } = require('child_process')
|
|
|
|
const fs = require('fs-extra')
|
|
|
|
const path = require('path')
|
|
|
|
|
|
|
|
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:41 +01:00
|
|
|
fs.copyFileSync(
|
|
|
|
'tests/__data__/input/database/db_update.streams.db',
|
2022-08-15 01:22:01 +02:00
|
|
|
'tests/__data__/output/database/streams.db'
|
2022-02-12 02:27:41 +01:00
|
|
|
)
|
2022-02-14 01:17:29 +01:00
|
|
|
})
|
2022-02-12 02:27:41 +01:00
|
|
|
|
2022-02-14 01:17:29 +01:00
|
|
|
it('can save results', () => {
|
2022-02-12 02:27:41 +01:00
|
|
|
const stdout = execSync(
|
2022-08-15 01:22:01 +02:00
|
|
|
'DB_DIR=tests/__data__/output/database LOGS_DIR=tests/__data__/input/logs/cluster/load npm run db:update',
|
2022-02-12 02:27:41 +01:00
|
|
|
{ encoding: 'utf8' }
|
|
|
|
)
|
2022-02-14 01:17:29 +01:00
|
|
|
expect(stdout).toEqual(`
|
|
|
|
> db:update
|
|
|
|
> node scripts/commands/database/update.js
|
|
|
|
|
|
|
|
loading streams...
|
2022-09-08 19:39:00 +02:00
|
|
|
found 10 streams
|
2022-02-14 01:17:29 +01:00
|
|
|
loading check results...
|
|
|
|
found 6 results
|
|
|
|
loading origins...
|
|
|
|
found 2 origins
|
|
|
|
updating streams...
|
|
|
|
updated 6 streams
|
|
|
|
done
|
|
|
|
`)
|
2022-02-12 02:27:41 +01:00
|
|
|
|
2022-08-24 02:14:20 +02:00
|
|
|
let input = content('tests/__data__/input/database/db_update.streams.db')
|
|
|
|
let output = content('tests/__data__/output/database/streams.db')
|
|
|
|
let expected = content('tests/__data__/expected/database/db_update.streams.db')
|
|
|
|
|
|
|
|
let inputDate = input.find(i => i._id === '2ST8btby3mmsgPF0')['updated_at']
|
|
|
|
let outputDate = output.find(i => i._id === '2ST8btby3mmsgPF0')['updated_at']
|
|
|
|
|
|
|
|
expect(outputDate).not.toEqual(inputDate)
|
|
|
|
|
|
|
|
output = output.map(i => {
|
|
|
|
delete i['updated_at']
|
|
|
|
return i
|
|
|
|
})
|
|
|
|
expect(output).toEqual(expected)
|
2022-02-12 02:27:41 +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)
|
|
|
|
})
|
|
|
|
}
|