Skip to content

Commit

Permalink
IS-1947: Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vetlesolgaard committed Feb 5, 2024
1 parent 5860ce8 commit af517a3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 37 deletions.
15 changes: 10 additions & 5 deletions src/main/kotlin/no/nav/syfo/dialogmote/database/MoteQuery.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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.*
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -181,8 +186,8 @@ fun Connection.createNewDialogmoteWithReferences(
}

fun Connection.createDialogmote(
newDialogmote: NewDialogmote,
commit: Boolean = true,
newDialogmote: NewDialogmote
): Pair<Int, UUID> {
val moteUuid = UUID.randomUUID()
val now = Timestamp.from(Instant.now())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<UUID>()

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) {
Expand Down Expand Up @@ -209,16 +191,7 @@ class TildelDialogmoteApiV2Spek : Spek({

it("should return status Forbidden if contains dialogmøte with denied access to person") {
val createdDialogmoterUuids = mutableListOf<UUID>()

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) {
Expand Down

0 comments on commit af517a3

Please sign in to comment.