2022-01-09 18:36:39 +03:00
|
|
|
const fs = require('fs')
|
|
|
|
|
const path = require('path')
|
|
|
|
|
const { execSync } = require('child_process')
|
|
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
|
fs.rmdirSync('tests/__data__/output', { recursive: true })
|
|
|
|
|
fs.mkdirSync('tests/__data__/output')
|
2022-01-16 15:31:06 +03:00
|
|
|
fs.mkdirSync('tests/__data__/output/database', { recursive: true })
|
|
|
|
|
|
|
|
|
|
fs.copyFileSync(
|
|
|
|
|
'tests/__data__/input/database/channels.db',
|
|
|
|
|
'tests/__data__/output/database/channels.db'
|
|
|
|
|
)
|
2022-01-09 18:36:39 +03:00
|
|
|
|
2022-01-21 19:42:27 +03:00
|
|
|
const stdout = execSync(
|
2022-01-14 16:38:29 +03:00
|
|
|
'DB_DIR=tests/__data__/output/database LOGS_DIR=tests/__data__/input/logs node scripts/commands/save-results.js',
|
2022-01-09 18:36:39 +03:00
|
|
|
{ encoding: 'utf8' }
|
|
|
|
|
)
|
2022-01-10 00:34:05 +03:00
|
|
|
})
|
|
|
|
|
|
2022-01-21 19:42:27 +03:00
|
|
|
it('can save results', () => {
|
|
|
|
|
const programs = content('tests/__data__/output/database/programs.db')
|
2022-01-10 00:34:05 +03:00
|
|
|
|
2022-01-21 19:42:27 +03:00
|
|
|
expect(Object.keys(programs[0]).sort()).toEqual([
|
|
|
|
|
'_cid',
|
2022-01-09 19:23:57 +03:00
|
|
|
'_id',
|
|
|
|
|
'category',
|
|
|
|
|
'channel',
|
|
|
|
|
'description',
|
2022-01-19 01:57:43 +03:00
|
|
|
'episode',
|
2022-01-09 19:23:57 +03:00
|
|
|
'icon',
|
|
|
|
|
'lang',
|
2022-01-19 01:57:43 +03:00
|
|
|
'season',
|
2022-01-09 19:23:57 +03:00
|
|
|
'start',
|
|
|
|
|
'stop',
|
|
|
|
|
'title'
|
|
|
|
|
])
|
2022-01-16 15:31:06 +03:00
|
|
|
|
2022-01-21 19:42:27 +03:00
|
|
|
expect(programs[0]).toMatchObject({
|
|
|
|
|
_cid: '0Wefq0oMR3feCcuY'
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const channels = content('tests/__data__/output/database/channels.db')
|
2022-01-16 15:31:06 +03:00
|
|
|
|
2022-01-21 19:42:27 +03:00
|
|
|
expect(channels[1]).toMatchObject({
|
2022-01-16 15:31:06 +03:00
|
|
|
_id: '0Wefq0oMR3feCcuY',
|
|
|
|
|
logo: 'https://example.com/logo.png'
|
|
|
|
|
})
|
2022-01-21 19:42:27 +03:00
|
|
|
|
|
|
|
|
const errors = content('tests/__data__/input/logs/errors.log')
|
|
|
|
|
|
|
|
|
|
expect(errors[0]).toMatchObject({
|
|
|
|
|
_id: '00AluKCrCnfgrl8W',
|
|
|
|
|
site: 'directv.com',
|
|
|
|
|
xmltv_id: 'BravoEast.us',
|
|
|
|
|
error: 'Invalid header value char'
|
|
|
|
|
})
|
2022-01-09 18:36:39 +03:00
|
|
|
})
|
2022-01-14 17:55:51 +03:00
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
})
|
|
|
|
|
}
|