From 3e4a24b42fba67b7ab71c0da523c83d91ee085fd Mon Sep 17 00:00:00 2001 From: Aleksandr Statciuk Date: Fri, 14 Jan 2022 17:55:51 +0300 Subject: [PATCH] Update save-results.js --- scripts/commands/save-results.js | 1 + tests/commands/save-results.test.js | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/scripts/commands/save-results.js b/scripts/commands/save-results.js index a1f9f582..c4e4fd5b 100644 --- a/scripts/commands/save-results.js +++ b/scripts/commands/save-results.js @@ -12,6 +12,7 @@ async function main() { const programs = result.programs.map(program => { program.site = result.site program.country = result.country + program.gid = result.gid return program }) diff --git a/tests/commands/save-results.test.js b/tests/commands/save-results.test.js index fc8f8c7e..2cb0e2df 100644 --- a/tests/commands/save-results.test.js +++ b/tests/commands/save-results.test.js @@ -13,18 +13,15 @@ beforeEach(() => { }) it('can save results to database', () => { - const output = fs.readFileSync(path.resolve('tests/__data__/output/database/programs.db'), { - encoding: 'utf8' - }) - const lines = output.split('\n') - const parsed = JSON.parse(lines[0]) + const output = content('tests/__data__/output/database/programs.db') - expect(Object.keys(parsed).sort()).toEqual([ + expect(Object.keys(output[0]).sort()).toEqual([ '_id', 'category', 'channel', 'country', 'description', + 'gid', 'icon', 'lang', 'site', @@ -33,3 +30,16 @@ it('can save results to database', () => { 'title' ]) }) + +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) + }) +}