Skip to content

Commit 03b5788

Browse files
authored
Increase coverage for ssn validations (#1221)
* Increase coverage for SSN validations
1 parent 82b39ff commit 03b5788

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

kontroller/src/main/kotlin/no/ssb/kostra/program/util/SsnValidationUtils.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object SsnValidationUtils {
2828
null
2929
}
3030

31-
private fun parseDateWithAutoPivotYear(socialSecurityId: String): LocalDate {
31+
internal fun parseDateWithAutoPivotYear(socialSecurityId: String): LocalDate {
3232
val individualDigits = Integer.parseInt(socialSecurityId.substring(6, 9))
3333
val individualYear = Integer.parseInt(socialSecurityId.substring(4, 6))
3434
val date = LocalDate.parse(socialSecurityId.take(6), LOCAL_DATE_FORMATTER)

kontroller/src/test/kotlin/no/ssb/kostra/program/util/SsnValidationUtilsTest.kt

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,20 @@ class SsnValidationUtilsTest : BehaviorSpec({
1818
row("05011399292", "fnr", LocalDate.of(2013, 1, 5)),
1919
row("41011088188", "dnr", LocalDate.of(2010, 1, 1)),
2020
row("01811088188", "tnr", LocalDate.of(2010, 1, 1)),
21+
) { socialSecurityId, type, expectedDate ->
22+
When("$socialSecurityId $type") {
23+
24+
val dateOfBirth = SsnValidationUtils.extractBirthDateFromSocialSecurityId(socialSecurityId)
25+
26+
Then("dateOfBirth ($dateOfBirth) should be as expected ($expectedDate)") {
27+
dateOfBirth shouldBe expectedDate
28+
}
29+
}
30+
}
31+
}
2132

33+
Given("parseDateWithAutoPivotYear") {
34+
forAll(
2235
row("01015450068", "fnr", LocalDate.of(1854, 1, 1)),
2336
row("31129974810", "fnr", LocalDate.of(1899, 12, 31)),
2437

@@ -30,10 +43,14 @@ class SsnValidationUtilsTest : BehaviorSpec({
3043

3144
row("01010050053", "fnr", LocalDate.of(2000, 1, 1)),
3245
row("31123999854", "fnr", LocalDate.of(2039, 12, 31)),
46+
47+
row("31124588890", "fnr", LocalDate.of(2045, 12, 31)),
48+
row("31123974912", "fnr", LocalDate.of(2039, 12, 31)),
49+
row("01014074912", "fnr", LocalDate.of(2040, 1, 1)),
3350
) { socialSecurityId, type, expectedDate ->
3451
When("$socialSecurityId $type") {
3552

36-
val dateOfBirth = SsnValidationUtils.extractBirthDateFromSocialSecurityId(socialSecurityId)
53+
val dateOfBirth = SsnValidationUtils.parseDateWithAutoPivotYear(socialSecurityId)
3754

3855
Then("dateOfBirth ($dateOfBirth) should be as expected ($expectedDate)") {
3956
dateOfBirth shouldBe expectedDate

0 commit comments

Comments
 (0)