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