diff --git a/services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/HankeControllerTest.kt b/services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/HankeControllerTest.kt index 32e349ff0..3a1051144 100644 --- a/services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/HankeControllerTest.kt +++ b/services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/HankeControllerTest.kt @@ -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 =