Skip to content

Commit

Permalink
test(KUI-1380): fix failing tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
karlandindrakryggen committed Sep 9, 2024
1 parent 02fb4c5 commit bb5a92d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 25 deletions.
4 changes: 2 additions & 2 deletions server/apiCalls/getFilteredData.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ function _parseCourseDefaultInformation(koppsCourseDetails, ladokCourse, languag
const mainSubjects = ladokCourse.huvudomraden?.map(x => getNameInLanguage(x, language))

return {
course_code: parseOrSetEmpty(ladokCourse.code),
course_code: parseOrSetEmpty(ladokCourse.kod),
course_department: getNameInLanguageOrSetEmpty(ladokCourse.organisation, language),
course_department_code: parseOrSetEmpty(ladokCourse.organisation.code, language),
course_department_link: buildCourseDepartmentLink(ladokCourse.organisation, language),
course_education_type_id: ladokCourse.utbildningstyp.id,
course_education_type_id: ladokCourse.utbildningstyp?.id,
course_level_code: parseOrSetEmpty(ladokCourse.utbildningstyp.level.code),
course_main_subject:
mainSubjects && mainSubjects.length > 0
Expand Down
27 changes: 12 additions & 15 deletions server/controllers/__tests__/courseCtrl.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

import { mockedCourseMemosForDiscontinuedCourse, mockedDiscontinuedCourse } from '../mocks/mockedDiscontinuedCourse'
import { mockedLadokData } from '../mocks/mockedLadokData'

const applicationPaths = {
system: {
Expand Down Expand Up @@ -32,6 +33,12 @@ jest.mock('@kth/kth-node-web-common/lib/language', () => ({
jest.mock('kth-node-express-routing', () => ({
getPaths: jest.fn(() => applicationPaths),
}))
jest.mock('om-kursen-ladok-client', () => ({
createApiClient: () => ({
getLatestCourseVersion: () => mockedLadokData.mockedLadokCourseVersion,
getActiveCourseRounds: () => mockedLadokData.mockedLadokRounds,
}),
}))
// jest.mock('@kth/kth-node-response')
jest.mock('../../configuration', () => ({
server: {
Expand Down Expand Up @@ -72,8 +79,7 @@ function buildReq(overrides) {
return req
}

// const courseCtrl = require('../courseCtrl')
const courseCtrl = {}
const courseCtrl = require('../courseCtrl')

let response
beforeEach(() => {
Expand All @@ -85,8 +91,7 @@ afterEach(() => {
response = {}
})

// TODO(karl): fix
describe.skip('Discontinued course to test', () => {
describe('Discontinued course to test', () => {
test('Gets correct data', async () => {
const req = buildReq({
params: { courseCode: mockedDiscontinuedCourse.course.courseCode },
Expand All @@ -105,13 +110,7 @@ describe.skip('Discontinued course to test', () => {
expect(response.render).toHaveBeenCalled()
expect(testResponse.title).toBe(mockedDiscontinuedCourse.course.courseCode)
expect(testResponse.compressedData.courseCode).toBe(mockedDiscontinuedCourse.course.courseCode)
expect(testResponse.compressedData.courseData.courseInfo.course_application_info).toBe(
mockedDiscontinuedCourse.course.applicationInfo
)
expect(testResponse.html.context.courseCode).toBe(mockedDiscontinuedCourse.course.courseCode)
expect(testResponse.html.context.courseData.courseInfo.course_application_info).toBe(
mockedDiscontinuedCourse.course.applicationInfo
)

expect(testResponse.html).toMatchInlineSnapshot(`
{
Expand All @@ -126,24 +125,23 @@ describe.skip('Discontinued course to test', () => {
"courseCode": "FCK3305",
"courseData": {
"courseInfo": {
"course_application_info": "<p>Kursen ges inte l&#228;s&#229;ret 22/23.</p><p>Kontakta examinator / kursansvarig f&#246;r information.</p>",
"course_application_info": "<i>Ingen information tillagd</i>",
"course_code": "FCK3305",
"course_contact_name": "<i>Ingen information tillagd</i>",
"course_department": "CBH/Kemi",
"course_department_code": "CE",
"course_department_link": "<a href="/cbh/" target="blank">CBH/Kemi</a>",
"course_disposition": "<p>Kursupplägg på svenska</p>",
"course_education_type_id": null,
"course_education_type_id": undefined,
"course_examiners": "<p>Examiner 1 </p>",
"course_grade_scale": "P, F",
"course_last_exam": [],
"course_level_code": "RESEARCH",
"course_level_code": "3",
"course_literature": "<p>Litteratur anvisas vid kursstart.</p>",
"course_main_subject": "Denna kurs tillhör inget huvudområde.",
"course_possibility_to_addition": "<i>Ingen information tillagd</i>",
"course_possibility_to_completions": "<i>Ingen information tillagd</i>",
"course_prerequisites": "<i>Ingen information tillagd</i>",
"course_recruitment_text": "<p>Teori och metoder inom glykovetenskap.</p>",
"course_required_equipment": "<i>Ingen information tillagd</i>",
"course_state": "ESTABLISHED",
"course_suggested_addon_studies": "<i>Ingen information tillagd</i>",
Expand All @@ -157,7 +155,6 @@ describe.skip('Discontinued course to test', () => {
"course_code": "FCK3305",
"course_credits": 7.5,
"course_credits_text": "hp",
"course_other_title": "Carbohydrate Technologies in Glycoscience",
"course_title": "Kolhydratteknik inom glykovetenskap",
},
"emptySyllabusData": {
Expand Down
28 changes: 28 additions & 0 deletions server/controllers/mocks/mockedLadokData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const mockedLadokCourseVersion = {
kod: 'FCK3305',
benamning: { sv: 'Kolhydratteknik inom glykovetenskap', en: 'Carbohydrate Technologies in Glycoscience' },
omfattning: 7.5,
organisation: {
code: 'CE',
sv: 'CBH/Kemi',
en: 'CBH/Kemi',
},
utbildningstyp: {
creditsUnitCode: 'HP',
level: {
code: '3',
sv: 'Grundnivå',
en: 'First cycle',
},
},
betygsskala: {
code: 'PF',
},
huvudomraden: [],
}

const mockedLadokRounds = []

const mockedLadokData = { mockedLadokCourseVersion, mockedLadokRounds }

module.exports = { mockedLadokData }
9 changes: 4 additions & 5 deletions server/util/__tests__/courseDepartmentUtils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,19 @@ function htmlStringToElement(html) {
return htmlElement
}

// TODO(karl): fix
describe.skip('course department link utils', () => {
describe('course department link utils', () => {
test('returns department link', () => {
const department = { code: 'JH', name: 'EECS/Datavetenskap' }
const department = { code: 'JH', sv: 'EECS/Datavetenskap', en: 'EECS/Computer Science' }
const result = buildCourseDepartmentLink(department, 'en')
expect(result).toBeDefined()

const element = htmlStringToElement(result)
expect(element.href).toBe('/eecs/')
expect(element.innerHTML).toBe('EECS/Datavetenskap')
expect(element.innerHTML).toBe('EECS/Computer Science')
})

test('returns undefined for Stockholm university as department', () => {
const department = { code: 'UL', name: 'Stockholms universitet' }
const department = { code: 'UL', sv: 'Stockholms universitet', en: 'Stockholm University' }

const result = buildCourseDepartmentLink(department, 'en')
expect(result).not.toBeDefined()
Expand Down
2 changes: 1 addition & 1 deletion server/util/courseDepartmentUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function isDepartmentStockholmUniversity(courseDepartment) {
}

function buildCourseDepartmentLink(courseDepartment, language) {
const name = courseDepartment[language]
const name = courseDepartment && courseDepartment[language]
if (!name) {
return INFORM_IF_IMPORTANT_INFO_IS_MISSING[language]
}
Expand Down
4 changes: 2 additions & 2 deletions server/util/languageUtil.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { parseOrSetEmpty } = require('../controllers/courseCtrlHelpers')

// Used for most Ladok objects that have Sv/En props
const getNameInLanguage = (obj, lang = 'sv') => (lang === 'en' ? obj.en : obj.sv)
const getNameInLanguage = (obj, lang = 'sv') => (lang === 'en' ? obj?.en : obj?.sv)

const getNameInLanguageOrSetEmpty = (obj, lang = 'sv') => {
const v = lang === 'en' ? obj.en : obj.sv
const v = lang === 'en' ? obj?.en : obj?.sv
return parseOrSetEmpty(v, lang)
}

Expand Down

0 comments on commit bb5a92d

Please sign in to comment.