Skip to content
This repository was archived by the owner on May 22, 2025. It is now read-only.

Commit 7a5c68b

Browse files
committed
Fix: Table output does not show projects
1 parent 449f595 commit 7a5c68b

File tree

2 files changed

+77
-2
lines changed

2 files changed

+77
-2
lines changed

spec/output/table.spec.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const moment = require('moment');
2+
const config = require('../../src/include/config');
3+
const Report = require('../../src/models/report');
4+
const table = require('../../src/output/table');
5+
const Sinon = require('sinon');
6+
7+
describe('Table output', () => {
8+
it('Renders projects if more than one', () => {
9+
const issues = [
10+
{
11+
times: [
12+
{
13+
user: "user1",
14+
project_namespace: "project1",
15+
seconds: 360,
16+
date: moment('2024-06-06 00:00:00')
17+
},
18+
{
19+
user: "user2",
20+
project_namespace: "project2",
21+
seconds: 720,
22+
date: moment('2024-06-06 00:00:00')
23+
}
24+
],
25+
stats: {time_estimate: 0, total_time_spent: 0}
26+
}
27+
];
28+
29+
const projectsMatcher = Sinon.match('project1').and(Sinon.match('project2'))
30+
let reportConfig = new config();
31+
reportConfig.set('report', ['stats'])
32+
let report = new Report(reportConfig);
33+
report.issues = issues;
34+
report.mergeRequests = [];
35+
36+
let out = new table(reportConfig, report);
37+
let mdMock = Sinon.mock(out);
38+
mdMock.expects('headline').once();
39+
mdMock.expects('write').once().withArgs(projectsMatcher);
40+
out.make();
41+
});
42+
43+
it('Does not render single project', () => {
44+
const issues = [
45+
{
46+
times: [
47+
{
48+
user: "user2",
49+
project_namespace: "project2",
50+
seconds: 720,
51+
date: moment('2024-06-06 00:00:00')
52+
}
53+
],
54+
stats: {time_estimate: 0, total_time_spent: 0}
55+
}
56+
];
57+
58+
const projectsMatcher = Sinon.match(function(value) {
59+
return ((typeof(value) === 'string') && (/project2/.test(value) === false));
60+
})
61+
62+
let reportConfig = new config();
63+
reportConfig.set('report', ['stats'])
64+
let report = new Report(reportConfig);
65+
report.issues = issues;
66+
report.mergeRequests = [];
67+
68+
let out = new table(reportConfig, report);
69+
let mdMock = Sinon.mock(out);
70+
mdMock.expects('headline').once();
71+
mdMock.expects('write').once().withArgs(projectsMatcher);
72+
out.make();
73+
});
74+
});
75+

src/output/table.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class table extends Base {
2525
_.each(this.stats, (time, name) => stats += `\n* ${name.red}: ${time}`);
2626
stats += `\n`;
2727

28-
if (this.projects.length > 1) {
28+
if (Object.keys(this.projects).length > 1) {
2929
_.each(this.projects, (time, name) => stats += `\n* ${name.red}: ${time}`);
3030
stats += `\n`;
3131
}
@@ -65,4 +65,4 @@ class table extends Base {
6565
}
6666
}
6767

68-
module.exports = table;
68+
module.exports = table;

0 commit comments

Comments
 (0)