mirror of
https://github.com/iptv-org/epg.git
synced 2025-05-09 16:40:07 -04:00
Throw an error if no programs are found
This commit is contained in:
parent
b0a8002b78
commit
26fc86dc02
3 changed files with 44 additions and 4 deletions
|
@ -11,6 +11,7 @@ async function main() {
|
|||
await db.programs.load()
|
||||
await api.channels.load()
|
||||
|
||||
let total = 0
|
||||
const grouped = groupByGroup(await loadQueue())
|
||||
for (const key in grouped) {
|
||||
let channels = {}
|
||||
|
@ -35,6 +36,7 @@ async function main() {
|
|||
channels = Object.values(channels)
|
||||
channels = _.sortBy(channels, 'xmltv_id')
|
||||
programs = _.sortBy(programs, ['channel', 'start'])
|
||||
total += programs.length
|
||||
|
||||
const filepath = `${PUBLIC_DIR}/guides/${key}.epg.xml`
|
||||
logger.info(`Creating "${filepath}"...`)
|
||||
|
@ -42,7 +44,12 @@ async function main() {
|
|||
await file.create(filepath, output)
|
||||
}
|
||||
|
||||
logger.info(`Done`)
|
||||
if (!total) {
|
||||
logger.error('\nError: No programs found')
|
||||
process.exit(1)
|
||||
} else {
|
||||
logger.info(`Done`)
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
|
|
0
tests/__data__/input/database/no-programs.db
Normal file
0
tests/__data__/input/database/no-programs.db
Normal file
|
@ -5,15 +5,15 @@ const path = require('path')
|
|||
beforeEach(() => {
|
||||
fs.emptyDirSync('tests/__data__/output')
|
||||
fs.copyFileSync('tests/__data__/input/database/queue.db', 'tests/__data__/output/queue.db')
|
||||
fs.copyFileSync('tests/__data__/input/database/programs.db', 'tests/__data__/output/programs.db')
|
||||
})
|
||||
|
||||
it('can generate /guides', () => {
|
||||
fs.copyFileSync('tests/__data__/input/database/programs.db', 'tests/__data__/output/programs.db')
|
||||
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' }
|
||||
)
|
||||
})
|
||||
|
||||
it('can generate /guides', () => {
|
||||
expect(content('tests/__data__/output/guides/fr/chaines-tv.orange.fr.epg.xml')).toBe(
|
||||
content('tests/__data__/expected/guides/fr/chaines-tv.orange.fr.epg.xml')
|
||||
)
|
||||
|
@ -23,6 +23,39 @@ it('can generate /guides', () => {
|
|||
)
|
||||
})
|
||||
|
||||
it('will terminate process if programs not found', () => {
|
||||
fs.copyFileSync(
|
||||
'tests/__data__/input/database/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' }
|
||||
)
|
||||
console.log(stdout)
|
||||
process.exit(1)
|
||||
} catch (err) {
|
||||
expect(err.status).toBe(1)
|
||||
expect(err.stdout).toBe(`
|
||||
> guides:update
|
||||
> node scripts/commands/guides/update.js
|
||||
|
||||
Generating guides/...
|
||||
Loading \"database/programs.db\"...
|
||||
Loading queue...
|
||||
Creating \"tests/__data__/output/guides/us/directv.com.epg.xml\"...
|
||||
Creating \"tests/__data__/output/guides/fr/chaines-tv.orange.fr.epg.xml\"...
|
||||
Creating \"tests/__data__/output/guides/bh/chaines-tv.orange.fr.epg.xml\"...
|
||||
Creating \"tests/__data__/output/guides/ge/magticom.ge.epg.xml\"...
|
||||
Creating \"tests/__data__/output/guides/ru/yandex.ru.epg.xml\"...
|
||||
Creating \"tests/__data__/output/guides/zw/dstv.com.epg.xml\"...
|
||||
|
||||
Error: No programs found
|
||||
`)
|
||||
}
|
||||
})
|
||||
|
||||
function content(filepath) {
|
||||
const data = fs.readFileSync(path.resolve(filepath), {
|
||||
encoding: 'utf8'
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue