Skip to content

Commit

Permalink
Fallback to give out name if nb/nn doesn't exist
Browse files Browse the repository at this point in the history
This happens when a class doesn't have grep codes
  • Loading branch information
runely committed Mar 25, 2022
1 parent b3ca593 commit 94eecfe
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 13 deletions.
4 changes: 4 additions & 0 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,9 @@ module.exports = {
if (!obj) return false
const regex = new RegExp(text, 'i')
return regex.test(JSON.stringify(obj))
},
classIdentifier: (lang, name) => {
if (lang) return lang
return name
}
}
2 changes: 1 addition & 1 deletion templates/minelev/varsel/fag-nb.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ info:
Dette omfatter følgende fag:

{{#each content.classes}}
- {{this.nb}}
- {{ classIdentifier this.nb this.name }}
{{/each}}

Varselet gjelder {{ lowercase content.period.nb }} skoleåret {{ content.year }}.
Expand Down
2 changes: 1 addition & 1 deletion templates/minelev/varsel/fag-nn.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ info:
Dette omfattar følgjande fag:

{{#each content.classes}}
- {{this.nn}}
- {{ classIdentifier this.nn this.name }}
{{/each}}

Varselet gjeld {{ lowercase content.period.nn }} skoleåret {{ content.year }}.
Expand Down
9 changes: 4 additions & 5 deletions tests/data/varsel-fag.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@
},
"classes": [
{
"id": "TESVS:TEST/201NOR1208",
"id": "01234567",
"name": "TEST/201NOR1208",
"nb": "Norsk hovedmål, skriftlig",
"nn": "Norsk hovudmål, skriftleg",
"en": "Norwegian as 1st lang, written"
}, {
"id": "TESVS:TEST/201NOR1209",
"nb": "Norsk hovedmål, muntlig",
"nn": "Norsk hovudmål, muntlig",
"en": "Norwegian as 1st lang, plural"
"id": "76543210",
"name": "TEST/201NOR1209"
}
],
"reasons": [
Expand Down
9 changes: 4 additions & 5 deletions tests/data/varsel-orden.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,14 @@
},
"classes": [
{
"id": "TESVS:TEST/201NOR1208",
"id": "01234567",
"name": "TEST/201NOR1208",
"nb": "Norsk hovedmål, skriftlig",
"nn": "Norsk hovudmål, skriftleg",
"en": "Norwegian as 1st lang, written"
}, {
"id": "TESVS:TEST/201NOR1209",
"nb": "Norsk hovedmål, muntlig",
"nn": "Norsk hovudmål, muntlig",
"en": "Norwegian as 1st lang, plural"
"id": "76543210",
"name": "TEST/201NOR1209"
}
],
"reasons": [
Expand Down
25 changes: 24 additions & 1 deletion tests/lib/helpers.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { isoDate, prettyDate, lowercase, join, uppercase, variable, eq, ne, lt, gt, lte, gte, and, or, multiple, replace, capitalize, uppercaseFirst, objectContains } = require('../../lib/helpers')
const { isoDate, prettyDate, lowercase, join, uppercase, variable, eq, ne, lt, gt, lte, gte, and, or, multiple, replace, capitalize, uppercaseFirst, objectContains, classIdentifier } = require('../../lib/helpers')

describe('Test helper - logic', () => {
const options = {}
Expand Down Expand Up @@ -220,3 +220,26 @@ describe('Test helper - objectContains', () => {
expect(objectContains(obj, 'heihei')).toBe(false)
})
})

describe('Test helper - classIdentifier', () => {
it('returns "nb" from class object when it exists', () => {
const obj = {
id: '01234567',
name: 'TEST/201NOR1208',
nb: 'Norsk hovedmål, skriftlig',
nn: 'Norsk hovudmål, skriftleg',
en: 'Norwegian as 1st lang, written'
}
const identifier = classIdentifier(obj.nb, obj.name)
expect(identifier).toBe(obj.nb)
})

it('returns "name" from class object when "nb" doesnt exist', () => {
const obj = {
id: '76543210',
name: 'TEST/201NOR1209'
}
const identifier = classIdentifier(obj.nb, obj.name)
expect(identifier).toBe(obj.name)
})
})

0 comments on commit 94eecfe

Please sign in to comment.