Skip to content

Commit

Permalink
fixify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sasumaki committed Jun 3, 2019
1 parent c421d1f commit deaa46a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
9 changes: 5 additions & 4 deletions services/backend/oodikone2-backend/src/services/studytrack.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,10 @@ const graduatedStatsFromStudyrights = studyrights => {
const graduated = stats[year] ? stats[year].graduated : 0
stats[year] = {
graduated: graduated + 1,
timesToGraduation: stats[year] ? [...stats[year].timesToGraduation, timeToGraduation] : [ timeToGraduation ]
timesToGraduation: stats[year] ?
[...stats[year].timesToGraduation, timeToGraduation || 0] : [ timeToGraduation || 0]
}
graduationTimes = [...graduationTimes, timeToGraduation]
graduationTimes = [...graduationTimes, timeToGraduation || 0]
})
const median = (values) => {
if (values.length === 0) return 0
Expand Down Expand Up @@ -174,8 +175,8 @@ const combineStatistics = (creditStats, studyrightStats, thesisStats) => {
const stats = { ...creditStats }
Object.keys(stats).forEach(year => {
const thesis = thesisStats[year] || {}
stats[year].graduated = studyrightStats[year].graduated || 0
stats[year].medianGraduationTime = studyrightStats[year].medianGraduationTime || 0
stats[year].graduated = studyrightStats[year] ? studyrightStats[year].graduated : 0
stats[year].medianGraduationTime = studyrightStats[year] ? studyrightStats[year].medianGraduationTime : 0
stats[year].bThesis = thesis.bThesis || 0
stats[year].mThesis = thesis.mThesis || 0
})
Expand Down
21 changes: 13 additions & 8 deletions services/backend/oodikone2-backend/src/services/studytrack.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ test('graduatedStatsFromStudyrights calculates stats correctly', () => {
]
const stats = graduatedStatsFromStudyrights(studyrights)
expect(stats).toMatchObject({
2015: 2,
2014: 1
2015: { graduated: 2., medianGraduationTime: 0, timesToGraduation: [ 0, 0 ]},
2014: { graduated: 1., medianGraduationTime: 0, timesToGraduation: [ 0 ]}
})
})

Expand All @@ -137,8 +137,8 @@ test('combineStatistics returns correctly formatted array', () => {
2014: { year: 2014, credits: 20 }
}
const studyrightStats = {
2015: 2,
2016: 1
2015: { graduated: 2, medianGraduationTime: 1.5, timesToGraduation: [1, 2] },
2016: { graduated: 1, medianGraduationTime: 0, timesToGraduation: [ 0 ] }
}
const thesisStats = {
2014: { mThesis: 1 },
Expand All @@ -150,21 +150,24 @@ test('combineStatistics returns correctly formatted array', () => {
mThesis: 2,
bThesis: 1,
credits: 40,
medianGraduationTime: 1.5,
graduated: 2
})
expect(stats).toContainEqual({
year: 2014,
mThesis: 1,
bThesis: 0,
credits: 20,
graduated: 0
graduated: 0,
medianGraduationTime: 0
})
expect(stats).toContainEqual({
year: 2016,
mThesis: 0,
bThesis: 0,
credits: 5,
graduated: 1
graduated: 1,
medianGraduationTime: 0
})
})

Expand All @@ -175,14 +178,16 @@ test('productivityStatsForStudytrack integrates', async () => {
graduated: 0,
bThesis: 0,
mThesis: 1,
credits: 40
credits: 40,
medianGraduationTime: 0
})
expect(stats.data).toContainEqual({
year: 2016,
graduated: 1,
mThesis: 0,
bThesis: 0,
credits: 5
credits: 5,
medianGraduationTime: 0
})
})

Expand Down

0 comments on commit deaa46a

Please sign in to comment.