From af517a3dd5fdcfc490ee6b55f383bdd08f616402 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Solga=CC=8Ard?= Date: Mon, 5 Feb 2024 13:59:43 +0100 Subject: [PATCH] IS-1947: Refactor tests --- .../nav/syfo/dialogmote/database/MoteQuery.kt | 15 +++++--- .../api/v2/TildelDialogmoteApiV2Spek.kt | 37 +++---------------- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/src/main/kotlin/no/nav/syfo/dialogmote/database/MoteQuery.kt b/src/main/kotlin/no/nav/syfo/dialogmote/database/MoteQuery.kt index f02783e6..279caa32 100644 --- a/src/main/kotlin/no/nav/syfo/dialogmote/database/MoteQuery.kt +++ b/src/main/kotlin/no/nav/syfo/dialogmote/database/MoteQuery.kt @@ -5,10 +5,15 @@ import no.nav.syfo.application.database.toList import no.nav.syfo.cronjob.statusendring.toInstantOslo import no.nav.syfo.dialogmote.database.domain.PDialogmote import no.nav.syfo.dialogmote.database.domain.PMotedeltakerBehandlerVarsel -import no.nav.syfo.dialogmote.domain.* +import no.nav.syfo.dialogmote.domain.DialogmoteStatus +import no.nav.syfo.dialogmote.domain.NewDialogmote +import no.nav.syfo.dialogmote.domain.TidStedDTO import no.nav.syfo.domain.EnhetNr import no.nav.syfo.domain.PersonIdent -import java.sql.* +import java.sql.Connection +import java.sql.ResultSet +import java.sql.SQLException +import java.sql.Timestamp import java.time.Instant import java.time.LocalDateTime import java.util.* @@ -135,12 +140,12 @@ data class CreatedDialogmoteIdentifiers( ) fun Connection.createNewDialogmoteWithReferences( - commit: Boolean = true, newDialogmote: NewDialogmote, + commit: Boolean = true, ): CreatedDialogmoteIdentifiers { val moteIdList = this.createDialogmote( + newDialogmote = newDialogmote, commit = false, - newDialogmote = newDialogmote ) val moteId = moteIdList.first @@ -181,8 +186,8 @@ fun Connection.createNewDialogmoteWithReferences( } fun Connection.createDialogmote( + newDialogmote: NewDialogmote, commit: Boolean = true, - newDialogmote: NewDialogmote ): Pair { val moteUuid = UUID.randomUUID() val now = Timestamp.from(Instant.now()) diff --git a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/TildelDialogmoteApiV2Spek.kt b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/TildelDialogmoteApiV2Spek.kt index 672e160d..d12f7594 100644 --- a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/TildelDialogmoteApiV2Spek.kt +++ b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/TildelDialogmoteApiV2Spek.kt @@ -18,7 +18,6 @@ import no.nav.syfo.dialogmote.api.domain.TildelDialogmoterDTO import no.nav.syfo.dialogmote.database.createNewDialogmoteWithReferences import no.nav.syfo.testhelper.* import no.nav.syfo.testhelper.generator.generateNewDialogmote -import no.nav.syfo.testhelper.generator.generateNewDialogmoteDTO import no.nav.syfo.util.bearerHeader import no.nav.syfo.util.configuredJacksonMapper import org.amshove.kluent.shouldBeEqualTo @@ -75,31 +74,14 @@ class TildelDialogmoteApiV2Spek : Spek({ val urlMote = "$dialogmoteApiV2Basepath$dialogmoteApiPersonIdentUrlPath" val urlMoterEnhet = "$dialogmoteApiV2Basepath$dialogmoteApiEnhetUrlPath/${UserConstants.ENHET_NR.value}" val urlTildelMote = "$dialogmoteApiV2Basepath$dialogmoteTildelPath" - val newDialogmoteDTO = generateNewDialogmoteDTO(UserConstants.ARBEIDSTAKER_FNR) - val newDialogmoteDTOAnnenArbeidstaker = generateNewDialogmoteDTO(UserConstants.ARBEIDSTAKER_ANNEN_FNR) + val newDialogmote = generateNewDialogmote(UserConstants.ARBEIDSTAKER_FNR) + val newDialogmoteAnnenArbeidstaker = generateNewDialogmote(UserConstants.ARBEIDSTAKER_ANNEN_FNR) describe("Happy path") { it("should tildele dialogmoter if request is successful") { val createdDialogmoterUuids = mutableListOf() - - with( - handleRequest(HttpMethod.Post, urlMote) { - addHeader(HttpHeaders.Authorization, bearerHeader(veilederCallerToken)) - addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString()) - setBody(objectMapper.writeValueAsString(newDialogmoteDTO)) - } - ) { - response.status() shouldBeEqualTo HttpStatusCode.OK - } - with( - handleRequest(HttpMethod.Post, urlMote) { - addHeader(HttpHeaders.Authorization, bearerHeader(veilederCallerToken)) - addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString()) - setBody(objectMapper.writeValueAsString(newDialogmoteDTOAnnenArbeidstaker)) - } - ) { - response.status() shouldBeEqualTo HttpStatusCode.OK - } + database.connection.run { this.createNewDialogmoteWithReferences(newDialogmote) } + database.connection.run { this.createNewDialogmoteWithReferences(newDialogmoteAnnenArbeidstaker) } with( handleRequest(HttpMethod.Get, urlMoterEnhet) { @@ -209,16 +191,7 @@ class TildelDialogmoteApiV2Spek : Spek({ it("should return status Forbidden if contains dialogmøte with denied access to person") { val createdDialogmoterUuids = mutableListOf() - - with( - handleRequest(HttpMethod.Post, urlMote) { - addHeader(HttpHeaders.Authorization, bearerHeader(veilederCallerToken)) - addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString()) - setBody(objectMapper.writeValueAsString(newDialogmoteDTO)) - } - ) { - response.status() shouldBeEqualTo HttpStatusCode.OK - } + database.connection.run { this.createNewDialogmoteWithReferences(newDialogmote) } with( handleRequest(HttpMethod.Get, urlMoterEnhet) {