Skip to content

Commit 2880947

Browse files
Added tests
1 parent 1345d13 commit 2880947

File tree

5 files changed

+1888
-27
lines changed

5 files changed

+1888
-27
lines changed

jest.config.js

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/** @type {import('ts-jest').JestConfigWithTsJest} */
2+
// eslint-disable-next-line no-undef
3+
module.exports = {
4+
preset: 'ts-jest',
5+
testEnvironment: 'node',
6+
testRegex: '.*.test.ts',
7+
}

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,22 @@
77
"start:dev": "ts-node-dev --inspect --respawn .",
88
"lint": "tsc --noEmit && eslint",
99
"build": "tsc",
10-
"start": "node dist/index.js"
10+
"start": "node dist/index.js",
11+
"test": "jest"
1112
},
1213
"dependencies": {
1314
"axios": "^0.27.2",
1415
"dotenv": "^16.0.2"
1516
},
1617
"devDependencies": {
1718
"@types/dotenv": "^8.2.0",
19+
"@types/jest": "^29.0.3",
1820
"@types/node": "^18.7.23",
1921
"@typescript-eslint/eslint-plugin": "^5.38.1",
2022
"@typescript-eslint/parser": "^5.38.1",
2123
"eslint": "^8.24.0",
24+
"jest": "^29.0.3",
25+
"ts-jest": "^29.0.2",
2226
"ts-node": "^10.9.1",
2327
"ts-node-dev": "^2.0.0",
2428
"typescript": "^4.8.3"

src/aggregation.ts

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ReportLine } from './api'
22

3-
interface Epic {
3+
export interface Epic {
44
name: string
55
tasks: string[]
66
durationSecs: number
@@ -26,7 +26,7 @@ export const aggregateReports = (reportLines: ReportLine[]): Epic[] => {
2626
}
2727

2828
if (splitted.length > 1) {
29-
epic.tasks.push(...epicRest)
29+
epic.tasks.push(...epicRest.map((t) => t.trim()))
3030
}
3131
epic.durationSecs += line.durationSec
3232
})
@@ -40,16 +40,15 @@ export const printEpics = (epics: Epic[]): void => {
4040
const DURATION_LENGTH = 14
4141

4242
const uniqueTasks = (value: string, idx: number, self: string[]) =>
43-
self.indexOf(value) === idx
43+
+self.indexOf(value) === idx
4444

4545
const prettyTable = epics.map((epic) => ({
4646
name: epic.name.padEnd(EPIC_LENGTH),
47-
tasks: epic.tasks
48-
.map((t) => t.trim())
49-
.filter(uniqueTasks)
50-
.join(', ')
51-
.padEnd(TASKS_LENGTH),
52-
minutes: (epic.durationSecs / 60).toFixed(2).padStart(DURATION_LENGTH),
47+
tasks: epic.tasks.filter(uniqueTasks).join(', ').padEnd(TASKS_LENGTH),
48+
minutes: (epic.durationSecs / 60)
49+
.toFixed(2)
50+
.replace('.', ',')
51+
.padStart(DURATION_LENGTH),
5352
}))
5453

5554
console.log('\n\n')
@@ -75,6 +74,7 @@ export const printEpics = (epics: Epic[]): void => {
7574
}, 0) / 60
7675
)
7776
.toFixed(2)
77+
.replace('.', ',')
7878
.padStart(DURATION_LENGTH),
7979
}
8080
console.log(''.padEnd(EPIC_LENGTH + TASKS_LENGTH + DURATION_LENGTH, '='))

tests/aggregation.test.ts

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { aggregateReports } from '../src/aggregation'
2+
import { ReportLine } from '../src/api'
3+
4+
describe('Test aggregation', () => {
5+
let report: ReportLine[]
6+
7+
beforeEach(() => {
8+
report = [
9+
{
10+
description: 'E1',
11+
durationSec: 10,
12+
},
13+
{
14+
description: 'E1, T1',
15+
durationSec: 10,
16+
},
17+
{
18+
description: 'E1, T2',
19+
durationSec: 10,
20+
},
21+
{
22+
description: 'E2, T1',
23+
durationSec: 10,
24+
},
25+
]
26+
})
27+
28+
it('should aggregate epics correctly', () => {
29+
const aggregation = aggregateReports(report)
30+
expect(aggregation.length).toBe(2)
31+
expect(aggregation[1].name).toBe('E2')
32+
})
33+
it('should aggregate tasks correctly', () => {
34+
const aggregation = aggregateReports(report)
35+
expect(aggregation[0].tasks).toEqual(['T1', 'T2'])
36+
expect(aggregation[1].tasks).toEqual(['T1'])
37+
})
38+
it('should aggregate time correctly', () => {
39+
const aggregation = aggregateReports(report)
40+
expect(aggregation[0].durationSecs).toBe(30)
41+
})
42+
})

0 commit comments

Comments
 (0)