Files
epg/tests/commands/queue/create.test.js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2022-01-06 12:59:37 +03:00
const { execSync } = require('child_process')
2022-02-26 23:21:44 +03:00
const fs = require('fs-extra')
const path = require('path')
2022-01-06 12:59:37 +03:00
beforeEach(() => {
2022-02-26 23:21:44 +03:00
fs.emptyDirSync('tests/__data__/output')
2022-01-06 12:59:37 +03:00
2022-01-20 23:20:57 +03:00
const stdout = execSync(
2022-02-27 18:04:30 +03:00
'DB_DIR=tests/__data__/output/database LOGS_DIR=tests/__data__/output/logs CHANNELS_PATH=tests/__data__/input/sites/example.com_ca.channels.xml npm run queue:create -- --max-clusters=1 --days=2',
2022-01-06 12:59:37 +03:00
{ encoding: 'utf8' }
)
2022-01-10 00:34:05 +03:00
})
2022-01-06 12:59:37 +03:00
2022-01-30 01:01:15 +03:00
it('can create queue', () => {
2022-01-30 02:03:40 +03:00
let output = content('tests/__data__/output/database/queue.db')
let expected = content('tests/__data__/expected/database/queue.db')
output = output.map(i => {
i._id = null
2022-01-30 22:55:48 +03:00
i.date = null
2022-01-30 02:03:40 +03:00
return i
})
expected = expected.map(i => {
i._id = null
2022-01-30 22:55:48 +03:00
i.date = null
2022-01-30 02:03:40 +03:00
return i
})
2022-01-10 00:34:05 +03:00
2022-01-30 00:01:03 +03:00
expect(output).toEqual(
expect.arrayContaining([
2022-01-30 02:03:40 +03:00
expect.objectContaining(expected[0]),
2022-01-31 05:23:39 +03:00
expect.objectContaining(expected[1])
2022-01-30 00:01:03 +03:00
])
)
2022-01-06 12:59:37 +03:00
})
2022-01-10 00:34:05 +03:00
function content(filepath) {
const data = fs.readFileSync(path.resolve(filepath), {
encoding: 'utf8'
})
2022-01-14 17:29:21 +03:00
return data
.split('\n')
.filter(l => l)
.map(l => {
return JSON.parse(l)
})
2022-01-10 00:34:05 +03:00
}