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

49 lines
1.2 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(
2023-01-10 12:41:22 +03:00
'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',
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')
2022-04-16 23:06:03 +03:00
let expected = content('tests/__data__/expected/database/create-queue/queue.db')
2022-01-30 02:03:40 +03:00
output = output.map(i => {
i._id = null
return i
})
expected = expected.map(i => {
i._id = null
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]),
2023-01-10 12:41:22 +03:00
expect.objectContaining(expected[1]),
expect.objectContaining(expected[2]),
expect.objectContaining(expected[3])
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
}