From 4fcd718b606b607d17184a1ecef82a30c79b8c0d Mon Sep 17 00:00:00 2001 From: Brandon Marshall Date: Fri, 5 Jan 2024 08:45:54 -0800 Subject: [PATCH] PR Changes --- bulk-update/reporter/console-reporter.js | 4 +- bulk-update/reporter/excel-reporter.js | 4 +- bulk-update/reporter/reporter.js | 2 +- ...orter.text.js => console-reporter.test.js} | 20 +++++-- .../reporter/excel-reporter.test.js | 59 ++++--------------- test/bulk-update/reporter/reporter.test.js | 32 ++++++++-- 6 files changed, 58 insertions(+), 63 deletions(-) rename test/bulk-update/reporter/{console-reporter.text.js => console-reporter.test.js} (57%) diff --git a/bulk-update/reporter/console-reporter.js b/bulk-update/reporter/console-reporter.js index 5d9ef37..75b0a3a 100644 --- a/bulk-update/reporter/console-reporter.js +++ b/bulk-update/reporter/console-reporter.js @@ -28,8 +28,8 @@ class ConsoleReporter extends BaseReporter { * Calculates the totals for each topic and status. * @returns {Object} - The totals object. */ - calculateTotals() { - const totals = super.calculateTotals(); + generateTotals() { + const totals = super.generateTotals(); this.console.table(totals); diff --git a/bulk-update/reporter/excel-reporter.js b/bulk-update/reporter/excel-reporter.js index 9281b54..238d79b 100644 --- a/bulk-update/reporter/excel-reporter.js +++ b/bulk-update/reporter/excel-reporter.js @@ -52,8 +52,8 @@ class ExcelReporter extends BaseReporter { * Updates the totals sheet for each topic and status. * @returns {Object} - The totals object. */ - calculateTotals() { - const totals = super.calculateTotals(); + generateTotals() { + const totals = super.generateTotals(); const totalsSheet = this.workbook.Sheets.Totals; const data = []; Object.entries(totals).forEach(([topic, statusCount]) => { diff --git a/bulk-update/reporter/reporter.js b/bulk-update/reporter/reporter.js index 9bbbabf..7b774c4 100644 --- a/bulk-update/reporter/reporter.js +++ b/bulk-update/reporter/reporter.js @@ -31,7 +31,7 @@ class BaseReporter { * Calculates the totals for each topic and status. * @returns {Object} - The totals object. */ - calculateTotals() { + generateTotals() { const totals = {}; Object.keys(this.logs).forEach((topic) => { diff --git a/test/bulk-update/reporter/console-reporter.text.js b/test/bulk-update/reporter/console-reporter.test.js similarity index 57% rename from test/bulk-update/reporter/console-reporter.text.js rename to test/bulk-update/reporter/console-reporter.test.js index 3f45aa8..e489b76 100644 --- a/test/bulk-update/reporter/console-reporter.text.js +++ b/test/bulk-update/reporter/console-reporter.test.js @@ -13,16 +13,26 @@ describe('ConsoleReporter', () => { console.table.restore(); }); - it('should log a message and update the report', () => { + it('logs a message', () => { const reporter = new ConsoleReporter(); - reporter.log('topic', 'status', 'message', 'arg1', 'arg2'); + reporter.log('topic', 'status', 'logs message 1', 'arg1', 'arg2'); expect(console.log.calledOnce).to.be.true; - expect(console.log.calledWith('topic - status: message', 'arg1', 'arg2')).to.be.true; + expect(console.log.calledWith('topic - status: logs message 1', 'arg1', 'arg2')).to.be.true; }); - it('should calculate the totals for each topic and status', () => { + it('logs multiple messages', () => { + const reporter = new ConsoleReporter(); + + reporter.log('topic', 'status', 'logs multiple message 1', 'arg1', 'arg2'); + reporter.log('topic', 'status', 'logs multiple message 2', 'arg1', 'arg2'); + + expect(console.log.calledTwice).to.be.true; + expect(console.log.calledWith('topic - status: logs multiple message 2', 'arg1', 'arg2')).to.be.true; + }); + + it('calculates the totals for each topic and status', () => { const reporter = new ConsoleReporter(); reporter.log('topic1', 'status1', 'message1'); @@ -31,7 +41,7 @@ describe('ConsoleReporter', () => { reporter.log('topic2', 'status2', 'message4'); reporter.log('topic2', 'status2', 'message5'); - reporter.calculateTotals(); + reporter.generateTotals(); expect(console.table.calledWith({ topic1: { diff --git a/test/bulk-update/reporter/excel-reporter.test.js b/test/bulk-update/reporter/excel-reporter.test.js index e08edcb..7d6c7b6 100644 --- a/test/bulk-update/reporter/excel-reporter.test.js +++ b/test/bulk-update/reporter/excel-reporter.test.js @@ -22,14 +22,14 @@ describe('ExcelReporter', () => { sandbox.restore(); }); - it('should create a new workbook', () => { + it('creates a new workbook', () => { const reporter = new ExcelReporter(); expect(reporter).is.not.undefined; expect(xlsx.utils.book_new.calledOnce).to.be.true; }); - it('should append log to sheet', () => { + it('appends log to sheet', () => { const reporter = new ExcelReporter(); reporter.log('topic', 'status', 'message', 'arg1', 'arg2'); @@ -38,61 +38,20 @@ describe('ExcelReporter', () => { }); }); - describe('Check report', () => { - it('should log a message', () => { - const reporter = new ExcelReporter(); - - reporter.log('topic', 'status', 'message', 'arg1', 'arg2'); - - const report = reporter.getReport(); - - expect(report.logs.topic).to.have.lengthOf(1); - expect(report.logs.topic[0]).to.deep.equal({ - status: 'status', - message: 'message', - 0: 'arg1', - 1: 'arg2', - }); - }); - - it('should calculate the totals for each topic and status', () => { - const reporter = new ExcelReporter(); - - reporter.log('topic1', 'status1', 'message1'); - reporter.log('topic1', 'status2', 'message2'); - reporter.log('topic2', 'status1', 'message3'); - reporter.log('topic2', 'status2', 'message4'); - reporter.log('topic2', 'status2', 'message5'); - - const totals = reporter.calculateTotals(); - - expect(totals).to.deep.equal({ - topic1: { - status1: 1, - status2: 1, - }, - topic2: { - status1: 1, - status2: 2, - }, - }); - }); - }); - describe('Check XLSX file and format', () => { const filepath = `${pathname}test.xlsx`; - it('should initialize with the correct properties', () => { + it('initializes with the correct properties', () => { const reporter = new ExcelReporter(filepath); expect(reporter.filepath).to.equal(filepath); expect(reporter.workbook).is.not.undefined; }); - it('should save the report to the specified filepath', () => { + it('saves the report to the specified filepath', () => { const reporter = new ExcelReporter(filepath); reporter.log('topic', 'status', 'message', 'arg1', 'arg2'); - reporter.calculateTotals(); + reporter.generateTotals(); expect(fs.existsSync(filepath)).to.be.true; @@ -100,7 +59,7 @@ describe('ExcelReporter', () => { expect(workbook.SheetNames).to.deep.equal(['Totals', 'topic']); }); - it('should log a message to xlsx', () => { + it('logs a message to xlsx', () => { const reporter = new ExcelReporter(); reporter.log('topic', 'status', 'message', 'arg1', 'arg2'); @@ -108,6 +67,7 @@ describe('ExcelReporter', () => { const topicSheet = reporter.workbook.Sheets.topic; + // Remove the type property from each cell deleteObjectProperty(topicSheet, 't'); expect(topicSheet).to.deep.equal({ '!ref': 'A1:D2', @@ -120,7 +80,7 @@ describe('ExcelReporter', () => { }); }); - it('should calculate the totals for each topic and status', () => { + it('produces totals sheet when calculating totals', () => { const reporter = new ExcelReporter(); reporter.log('topic1', 'status1', 'message1'); @@ -129,9 +89,10 @@ describe('ExcelReporter', () => { reporter.log('topic2', 'status2', 'message4'); reporter.log('topic2', 'status2', 'message5'); - reporter.calculateTotals(); + reporter.generateTotals(); const totalsSheet = reporter.workbook.Sheets.Totals; + // Remove the type property from each cell deleteObjectProperty(totalsSheet, 't'); expect(totalsSheet).to.deep.equal({ '!ref': 'A1:C5', diff --git a/test/bulk-update/reporter/reporter.test.js b/test/bulk-update/reporter/reporter.test.js index 090f7c4..34ba820 100644 --- a/test/bulk-update/reporter/reporter.test.js +++ b/test/bulk-update/reporter/reporter.test.js @@ -8,13 +8,13 @@ describe('BaseReporter', () => { reporter = new BaseReporter(); }); - it('should initialize with an empty report', () => { + it('initializes with an empty report', () => { const report = reporter.getReport(); expect(report.logs).to.be.an('object').that.is.empty; }); - it('should log a message and update the report', () => { + it('logs a message and update the report', () => { reporter.log('topic', 'status', 'message', 'arg1', 'arg2'); const report = reporter.getReport(); @@ -27,14 +27,38 @@ describe('BaseReporter', () => { }); }); - it('should calculate the totals for each topic and status', () => { + it('logs multiple messages and update the report', () => { + reporter.log('topic', 'status', 'message', 'arg1', 'arg2'); + reporter.log('topic', 'status', 'message', 'arg1', 'arg2'); + const report = reporter.getReport(); + + expect(report.logs.topic).to.have.lengthOf(2); + expect(report.logs.topic).to.deep.equal( + [ + { + status: 'status', + message: 'message', + 0: 'arg1', + 1: 'arg2', + }, + { + status: 'status', + message: 'message', + 0: 'arg1', + 1: 'arg2', + }, + ], + ); + }); + + it('calculates the totals for each topic and status', () => { reporter.log('topic1', 'status1', 'message1'); reporter.log('topic1', 'status2', 'message2'); reporter.log('topic2', 'status1', 'message3'); reporter.log('topic2', 'status2', 'message4'); reporter.log('topic2', 'status2', 'message5'); - const totals = reporter.calculateTotals(); + const totals = reporter.generateTotals(); expect(totals).to.deep.equal({ topic1: {