forked from kriskbx/gitlab-time-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcsv.spec.js
More file actions
89 lines (78 loc) · 2.78 KB
/
csv.spec.js
File metadata and controls
89 lines (78 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const moment = require('moment');
const config = require('../../src/include/config');
const Report = require('../../src/models/report');
const Sinon = require('sinon');
const { describe } = require('mocha');
const Csv = require('csv-string');
const csv = require('../../src/output/csv');
const { assert } = require('chai');
describe('csv output', () => {
/**
* @type {Sinon.SinonSpyStatic}
*/
let csvSpy;
beforeEach(() => {
csvSpy = Sinon.spy(Csv, 'stringify')
})
afterEach(() => {
csvSpy.restore();
})
it('renders projects if more than one', () => {
const issues = [
{
times: [
{
user: "user1",
project_namespace: "project1",
seconds: 360,
date: moment('2024-06-06 00:00:00')
},
{
user: "user2",
project_namespace: "project2",
seconds: 720,
date: moment('2024-06-06 00:00:00')
}
],
stats: {time_estimate: 0, total_time_spent: 0}
}
];
const projectsMatcher = Sinon.match((value) => {
return Array.isArray(value) && Array.isArray(value[0]) && value[0].includes('project1') && value[0].includes('project2')
}, 'Both projects exist')
let reportConfig = new config();
reportConfig.set('report', ['stats'])
let report = new Report(reportConfig);
report.issues = issues;
report.mergeRequests = [];
let out = new csv(reportConfig, report);
out.make();
assert(csvSpy.calledWith(projectsMatcher), 'Not called properly')
})
it('does not render single project', () => {
const issues = [
{
times: [
{
user: "user2",
project_namespace: "project2",
seconds: 720,
date: moment('2024-06-06 00:00:00')
}
],
stats: {time_estimate: 0, total_time_spent: 0}
}
];
const projectsMatcher = Sinon.match((value) => {
return Array.isArray(value) && Array.isArray(value[0]) && !value[0].includes('project2')
}, 'Project does not exist')
let reportConfig = new config();
reportConfig.set('report', ['stats'])
let report = new Report(reportConfig);
report.issues = issues;
report.mergeRequests = [];
let out = new csv(reportConfig, report);
out.make();
assert(csvSpy.calledWith(projectsMatcher), 'Not called properly')
})
})