Files
epg/tests/commands/guides/update.test.js

71 lines
2.1 KiB
JavaScript
Raw Normal View History

2022-02-26 23:21:44 +03:00
const { execSync } = require('child_process')
const fs = require('fs-extra')
const path = require('path')
2022-03-15 15:26:24 +03:00
const glob = require('glob')
2022-02-26 23:21:44 +03:00
beforeEach(() => {
fs.emptyDirSync('tests/__data__/output')
2022-04-16 23:05:58 +03:00
fs.copyFileSync(
'tests/__data__/input/database/update-guides/queue.db',
'tests/__data__/output/queue.db'
)
})
2022-02-26 23:21:44 +03:00
it('can generate /guides', () => {
2022-04-16 23:05:58 +03:00
fs.copyFileSync(
'tests/__data__/input/database/update-guides/programs.db',
'tests/__data__/output/programs.db'
)
2022-02-26 23:21:44 +03:00
const stdout = execSync(
2022-05-09 16:21:50 +03:00
'DB_DIR=tests/__data__/output DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output CURR_DATE=2022-05-05 npm run guides:update',
2022-02-26 23:21:44 +03:00
{ encoding: 'utf8' }
)
2022-10-19 23:08:34 +03:00
const uncompressed = glob
.sync('tests/__data__/expected/guides/**/*.epg.xml')
.map(f => f.replace('tests/__data__/expected/', ''))
uncompressed.forEach(filepath => {
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
})
2022-03-15 15:26:24 +03:00
const compressed = glob
2022-08-25 00:08:53 +03:00
.sync('tests/__data__/expected/guides/**/*.epg.xml.gz')
2022-03-15 15:26:24 +03:00
.map(f => f.replace('tests/__data__/expected/', ''))
compressed.forEach(filepath => {
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
})
2022-10-06 14:12:53 +03:00
const json = glob
.sync('tests/__data__/expected/guides/**/*.json')
.map(f => f.replace('tests/__data__/expected/', ''))
json.forEach(filepath => {
expect(content(`output/${filepath}`), filepath).toBe(content(`expected/${filepath}`))
})
2022-02-26 23:21:44 +03:00
})
it('will terminate process if programs not found', () => {
fs.copyFileSync(
2022-04-16 23:05:58 +03:00
'tests/__data__/input/database/update-guides/no-programs.db',
'tests/__data__/output/programs.db'
)
try {
const stdout = execSync(
'DB_DIR=tests/__data__/output DATA_DIR=tests/__data__/input/data PUBLIC_DIR=tests/__data__/output npm run guides:update',
{ encoding: 'utf8' }
)
process.exit(1)
} catch (err) {
expect(err.status).toBe(1)
2022-10-19 23:08:34 +03:00
expect(err.stdout.includes('Error: No programs found')).toBe(true)
}
})
2022-02-26 23:21:44 +03:00
function content(filepath) {
2022-03-15 15:26:24 +03:00
return fs.readFileSync(`tests/__data__/${filepath}`, {
2022-02-26 23:21:44 +03:00
encoding: 'utf8'
})
}