Skip to content

Commit c47115d

Browse files
committed
IS-1947: Refactor tests
1 parent bab620f commit c47115d

File tree

2 files changed

+15
-37
lines changed

2 files changed

+15
-37
lines changed

src/main/kotlin/no/nav/syfo/dialogmote/database/MoteQuery.kt

+10-5
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,15 @@ import no.nav.syfo.application.database.toList
55
import no.nav.syfo.cronjob.statusendring.toInstantOslo
66
import no.nav.syfo.dialogmote.database.domain.PDialogmote
77
import no.nav.syfo.dialogmote.database.domain.PMotedeltakerBehandlerVarsel
8-
import no.nav.syfo.dialogmote.domain.*
8+
import no.nav.syfo.dialogmote.domain.DialogmoteStatus
9+
import no.nav.syfo.dialogmote.domain.NewDialogmote
10+
import no.nav.syfo.dialogmote.domain.TidStedDTO
911
import no.nav.syfo.domain.EnhetNr
1012
import no.nav.syfo.domain.PersonIdent
11-
import java.sql.*
13+
import java.sql.Connection
14+
import java.sql.ResultSet
15+
import java.sql.SQLException
16+
import java.sql.Timestamp
1217
import java.time.Instant
1318
import java.time.LocalDateTime
1419
import java.util.*
@@ -135,12 +140,12 @@ data class CreatedDialogmoteIdentifiers(
135140
)
136141

137142
fun Connection.createNewDialogmoteWithReferences(
138-
commit: Boolean = true,
139143
newDialogmote: NewDialogmote,
144+
commit: Boolean = true,
140145
): CreatedDialogmoteIdentifiers {
141146
val moteIdList = this.createDialogmote(
147+
newDialogmote = newDialogmote,
142148
commit = false,
143-
newDialogmote = newDialogmote
144149
)
145150

146151
val moteId = moteIdList.first
@@ -181,8 +186,8 @@ fun Connection.createNewDialogmoteWithReferences(
181186
}
182187

183188
fun Connection.createDialogmote(
189+
newDialogmote: NewDialogmote,
184190
commit: Boolean = true,
185-
newDialogmote: NewDialogmote
186191
): Pair<Int, UUID> {
187192
val moteUuid = UUID.randomUUID()
188193
val now = Timestamp.from(Instant.now())

src/test/kotlin/no/nav/syfo/dialogmote/api/v2/TildelDialogmoteApiV2Spek.kt

+5-32
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import no.nav.syfo.dialogmote.api.domain.TildelDialogmoterDTO
1818
import no.nav.syfo.dialogmote.database.createNewDialogmoteWithReferences
1919
import no.nav.syfo.testhelper.*
2020
import no.nav.syfo.testhelper.generator.generateNewDialogmote
21-
import no.nav.syfo.testhelper.generator.generateNewDialogmoteDTO
2221
import no.nav.syfo.util.bearerHeader
2322
import no.nav.syfo.util.configuredJacksonMapper
2423
import org.amshove.kluent.shouldBeEqualTo
@@ -75,31 +74,14 @@ class TildelDialogmoteApiV2Spek : Spek({
7574
val urlMote = "$dialogmoteApiV2Basepath$dialogmoteApiPersonIdentUrlPath"
7675
val urlMoterEnhet = "$dialogmoteApiV2Basepath$dialogmoteApiEnhetUrlPath/${UserConstants.ENHET_NR.value}"
7776
val urlTildelMote = "$dialogmoteApiV2Basepath$dialogmoteTildelPath"
78-
val newDialogmoteDTO = generateNewDialogmoteDTO(UserConstants.ARBEIDSTAKER_FNR)
79-
val newDialogmoteDTOAnnenArbeidstaker = generateNewDialogmoteDTO(UserConstants.ARBEIDSTAKER_ANNEN_FNR)
77+
val newDialogmote = generateNewDialogmote(UserConstants.ARBEIDSTAKER_FNR)
78+
val newDialogmoteAnnenArbeidstaker = generateNewDialogmote(UserConstants.ARBEIDSTAKER_ANNEN_FNR)
8079

8180
describe("Happy path") {
8281
it("should tildele dialogmoter if request is successful") {
8382
val createdDialogmoterUuids = mutableListOf<UUID>()
84-
85-
with(
86-
handleRequest(HttpMethod.Post, urlMote) {
87-
addHeader(HttpHeaders.Authorization, bearerHeader(veilederCallerToken))
88-
addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString())
89-
setBody(objectMapper.writeValueAsString(newDialogmoteDTO))
90-
}
91-
) {
92-
response.status() shouldBeEqualTo HttpStatusCode.OK
93-
}
94-
with(
95-
handleRequest(HttpMethod.Post, urlMote) {
96-
addHeader(HttpHeaders.Authorization, bearerHeader(veilederCallerToken))
97-
addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString())
98-
setBody(objectMapper.writeValueAsString(newDialogmoteDTOAnnenArbeidstaker))
99-
}
100-
) {
101-
response.status() shouldBeEqualTo HttpStatusCode.OK
102-
}
83+
database.connection.run { this.createNewDialogmoteWithReferences(newDialogmote) }
84+
database.connection.run { this.createNewDialogmoteWithReferences(newDialogmoteAnnenArbeidstaker) }
10385

10486
with(
10587
handleRequest(HttpMethod.Get, urlMoterEnhet) {
@@ -209,16 +191,7 @@ class TildelDialogmoteApiV2Spek : Spek({
209191

210192
it("should return status Forbidden if contains dialogmøte with denied access to person") {
211193
val createdDialogmoterUuids = mutableListOf<UUID>()
212-
213-
with(
214-
handleRequest(HttpMethod.Post, urlMote) {
215-
addHeader(HttpHeaders.Authorization, bearerHeader(veilederCallerToken))
216-
addHeader(HttpHeaders.ContentType, ContentType.Application.Json.toString())
217-
setBody(objectMapper.writeValueAsString(newDialogmoteDTO))
218-
}
219-
) {
220-
response.status() shouldBeEqualTo HttpStatusCode.OK
221-
}
194+
database.connection.run { this.createNewDialogmoteWithReferences(newDialogmote) }
222195

223196
with(
224197
handleRequest(HttpMethod.Get, urlMoterEnhet) {

0 commit comments

Comments
 (0)