From 1b63609b7d769df29dd8c8f1d755be43cf95f56f Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Sun, 30 Jan 2022 20:54:09 +0300 Subject: [PATCH] Update save-results.js --- scripts/commands/save-results.js | 11 +---------- .../expected/database/queue-with-errors.db | 4 ++++ tests/__data__/input/database/queue.db | 8 ++++---- tests/commands/save-results.test.js | 17 ++--------------- 4 files changed, 11 insertions(+), 29 deletions(-) create mode 100644 tests/__data__/expected/database/queue-with-errors.db diff --git a/scripts/commands/save-results.js b/scripts/commands/save-results.js index baec0a31..53191701 100644 --- a/scripts/commands/save-results.js +++ b/scripts/commands/save-results.js @@ -4,8 +4,6 @@ const _ = require('lodash') const LOGS_DIR = process.env.LOGS_DIR || 'scripts/logs' async function main() { - const errorsLog = `${LOGS_DIR}/errors.log` - await file.create(errorsLog) await db.queue.load() await db.programs.load() await db.programs.reset() @@ -34,15 +32,8 @@ async function main() { await db.queue.update( { _id: result.channel._id }, - { $set: { programCount: result.programs.length } } + { $set: { programCount: result.programs.length, error: result.error } } ) - - if (result.error) { - await file.append( - errorsLog, - JSON.stringify({ ...result.channel, date: result.date, error: result.error }) + '\n' - ) - } } } diff --git a/tests/__data__/expected/database/queue-with-errors.db b/tests/__data__/expected/database/queue-with-errors.db new file mode 100644 index 00000000..af79b1f8 --- /dev/null +++ b/tests/__data__/expected/database/queue-with-errors.db @@ -0,0 +1,4 @@ +{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"cluster_id":84,"programCount":0,"error":"Invalid header value char","_id":"00AluKCrCnfgrl8W"} +{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr","bh/chaines-tv.orange.fr"],"cluster_id":1,"programCount":23,"error":null,"_id":"0Wefq0oMR3feCcuY"} +{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"programCount":0,"error":null,"_id":"1XzrxNkSF2AQNBrT"} +{"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"cluster_id":120,"programCount":14,"error":null,"_id":"1lnhXpN7g0ER5XwN"} diff --git a/tests/__data__/input/database/queue.db b/tests/__data__/input/database/queue.db index 87a22b74..57f31f7e 100644 --- a/tests/__data__/input/database/queue.db +++ b/tests/__data__/input/database/queue.db @@ -1,4 +1,4 @@ -{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"cluster_id":84,"programCount":0,"_id":"00AluKCrCnfgrl8W"} -{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr", "bh/chaines-tv.orange.fr"],"cluster_id":1,"programCount":32,"_id":"0Wefq0oMR3feCcuY"} -{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"programCount":0,"_id":"1XzrxNkSF2AQNBrT"} -{"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"cluster_id":120,"programCount":14,"_id":"1lnhXpN7g0ER5XwN"} +{"lang":"en","xmltv_id":"BravoEast.us","site_id":"237","site":"directv.com","configPath":"sites/directv.com/directv.com.config.js","groups":["us/directv.com"],"cluster_id":84,"programCount":0,"error":"Invalid header value char","_id":"00AluKCrCnfgrl8W"} +{"lang":"fr","xmltv_id":"CNNInternationalEurope.us","site_id":"53","site":"chaines-tv.orange.fr","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["fr/chaines-tv.orange.fr", "bh/chaines-tv.orange.fr"],"cluster_id":1,"programCount":32,"error":null,"_id":"0Wefq0oMR3feCcuY"} +{"lang":"ru","xmltv_id":"CNNInternationalEurope.us","site_id":"140","site":"magticom.ge","configPath":"tests/__data__/input/sites/example.com.config.js","groups":["ge/magticom.ge"],"cluster_id":1,"programCount":0,"error":null,"_id":"1XzrxNkSF2AQNBrT"} +{"lang":"en","xmltv_id":"MNetMovies2.za","site_id":"404a052b-3dea-4cac-a19c-de9a7d6f191d#MAP","site":"dstv.com","configPath":"sites/dstv.com/dstv.com.config.js","groups":["zw/dstv.com"],"cluster_id":120,"programCount":14,"error":null,"_id":"1lnhXpN7g0ER5XwN"} diff --git a/tests/commands/save-results.test.js b/tests/commands/save-results.test.js index 3b5957e4..ff9a5db0 100644 --- a/tests/commands/save-results.test.js +++ b/tests/commands/save-results.test.js @@ -36,22 +36,9 @@ it('can save programs to database', () => { it('can update queue', () => { const output = content('tests/__data__/output/database/queue.db') + const expected = content('tests/__data__/expected/database/queue-with-errors.db') - expect(output[1]).toMatchObject({ - _id: '0Wefq0oMR3feCcuY', - programCount: 23 - }) -}) - -it('can save errors', () => { - const output = content('tests/__data__/input/logs/errors.log') - - expect(output[0]).toMatchObject({ - _id: '00AluKCrCnfgrl8W', - site: 'directv.com', - xmltv_id: 'BravoEast.us', - error: 'Invalid header value char' - }) + expect(output).toEqual(expected) }) function content(filepath) {