Files
epg/tests/commands/load-cluster.test.js

59 lines
1.6 KiB
JavaScript
Raw Normal View History

2022-01-06 16:01:23 +03:00
const fs = require('fs')
const path = require('path')
2022-01-21 19:25:50 +03:00
const dayjs = require('dayjs')
const utc = require('dayjs/plugin/utc')
2022-01-06 16:01:23 +03:00
const { execSync } = require('child_process')
2022-01-21 19:25:50 +03:00
dayjs.extend(utc)
2022-01-06 16:01:23 +03:00
beforeEach(() => {
2022-01-16 01:33:40 +03:00
fs.rmdirSync('tests/__data__/temp', { recursive: true })
2022-01-06 16:01:23 +03:00
fs.rmdirSync('tests/__data__/output', { recursive: true })
fs.mkdirSync('tests/__data__/output')
2022-01-10 15:11:30 +03:00
fs.mkdirSync('tests/__data__/temp/database', { recursive: true })
fs.copyFileSync(
'tests/__data__/input/database/channels.db',
'tests/__data__/temp/database/channels.db'
)
2022-01-06 16:01:23 +03:00
2022-01-10 00:34:05 +03:00
execSync(
2022-01-16 01:33:40 +03:00
'DB_DIR=tests/__data__/temp/database LOGS_DIR=tests/__data__/output/logs node scripts/commands/load-cluster.js --cluster-id=1 --timeout=10000',
2022-01-06 16:01:23 +03:00
{ encoding: 'utf8' }
)
2022-01-10 00:34:05 +03:00
})
it('can load cluster', () => {
2022-01-14 17:52:44 +03:00
const output = content('tests/__data__/output/logs/load-cluster/cluster_1.log')
2022-01-21 19:25:50 +03:00
expect(Object.keys(output[0]).sort()).toEqual(['channel', 'date', 'error', 'programs'])
2022-01-14 17:52:44 +03:00
expect(output[0]).toMatchObject({
2022-01-21 19:25:50 +03:00
channel: {
_id: '0Wefq0oMR3feCcuY',
logo: 'https://example.com/logo.png'
},
date: dayjs.utc().startOf('d').format(),
2022-01-21 18:00:33 +03:00
error: null
2022-01-14 17:52:44 +03:00
})
2022-01-10 00:34:05 +03:00
2022-01-14 17:52:44 +03:00
expect(output[1]).toMatchObject({
2022-01-21 19:25:50 +03:00
channel: {
_id: '1XzrxNkSF2AQNBrT',
logo: 'https://www.magticom.ge/images/channels/MjAxOC8wOS8xMC9lZmJhNWU5Yy0yMmNiLTRkMTAtOWY5Ny01ODM0MzY0ZTg0MmEuanBn.jpg'
}
2022-01-14 17:52:44 +03:00
})
2022-01-06 16:01:23 +03:00
})
2022-01-14 17:52:44 +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)
})
}