From deaa46adf54d77e3e334671f30aec5c944ca8672 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A4kinen=20Sasu=20S?= Date: Mon, 3 Jun 2019 16:06:59 +0300 Subject: [PATCH] fixify tests --- .../src/services/studytrack.js | 9 ++++---- .../src/services/studytrack.test.js | 21 ++++++++++++------- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/services/backend/oodikone2-backend/src/services/studytrack.js b/services/backend/oodikone2-backend/src/services/studytrack.js index 5ed410da05..af9de7bf16 100644 --- a/services/backend/oodikone2-backend/src/services/studytrack.js +++ b/services/backend/oodikone2-backend/src/services/studytrack.js @@ -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 @@ -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 }) diff --git a/services/backend/oodikone2-backend/src/services/studytrack.test.js b/services/backend/oodikone2-backend/src/services/studytrack.test.js index 92c514e3e2..0650f0196b 100644 --- a/services/backend/oodikone2-backend/src/services/studytrack.test.js +++ b/services/backend/oodikone2-backend/src/services/studytrack.test.js @@ -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 ]} }) }) @@ -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 }, @@ -150,6 +150,7 @@ test('combineStatistics returns correctly formatted array', () => { mThesis: 2, bThesis: 1, credits: 40, + medianGraduationTime: 1.5, graduated: 2 }) expect(stats).toContainEqual({ @@ -157,14 +158,16 @@ test('combineStatistics returns correctly formatted array', () => { 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 }) }) @@ -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 }) })