diff --git a/tests/commands/database/clear.test.js b/tests/commands/database/clear.test.js new file mode 100644 index 0000000000..3dea67cc12 --- /dev/null +++ b/tests/commands/database/clear.test.js @@ -0,0 +1,48 @@ +const fs = require('fs-extra') +const path = require('path') +const { execSync } = require('child_process') + +beforeEach(() => { + fs.emptyDirSync('tests/__data__/output') + fs.mkdirSync('tests/__data__/output/database') + fs.copyFileSync( + 'tests/__data__/input/database/db_clear.streams.db', + 'tests/__data__/output/database/streams.db' + ) + + const stdout = execSync( + 'DB_DIR=tests/__data__/output/database npm run db:clear -- --threshold 7', + { + encoding: 'utf8' + } + ) +}) + +it('can clear database', () => { + let output = content('tests/__data__/output/database/streams.db') + let expected = content('tests/__data__/expected/database/db_clear.streams.db') + + output = output.map(i => { + i._id = null + return i + }) + expected = expected.map(i => { + i._id = null + return i + }) + + expect(output).toMatchObject(expected) +}) + +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) + }) +} diff --git a/tests/commands/database/create.test.js b/tests/commands/database/create.test.js index 056b50cbd3..79f7b07b32 100644 --- a/tests/commands/database/create.test.js +++ b/tests/commands/database/create.test.js @@ -4,9 +4,10 @@ const { execSync } = require('child_process') beforeEach(() => { fs.emptyDirSync('tests/__data__/output') + fs.mkdirSync('tests/__data__/output/database') const stdout = execSync( - 'DB_DIR=tests/__data__/output/database npm run db:create -- --input-dir=tests/__data__/input/streams --max-clusters=1', + 'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data npm run db:create -- --input-dir=tests/__data__/input/streams --max-clusters=1', { encoding: 'utf8' } ) }) @@ -24,14 +25,7 @@ it('can create database', () => { return i }) - expect(output).toEqual( - expect.arrayContaining([ - expect.objectContaining(expected[0]), - expect.objectContaining(expected[1]), - expect.objectContaining(expected[2]), - expect.objectContaining(expected[3]) - ]) - ) + expect(output).toMatchObject(expect.arrayContaining(expected)) }) function content(filepath) { diff --git a/tests/commands/database/export.test.js b/tests/commands/database/export.test.js index 04fba3d36e..f121a1453b 100644 --- a/tests/commands/database/export.test.js +++ b/tests/commands/database/export.test.js @@ -5,13 +5,14 @@ const dayjs = require('dayjs') beforeEach(() => { fs.emptyDirSync('tests/__data__/output') + fs.mkdirSync('tests/__data__/output/database') fs.copyFileSync( 'tests/__data__/input/database/db_export.streams.db', - 'tests/__data__/output/streams.db' + 'tests/__data__/output/database/streams.db' ) const stdout = execSync( - 'DB_DIR=tests/__data__/output DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.api npm run db:export', + 'DB_DIR=tests/__data__/output/database DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output/.api npm run db:export', { encoding: 'utf8' } ) }) diff --git a/tests/commands/database/matrix.test.js b/tests/commands/database/matrix.test.js index 1d2ae7a342..1266584a24 100644 --- a/tests/commands/database/matrix.test.js +++ b/tests/commands/database/matrix.test.js @@ -4,15 +4,15 @@ const { execSync } = require('child_process') beforeEach(() => { fs.emptyDirSync('tests/__data__/output') - + fs.mkdirSync('tests/__data__/output/database') fs.copyFileSync( 'tests/__data__/input/database/db_matrix.streams.db', - 'tests/__data__/output/streams.db' + 'tests/__data__/output/database/streams.db' ) }) it('can create valid matrix', () => { - const result = execSync('DB_DIR=tests/__data__/output npm run db:matrix', { + const result = execSync('DB_DIR=tests/__data__/output/database npm run db:matrix', { encoding: 'utf8' }) expect(result).toBe( diff --git a/tests/commands/database/update.test.js b/tests/commands/database/update.test.js index 3701dbaa10..a0cc342c06 100644 --- a/tests/commands/database/update.test.js +++ b/tests/commands/database/update.test.js @@ -4,15 +4,16 @@ const path = require('path') beforeEach(() => { fs.emptyDirSync('tests/__data__/output') + fs.mkdirSync('tests/__data__/output/database') fs.copyFileSync( 'tests/__data__/input/database/db_update.streams.db', - 'tests/__data__/output/streams.db' + 'tests/__data__/output/database/streams.db' ) }) it('can save results', () => { const stdout = execSync( - 'DB_DIR=tests/__data__/output LOGS_DIR=tests/__data__/input/logs/cluster/load npm run db:update', + 'DB_DIR=tests/__data__/output/database LOGS_DIR=tests/__data__/input/logs/cluster/load npm run db:update', { encoding: 'utf8' } ) expect(stdout).toEqual(` @@ -31,7 +32,7 @@ removed 1 duplicates done `) - expect(content('tests/__data__/output/streams.db')).toEqual( + expect(content('tests/__data__/output/database/streams.db')).toEqual( content('tests/__data__/expected/database/db_update.streams.db') ) })