diff --git a/tests/commands/api/update.test.js b/tests/commands/api/update.test.js deleted file mode 100644 index 0ac1313b..00000000 --- a/tests/commands/api/update.test.js +++ /dev/null @@ -1,26 +0,0 @@ -const { execSync } = require('child_process') -const fs = require('fs-extra') -const path = require('path') - -beforeEach(() => { - fs.emptyDirSync('tests/__data__/output') - - const stdout = execSync( - 'LOGS_DIR=tests/__data__/input/logs OUTPUT_DIR=tests/__data__/output/api npm run api:update', - { encoding: 'utf8' } - ) -}) - -it('can generate guides.json', () => { - expect(content('tests/__data__/output/api/guides.json')).toBe( - content('tests/__data__/expected/api/guides.json') - ) -}) - -function content(filepath) { - const data = fs.readFileSync(path.resolve(filepath), { - encoding: 'utf8' - }) - - return JSON.stringify(data) -} diff --git a/tests/commands/cluster/load.test.js b/tests/commands/cluster/load.test.js deleted file mode 100644 index cbce0c5f..00000000 --- a/tests/commands/cluster/load.test.js +++ /dev/null @@ -1,37 +0,0 @@ -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/queue.db', 'tests/__data__/output/queue.db') -}) - -it('can load cluster and will terminate process if programs not found', () => { - try { - execSync( - 'DB_DIR=tests/__data__/output LOGS_DIR=tests/__data__/output/logs npm run cluster:load -- --cluster-id=1 --timeout=10000', - { encoding: 'utf8' } - ) - process.exit(1) - } catch (err) { - expect(err.status).toBe(1) - expect(err.stdout.includes('Error: No programs found')).toBe(true) - expect(content('tests/__data__/output/logs/cluster/load/cluster_1.log')).toEqual( - content('tests/__data__/expected/logs/cluster/load/cluster_1.log') - ) - } -}) - -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/guides/update.test.js b/tests/commands/guides/update.test.js deleted file mode 100644 index 304706eb..00000000 --- a/tests/commands/guides/update.test.js +++ /dev/null @@ -1,49 +0,0 @@ -const { execSync } = require('child_process') -const fs = require('fs-extra') -const path = require('path') -const glob = require('glob') - -beforeEach(() => { - fs.emptyDirSync('tests/__data__/output') - fs.copyFileSync( - 'tests/__data__/input/database/update-guides/programs.db', - 'tests/__data__/output/programs.db' - ) - fs.copyFileSync( - 'tests/__data__/input/database/update-guides/queue.db', - 'tests/__data__/output/queue.db' - ) -}) - -it('can generate /guides', () => { - const stdout = execSync( - 'DB_DIR=tests/__data__/output LOGS_DIR=tests/__data__/output/logs DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output CURR_DATE=2022-10-20 npm run guides:update', - { encoding: 'utf8' } - ) - - const uncompressed = glob - .sync('tests/__data__/expected/guides/**/*.xml') - .map(f => f.replace('tests/__data__/expected/', '')) - - uncompressed.forEach(filepath => { - expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`)) - }) - - const compressed = glob - .sync('tests/__data__/expected/guides/**/*.xml.gz') - .map(f => f.replace('tests/__data__/expected/', '')) - - compressed.forEach(filepath => { - expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`)) - }) - - expect(content('output/logs/guides/update.log')).toEqual( - content('expected/logs/guides/update.log') - ) -}) - -function content(filepath) { - return fs.readFileSync(`tests/__data__/${filepath}`, { - encoding: 'utf8' - }) -} diff --git a/tests/commands/programs/save.test.js b/tests/commands/programs/save.test.js deleted file mode 100644 index dad307c8..00000000 --- a/tests/commands/programs/save.test.js +++ /dev/null @@ -1,48 +0,0 @@ -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/queue.db', 'tests/__data__/output/queue.db') - - const stdout = execSync( - 'DB_DIR=tests/__data__/output LOGS_DIR=tests/__data__/input/logs npm run programs:save', - { encoding: 'utf8' } - ) -}) - -it('can save programs to database', () => { - let output = content('tests/__data__/output/programs.db') - let expected = content('tests/__data__/expected/database/programs.db') - - output = output.map(i => { - i._id = null - return i - }) - expected = expected.map(i => { - i._id = null - return i - }) - - expect(output).toEqual(expected) -}) - -it('can update queue', () => { - expect(content('tests/__data__/output/queue.db')).toEqual( - content('tests/__data__/expected/database/queue-with-errors.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) - }) -} diff --git a/tests/commands/queue/create.test.js b/tests/commands/queue/create.test.js deleted file mode 100644 index efaba63f..00000000 --- a/tests/commands/queue/create.test.js +++ /dev/null @@ -1,48 +0,0 @@ -const { execSync } = require('child_process') -const fs = require('fs-extra') -const path = require('path') - -beforeEach(() => { - fs.emptyDirSync('tests/__data__/output') - - const stdout = execSync( - 'DB_DIR=tests/__data__/output/database CHANNELS_PATH=tests/__data__/input/sites/example.com_*.channels.xml DATA_DIR=tests/__data__/input/data CURR_DATE=2022-12-29 npm run queue:create -- --max-clusters=1', - { encoding: 'utf8' } - ) -}) - -it('can create queue', () => { - let output = content('tests/__data__/output/database/queue.db') - let expected = content('tests/__data__/expected/database/create-queue/queue.db') - - output = output.map(i => { - i._id = null - return i - }) - expected = expected.map(i => { - i._id = null - return i - }) - - expect(output).toEqual( - expect.arrayContaining([ - expect.objectContaining(expected[0]), - expect.objectContaining(expected[1]), - expect.objectContaining(expected[2]), - expect.objectContaining(expected[3]) - ]) - ) -}) - -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/readme/update.test.js b/tests/commands/readme/update.test.js deleted file mode 100644 index 739fa772..00000000 --- a/tests/commands/readme/update.test.js +++ /dev/null @@ -1,26 +0,0 @@ -const { execSync } = require('child_process') -const fs = require('fs-extra') -const path = require('path') - -beforeEach(() => { - fs.emptyDirSync('tests/__data__/output') - - const stdout = execSync( - 'LOGS_DIR=tests/__data__/input/logs DATA_DIR=tests/__data__/input/data npm run readme:update -- --config=tests/__data__/input/readme.json', - { encoding: 'utf8' } - ) -}) - -it('can update readme.md', () => { - expect(content('tests/__data__/output/readme.md')).toBe( - content('tests/__data__/expected/_readme.md') - ) -}) - -function content(filepath) { - const data = fs.readFileSync(path.resolve(filepath), { - encoding: 'utf8' - }) - - return JSON.stringify(data) -}