From be43a33a27d7ebd4a7b85d5c047b8e6fbc873748 Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sat, 12 Feb 2022 04:27:31 +0300 Subject: [PATCH] Create cleanup.test.js --- tests/commands/database/cleanup.test.js | 34 +++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/commands/database/cleanup.test.js diff --git a/tests/commands/database/cleanup.test.js b/tests/commands/database/cleanup.test.js new file mode 100644 index 0000000000..e4f8948ce2 --- /dev/null +++ b/tests/commands/database/cleanup.test.js @@ -0,0 +1,34 @@ +const { execSync } = require('child_process') +const fs = require('fs-extra') +const path = require('path') + +beforeEach(() => { + fs.emptyDirSync('tests/__data__/output') + fs.copyFileSync( + 'tests/__data__/input/database/db_cleanup.streams.db', + 'tests/__data__/output/streams.db' + ) + + const stdout = execSync('DB_DIR=tests/__data__/output npm run db:cleanup', { + encoding: 'utf8' + }) +}) + +it('can remove broken links from database', () => { + expect(content('tests/__data__/output/streams.db')).toEqual( + content('tests/__data__/expected/database/db_cleanup.streams.db') + ) +}) + +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) + }) +}