|
| 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 | + |
0 commit comments