Skip to content

Commit

Permalink
HAI-1844 Add test for hanke tunnus check
Browse files Browse the repository at this point in the history
  • Loading branch information
pitkni committed Aug 30, 2023
1 parent 125a9d0 commit 9b89c02
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,23 @@ class HankeControllerTest {
verify { disclosureLogService.saveDisclosureLogsForHanke(any(), eq(username)) }
}

@Test
fun `test that the updateHanke will throw if mismatch in hanke tunnus payload vs path`() {
val hankeUpdate = HankeFactory.create()
val existingHanke = HankeFactory.create(hankeTunnus = "wrong")
Mockito.`when`(hankeService.findHankeOrThrow("wrong")).thenReturn(existingHanke)
Mockito.`when`(
permissionService.hasPermission(existingHanke.id!!, username, PermissionCode.EDIT)
)
.thenReturn(true)

assertThatExceptionOfType(HankeArgumentException::class.java)
.isThrownBy { hankeController.updateHanke(hankeUpdate, "wrong") }
.withMessageContaining(
"Hanketunnus mismatch. (In payload=${hankeUpdate.hankeTunnus}, In path=wrong)"
)
}

@Test
fun `test that the updateHanke will give validation errors from invalid hanke data for name`() {
val partialHanke =
Expand Down

0 comments on commit 9b89c02

Please sign in to comment.