Skip to content

Commit 06239c6

Browse files
committed
Fix: XLSX output does not show projects
1 parent 7a5c68b commit 06239c6

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

spec/output/xlsx.spec.js

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
const moment = require('moment');
2+
const config = require('../../src/include/config');
3+
const Report = require('../../src/models/report');
4+
const Sinon = require('sinon');
5+
const { describe } = require('mocha');
6+
const output = require('../../src/output/xlsx');
7+
const XLSX = require('xlsx');
8+
const { assert } = require('chai');
9+
10+
describe('XLSX output', () => {
11+
/**
12+
* @type {Sinon.SinonSpyStatic}
13+
*/
14+
let xlsxSpy;
15+
16+
beforeEach(() => {
17+
xlsxSpy = Sinon.spy(XLSX.utils, 'aoa_to_sheet')
18+
})
19+
20+
afterEach(() => {
21+
xlsxSpy.restore();
22+
})
23+
24+
it('renders projects if more than one', () => {
25+
const issues = [
26+
{
27+
times: [
28+
{
29+
user: "user1",
30+
project_namespace: "project1",
31+
seconds: 360,
32+
date: moment('2024-06-06 00:00:00')
33+
},
34+
{
35+
user: "user2",
36+
project_namespace: "project2",
37+
seconds: 720,
38+
date: moment('2024-06-06 00:00:00')
39+
}
40+
],
41+
stats: {time_estimate: 0, total_time_spent: 0}
42+
}
43+
];
44+
45+
const projectsMatcher = Sinon.match((value) => {
46+
return Array.isArray(value) && Array.isArray(value[0]) && value[0].includes('project1') && value[0].includes('project2')
47+
}, 'Both projects exist')
48+
49+
let reportConfig = new config();
50+
reportConfig.set('report', ['stats'])
51+
let report = new Report(reportConfig);
52+
report.issues = issues;
53+
report.mergeRequests = [];
54+
55+
let out = new output(reportConfig, report);
56+
out.make();
57+
assert(xlsxSpy.calledWith(projectsMatcher), 'Not called properly')
58+
})
59+
60+
it('does not render single project', () => {
61+
const issues = [
62+
{
63+
times: [
64+
{
65+
user: "user2",
66+
project_namespace: "project2",
67+
seconds: 720,
68+
date: moment('2024-06-06 00:00:00')
69+
}
70+
],
71+
stats: {time_estimate: 0, total_time_spent: 0}
72+
}
73+
];
74+
75+
const projectsMatcher = Sinon.match((value) => {
76+
return Array.isArray(value) && Array.isArray(value[0]) && !value[0].includes('project2')
77+
}, 'Project does not exist')
78+
79+
let reportConfig = new config();
80+
reportConfig.set('report', ['stats'])
81+
let report = new Report(reportConfig);
82+
report.issues = issues;
83+
report.mergeRequests = [];
84+
85+
let out = new output(reportConfig, report);
86+
out.make();
87+
assert(xlsxSpy.calledWith(projectsMatcher), 'Not called properly')
88+
})
89+
})

src/output/xlsx.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class xlsx extends Base {
1919
stats[1].push(time);
2020
});
2121

22-
if (this.projects.length > 1) {
22+
if (Object.keys(this.projects).length > 1) {
2323
_.each(this.projects, (time, name) => {
2424
stats[0].push(name);
2525
stats[1].push(time);

0 commit comments

Comments
 (0)