-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HAI-1882 Add API for own permissions
Add an API where the user (or in practice, the frontend) can ask what permission level they have for a hanke. Returns 404 if the hanke is not found or the user doesn't have any permissions for it. Also rewrite the hanke not found log message to make it searchable.
- Loading branch information
Showing
8 changed files
with
245 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
services/hanke-service/src/main/kotlin/fi/hel/haitaton/hanke/permissions/WhoamiResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package fi.hel.haitaton.hanke.permissions | ||
|
||
data class WhoamiResponse(val userId: String, val kayttooikeustaso: Kayttooikeustaso) { | ||
constructor( | ||
permissionEntity: PermissionEntity | ||
) : this(permissionEntity.userId, permissionEntity.kayttooikeustaso.kayttooikeustaso) | ||
} |
99 changes: 99 additions & 0 deletions
99
services/hanke-service/src/test/kotlin/fi/hel/haitaton/hanke/HankeServiceTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package fi.hel.haitaton.hanke | ||
|
||
import assertk.all | ||
import assertk.assertFailure | ||
import assertk.assertThat | ||
import assertk.assertions.hasClass | ||
import assertk.assertions.isEqualTo | ||
import assertk.assertions.isNotNull | ||
import assertk.assertions.isNull | ||
import assertk.assertions.messageContains | ||
import fi.hel.haitaton.hanke.application.ApplicationService | ||
import fi.hel.haitaton.hanke.geometria.GeometriatService | ||
import fi.hel.haitaton.hanke.logging.AuditLogService | ||
import fi.hel.haitaton.hanke.logging.HankeLoggingService | ||
import fi.hel.haitaton.hanke.permissions.HankeKayttajaService | ||
import fi.hel.haitaton.hanke.permissions.PermissionService | ||
import fi.hel.haitaton.hanke.tormaystarkastelu.TormaystarkasteluLaskentaService | ||
import io.mockk.every | ||
import io.mockk.mockk | ||
import org.junit.jupiter.api.Nested | ||
import org.junit.jupiter.api.Test | ||
|
||
class HankeServiceTest { | ||
|
||
private val hankeRepository: HankeRepository = mockk() | ||
private val tormaystarkasteluService: TormaystarkasteluLaskentaService = mockk() | ||
private val hanketunnusService: HanketunnusService = mockk() | ||
private val geometriatService: GeometriatService = mockk() | ||
private val auditLogService: AuditLogService = mockk() | ||
private val hankeLoggingService: HankeLoggingService = mockk() | ||
private val applicationService: ApplicationService = mockk() | ||
private val permissionService: PermissionService = mockk() | ||
private val hankeKayttajaService: HankeKayttajaService = mockk() | ||
|
||
private val hankeService = | ||
HankeServiceImpl( | ||
hankeRepository, | ||
tormaystarkasteluService, | ||
hanketunnusService, | ||
geometriatService, | ||
auditLogService, | ||
hankeLoggingService, | ||
applicationService, | ||
permissionService, | ||
hankeKayttajaService, | ||
) | ||
|
||
@Nested | ||
inner class GetHankeId { | ||
val hankeTunnus = "HAI23-1" | ||
val hankeId = 9984 | ||
|
||
@Test | ||
fun `Returns hanke id if hanke found`() { | ||
every { hankeRepository.findByHankeTunnus(hankeTunnus) } returns | ||
HankeEntity(id = hankeId) | ||
|
||
val response = hankeService.getHankeId(hankeTunnus) | ||
|
||
assertThat(response).isNotNull().isEqualTo(hankeId) | ||
} | ||
|
||
@Test | ||
fun `Returns null if hanke not found`() { | ||
every { hankeRepository.findByHankeTunnus(hankeTunnus) } returns null | ||
|
||
val response = hankeService.getHankeId(hankeTunnus) | ||
|
||
assertThat(response).isNull() | ||
} | ||
} | ||
|
||
@Nested | ||
inner class GetHankeIdOrThrow { | ||
val hankeTunnus = "HAI23-1" | ||
val hankeId = 9984 | ||
|
||
@Test | ||
fun `Returns hanke id if hanke found`() { | ||
every { hankeRepository.findByHankeTunnus(hankeTunnus) } returns | ||
HankeEntity(id = hankeId) | ||
|
||
val response = hankeService.getHankeIdOrThrow(hankeTunnus) | ||
|
||
assertThat(response).isNotNull().isEqualTo(hankeId) | ||
} | ||
|
||
@Test | ||
fun `Returns null if hanke not found`() { | ||
every { hankeRepository.findByHankeTunnus(hankeTunnus) } returns null | ||
|
||
assertFailure { hankeService.getHankeIdOrThrow(hankeTunnus) } | ||
.all { | ||
hasClass(HankeNotFoundException::class) | ||
messageContains(hankeTunnus) | ||
} | ||
} | ||
} | ||
} |