Skip to content
This repository has been archived by the owner on Feb 13, 2025. It is now read-only.

Commit

Permalink
PR Changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon32 committed Jan 5, 2024
1 parent ad19839 commit 4fcd718
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 63 deletions.
4 changes: 2 additions & 2 deletions bulk-update/reporter/console-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
4 changes: 2 additions & 2 deletions bulk-update/reporter/excel-reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
2 changes: 1 addition & 1 deletion bulk-update/reporter/reporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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: {
Expand Down
59 changes: 10 additions & 49 deletions test/bulk-update/reporter/excel-reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -38,76 +38,36 @@ 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;

const workbook = xlsx.readFile(filepath);
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');
expect(reporter.workbook.SheetNames).to.deep.equal(['Totals', 'topic']);

const topicSheet = reporter.workbook.Sheets.topic;

// Remove the type property from each cell
deleteObjectProperty(topicSheet, 't');
expect(topicSheet).to.deep.equal({
'!ref': 'A1:D2',
Expand All @@ -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');
Expand All @@ -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',
Expand Down
32 changes: 28 additions & 4 deletions test/bulk-update/reporter/reporter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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: {
Expand Down

0 comments on commit 4fcd718

Please sign in to comment.