diff --git a/scripts/commands/guides/update.js b/scripts/commands/guides/update.js index d40a28aa..f7de932e 100644 --- a/scripts/commands/guides/update.js +++ b/scripts/commands/guides/update.js @@ -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() diff --git a/tests/__data__/input/database/no-programs.db b/tests/__data__/input/database/no-programs.db new file mode 100644 index 00000000..e69de29b diff --git a/tests/commands/guides/update.test.js b/tests/commands/guides/update.test.js index 98c8455a..665bbf5b 100644 --- a/tests/commands/guides/update.test.js +++ b/tests/commands/guides/update.test.js @@ -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'