From 7f3c27aed2d7d1b284eb1ad383ff3fae49c75d78 Mon Sep 17 00:00:00 2001 From: Eirik Dahlen Date: Thu, 31 Oct 2024 14:53:18 +0100 Subject: [PATCH] IS: Move motestatusendring queries inside repository MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prøver å rydde litt i repoet i kjølevannet av nytt endepunkt for møtestatusendring --- src/main/kotlin/no/nav/syfo/App.kt | 1 + .../no/nav/syfo/cronjob/CronjobModule.kt | 3 + .../PublishDialogmoteStatusEndringService.kt | 25 ++-- .../dialogmote/DialogmotestatusService.kt | 3 +- .../database/MoteStatusEndretQuery.kt | 112 ------------------ .../repository/MoteStatusEndretRepository.kt | 93 +++++++++++++++ ...blishDialogmoteStatusEndringCronjobSpek.kt | 4 + .../api/v2/AvlysDialogmoteApiV2Spek.kt | 7 +- ...ogmoteApiV2AllowVarselMedFysiskBrevSpek.kt | 5 +- .../api/v2/FerdigstillDialogmoteApiV2Spek.kt | 5 +- ...ogmoteApiV2AllowVarselMedFysiskBrevSpek.kt | 5 +- .../api/v2/PostDialogmoteApiV2Spek.kt | 7 +- .../api/v2/PostDialogmoteTidStedApiV2Spek.kt | 5 +- .../no/nav/syfo/janitor/JanitorServiceSpek.kt | 10 +- 14 files changed, 146 insertions(+), 139 deletions(-) delete mode 100644 src/main/kotlin/no/nav/syfo/dialogmote/database/MoteStatusEndretQuery.kt diff --git a/src/main/kotlin/no/nav/syfo/App.kt b/src/main/kotlin/no/nav/syfo/App.kt index 3eed9e3a..9b1876f4 100644 --- a/src/main/kotlin/no/nav/syfo/App.kt +++ b/src/main/kotlin/no/nav/syfo/App.kt @@ -167,6 +167,7 @@ fun main() { dialogmotestatusService = dialogmotestatusService, dialogmoterelasjonService = dialogmoterelasjonService, arbeidstakerVarselService = arbeidstakerVarselService, + moteStatusEndretRepository = moteStatusEndretRepository, ) } } diff --git a/src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt b/src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt index b4e15f7a..e9702418 100644 --- a/src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt +++ b/src/main/kotlin/no/nav/syfo/cronjob/CronjobModule.kt @@ -26,6 +26,7 @@ import no.nav.syfo.cronjob.statusendring.kafkaDialogmoteStatusEndringProducerCon import no.nav.syfo.dialogmote.* import no.nav.syfo.cronjob.dialogmotesvar.KDialogmotesvar import no.nav.syfo.dialogmote.avro.KDialogmoteStatusEndring +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository import org.apache.kafka.clients.producer.KafkaProducer fun Application.cronjobModule( @@ -36,6 +37,7 @@ fun Application.cronjobModule( dialogmotestatusService: DialogmotestatusService, dialogmoterelasjonService: DialogmoterelasjonService, arbeidstakerVarselService: ArbeidstakerVarselService, + moteStatusEndretRepository: MoteStatusEndretRepository, ) { val azureAdV2Client = AzureAdV2Client( aadAppClient = environment.aadAppClient, @@ -96,6 +98,7 @@ fun Application.cronjobModule( val publishDialogmoteStatusEndringService = PublishDialogmoteStatusEndringService( database = database, dialogmoteStatusEndringProducer = dialogmoteStatusEndringProducer, + moteStatusEndretRepository = moteStatusEndretRepository, ) val publishDialogmotesvarService = PublishDialogmotesvarService( database = database, diff --git a/src/main/kotlin/no/nav/syfo/cronjob/statusendring/PublishDialogmoteStatusEndringService.kt b/src/main/kotlin/no/nav/syfo/cronjob/statusendring/PublishDialogmoteStatusEndringService.kt index 9f67650b..d8a91c13 100644 --- a/src/main/kotlin/no/nav/syfo/cronjob/statusendring/PublishDialogmoteStatusEndringService.kt +++ b/src/main/kotlin/no/nav/syfo/cronjob/statusendring/PublishDialogmoteStatusEndringService.kt @@ -2,19 +2,30 @@ package no.nav.syfo.cronjob.statusendring import no.nav.syfo.application.database.DatabaseInterface import no.nav.syfo.dialogmote.avro.KDialogmoteStatusEndring -import no.nav.syfo.dialogmote.database.* -import no.nav.syfo.dialogmote.database.domain.* -import no.nav.syfo.dialogmote.domain.* +import no.nav.syfo.dialogmote.database.domain.PDialogmote +import no.nav.syfo.dialogmote.database.domain.toDialogmoteStatusEndret +import no.nav.syfo.dialogmote.database.domain.toDialogmoteTidSted +import no.nav.syfo.dialogmote.database.getDialogmote +import no.nav.syfo.dialogmote.database.getMoteDeltakerArbeidsgiver +import no.nav.syfo.dialogmote.database.getMoteDeltakerArbeidstaker +import no.nav.syfo.dialogmote.database.getTidSted +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository +import no.nav.syfo.dialogmote.domain.DialogmoteStatusEndret +import no.nav.syfo.dialogmote.domain.DialogmoteTidSted +import no.nav.syfo.dialogmote.domain.latest import no.nav.syfo.domain.PersonIdent import no.nav.syfo.domain.Virksomhetsnummer -import java.time.* +import java.time.Instant +import java.time.LocalDateTime +import java.time.ZoneId class PublishDialogmoteStatusEndringService( private val database: DatabaseInterface, private val dialogmoteStatusEndringProducer: DialogmoteStatusEndringProducer, + private val moteStatusEndretRepository: MoteStatusEndretRepository, ) { fun getDialogmoteStatuEndretToPublishList(): List { - return database.getMoteStatusEndretNotPublished().map { + return moteStatusEndretRepository.getMoteStatusEndretNotPublished().map { it.toDialogmoteStatusEndret() } } @@ -34,8 +45,8 @@ class PublishDialogmoteStatusEndringService( virksomhetsnummer = database.getMoteDeltakerArbeidsgiver(moteId).virksomhetsnummer, ) dialogmoteStatusEndringProducer.sendDialogmoteStatusEndring(kDialogmoteStatusEndring) - - database.updateMoteStatusEndretPublishedAt( + + moteStatusEndretRepository.updateMoteStatusEndretPublishedAt( moteStatusEndretId = dialogmoteStatusEndret.id, ) } diff --git a/src/main/kotlin/no/nav/syfo/dialogmote/DialogmotestatusService.kt b/src/main/kotlin/no/nav/syfo/dialogmote/DialogmotestatusService.kt index 4b7a53cc..a355728f 100644 --- a/src/main/kotlin/no/nav/syfo/dialogmote/DialogmotestatusService.kt +++ b/src/main/kotlin/no/nav/syfo/dialogmote/DialogmotestatusService.kt @@ -97,7 +97,8 @@ class DialogmotestatusService( ) } - connection.createMoteStatusEndring( + moteStatusEndretRepository.createMoteStatusEndring( + connection = connection, commit = false, moteId = dialogmoteId, opprettetAv = opprettetAv, diff --git a/src/main/kotlin/no/nav/syfo/dialogmote/database/MoteStatusEndretQuery.kt b/src/main/kotlin/no/nav/syfo/dialogmote/database/MoteStatusEndretQuery.kt deleted file mode 100644 index e3fe48c2..00000000 --- a/src/main/kotlin/no/nav/syfo/dialogmote/database/MoteStatusEndretQuery.kt +++ /dev/null @@ -1,112 +0,0 @@ -package no.nav.syfo.dialogmote.database - -import no.nav.syfo.application.database.DatabaseInterface -import no.nav.syfo.application.database.toList -import no.nav.syfo.dialogmote.database.domain.PMoteStatusEndret -import no.nav.syfo.dialogmote.domain.DialogmoteStatus -import java.sql.* -import java.time.* -import java.util.* - -const val queryCreateMoteStatusEndring = - """ - INSERT INTO MOTE_STATUS_ENDRET ( - id, - uuid, - created_at, - updated_at, - mote_id, - status, - opprettet_av, - tilfelle_start, - motedeltaker_behandler - ) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id - """ - -fun Connection.createMoteStatusEndring( - commit: Boolean = true, - moteId: Int, - opprettetAv: String, - status: DialogmoteStatus, - tilfelleStart: LocalDate?, - isBehandlerMotedeltaker: Boolean, -): Pair { - val now = Timestamp.from(Instant.now()) - val startDate = tilfelleStart ?: LocalDate.EPOCH - - val moteStatusEndringUuid = UUID.randomUUID() - - val moteStatusEndringIdList = this.prepareStatement(queryCreateMoteStatusEndring).use { - it.setString(1, moteStatusEndringUuid.toString()) - it.setTimestamp(2, now) - it.setTimestamp(3, now) - it.setInt(4, moteId) - it.setString(5, status.name) - it.setString(6, opprettetAv) - it.setTimestamp(7, Timestamp.valueOf(startDate.atStartOfDay())) - it.setBoolean(8, isBehandlerMotedeltaker) - it.executeQuery().toList { getInt("id") } - } - - if (moteStatusEndringIdList.size != 1) { - throw SQLException("Creating MoteStatusEndring failed, no rows affected.") - } - - if (commit) { - this.commit() - } - - return Pair(moteStatusEndringIdList.first(), moteStatusEndringUuid) -} - -const val queryMoteStatusEndretNotPublished = - """ - SELECT * - FROM MOTE_STATUS_ENDRET - WHERE published_at IS NULL - ORDER BY created_at ASC LIMIT 100 - """ - -fun DatabaseInterface.getMoteStatusEndretNotPublished(): List { - return this.connection.use { connection -> - connection.prepareStatement(queryMoteStatusEndretNotPublished).use { - it.executeQuery().toList { toPMoteStatusEndret() } - } - } -} - -const val queryUpdateMoteStatusEndretPublishedAt = - """ - UPDATE MOTE_STATUS_ENDRET - SET published_at = ?, updated_at = ? - WHERE id = ? - """ - -fun DatabaseInterface.updateMoteStatusEndretPublishedAt( - moteStatusEndretId: Int, -) { - val now = Timestamp.from(Instant.now()) - this.connection.use { connection -> - connection.prepareStatement(queryUpdateMoteStatusEndretPublishedAt).use { - it.setTimestamp(1, now) - it.setTimestamp(2, now) - it.setInt(3, moteStatusEndretId) - it.execute() - } - connection.commit() - } -} - -fun ResultSet.toPMoteStatusEndret(): PMoteStatusEndret = - PMoteStatusEndret( - id = getInt("id"), - uuid = UUID.fromString(getString("uuid")), - createdAt = getTimestamp("created_at").toLocalDateTime(), - updatedAt = getTimestamp("updated_at").toLocalDateTime(), - moteId = getInt("mote_id"), - motedeltakerBehandler = getBoolean("motedeltaker_behandler"), - status = DialogmoteStatus.valueOf(getString("status")), - opprettetAv = getString("opprettet_av"), - tilfelleStart = getTimestamp("tilfelle_start").toLocalDateTime().toLocalDate(), - publishedAt = getTimestamp("published_at")?.toLocalDateTime(), - ) diff --git a/src/main/kotlin/no/nav/syfo/dialogmote/database/repository/MoteStatusEndretRepository.kt b/src/main/kotlin/no/nav/syfo/dialogmote/database/repository/MoteStatusEndretRepository.kt index 42394474..889b427b 100644 --- a/src/main/kotlin/no/nav/syfo/dialogmote/database/repository/MoteStatusEndretRepository.kt +++ b/src/main/kotlin/no/nav/syfo/dialogmote/database/repository/MoteStatusEndretRepository.kt @@ -7,7 +7,12 @@ import no.nav.syfo.dialogmote.database.domain.toDialogmoteStatusEndret import no.nav.syfo.dialogmote.domain.DialogmoteStatus import no.nav.syfo.dialogmote.domain.DialogmoteStatusEndret import no.nav.syfo.domain.PersonIdent +import java.sql.Connection import java.sql.ResultSet +import java.sql.SQLException +import java.sql.Timestamp +import java.time.Instant +import java.time.LocalDate import java.util.* class MoteStatusEndretRepository(private val database: DatabaseInterface) { @@ -22,6 +27,64 @@ class MoteStatusEndretRepository(private val database: DatabaseInterface) { } } + fun getMoteStatusEndretNotPublished(): List { + return database.connection.use { connection -> + connection.prepareStatement(GET_MOTE_STATUS_ENDRET_NOT_PUBLISHED).use { + it.executeQuery().toList { toPMoteStatusEndret() } + } + } + } + + fun updateMoteStatusEndretPublishedAt(moteStatusEndretId: Int) { + val now = Timestamp.from(Instant.now()) + database.connection.use { connection -> + connection.prepareStatement(UPDATE_MOTE_STATUS_ENDRET_PUBLISHED_AT).use { + it.setTimestamp(1, now) + it.setTimestamp(2, now) + it.setInt(3, moteStatusEndretId) + it.execute() + } + connection.commit() + } + } + + fun createMoteStatusEndring( + connection: Connection, + commit: Boolean = true, + moteId: Int, + opprettetAv: String, + status: DialogmoteStatus, + tilfelleStart: LocalDate?, + isBehandlerMotedeltaker: Boolean, + ): Pair { + val now = Timestamp.from(Instant.now()) + val startDate = tilfelleStart ?: LocalDate.EPOCH + + val moteStatusEndringUuid = UUID.randomUUID() + + val moteStatusEndringIdList = connection.prepareStatement(CREATE_MOTE_STATUS_ENDRING).use { + it.setString(1, moteStatusEndringUuid.toString()) + it.setTimestamp(2, now) + it.setTimestamp(3, now) + it.setInt(4, moteId) + it.setString(5, status.name) + it.setString(6, opprettetAv) + it.setTimestamp(7, Timestamp.valueOf(startDate.atStartOfDay())) + it.setBoolean(8, isBehandlerMotedeltaker) + it.executeQuery().toList { getInt("id") } + } + + if (moteStatusEndringIdList.size != 1) { + throw SQLException("Creating MoteStatusEndring failed, no rows affected.") + } + + if (commit) { + connection.commit() + } + + return Pair(moteStatusEndringIdList.first(), moteStatusEndringUuid) + } + companion object { private const val GET_MOTE_STATUS_ENDRINGER = """ @@ -31,6 +94,36 @@ class MoteStatusEndretRepository(private val database: DatabaseInterface) { INNER JOIN motedeltaker_arbeidstaker mda on m.id = mda.mote_id WHERE mda.personident = ? """ + + private const val CREATE_MOTE_STATUS_ENDRING = + """ + INSERT INTO MOTE_STATUS_ENDRET ( + id, + uuid, + created_at, + updated_at, + mote_id, + status, + opprettet_av, + tilfelle_start, + motedeltaker_behandler + ) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?, ?) RETURNING id + """ + + private const val GET_MOTE_STATUS_ENDRET_NOT_PUBLISHED = + """ + SELECT * + FROM MOTE_STATUS_ENDRET + WHERE published_at IS NULL + ORDER BY created_at ASC LIMIT 100 + """ + + private const val UPDATE_MOTE_STATUS_ENDRET_PUBLISHED_AT = + """ + UPDATE MOTE_STATUS_ENDRET + SET published_at = ?, updated_at = ? + WHERE id = ? + """ } } diff --git a/src/test/kotlin/no/nav/syfo/cronjob/statusendring/PublishDialogmoteStatusEndringCronjobSpek.kt b/src/test/kotlin/no/nav/syfo/cronjob/statusendring/PublishDialogmoteStatusEndringCronjobSpek.kt index 91059891..ad26c9d3 100644 --- a/src/test/kotlin/no/nav/syfo/cronjob/statusendring/PublishDialogmoteStatusEndringCronjobSpek.kt +++ b/src/test/kotlin/no/nav/syfo/cronjob/statusendring/PublishDialogmoteStatusEndringCronjobSpek.kt @@ -23,6 +23,7 @@ import no.nav.syfo.brev.esyfovarsel.EsyfovarselProducer import no.nav.syfo.brev.esyfovarsel.NarmesteLederHendelse import no.nav.syfo.dialogmote.api.domain.DialogmoteDTO import no.nav.syfo.dialogmote.api.v2.* +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository import no.nav.syfo.dialogmote.domain.DialogmoteStatus import no.nav.syfo.testhelper.* import no.nav.syfo.testhelper.generator.* @@ -44,6 +45,8 @@ class PublishDialogmoteStatusEndringCronjobSpek : Spek({ val externalMockEnvironment = ExternalMockEnvironment.getInstance() val database = externalMockEnvironment.database + + val moteStatusEndretRepository = MoteStatusEndretRepository(database) val behandlerDialogmeldingProducer = mockk() justRun { behandlerDialogmeldingProducer.sendDialogmelding(dialogmelding = any()) } @@ -72,6 +75,7 @@ class PublishDialogmoteStatusEndringCronjobSpek : Spek({ val publishDialogmoteStatusEndringService = PublishDialogmoteStatusEndringService( database = database, dialogmoteStatusEndringProducer = dialogmoteStatusEndringProducer, + moteStatusEndretRepository = moteStatusEndretRepository, ) val publishDialogmoteStatusEndringCronjob = PublishDialogmoteStatusEndringCronjob( diff --git a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/AvlysDialogmoteApiV2Spek.kt b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/AvlysDialogmoteApiV2Spek.kt index e72bf3bf..c50e24a8 100644 --- a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/AvlysDialogmoteApiV2Spek.kt +++ b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/AvlysDialogmoteApiV2Spek.kt @@ -21,7 +21,7 @@ import no.nav.syfo.brev.behandler.kafka.KafkaBehandlerDialogmeldingDTO import no.nav.syfo.brev.esyfovarsel.EsyfovarselProducer import no.nav.syfo.client.oppfolgingstilfelle.toLatestOppfolgingstilfelle import no.nav.syfo.dialogmote.api.domain.DialogmoteDTO -import no.nav.syfo.dialogmote.database.repository.getMoteStatusEndretNotPublished +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository import no.nav.syfo.dialogmote.domain.* import no.nav.syfo.testhelper.ExternalMockEnvironment import no.nav.syfo.testhelper.UserConstants.ARBEIDSTAKER_FNR @@ -55,6 +55,7 @@ class AvlysDialogmoteApiV2Spek : Spek({ behandlerDialogmeldingProducer = behandlerDialogmeldingProducer, ) val esyfovarselProducerMock = mockk(relaxed = true) + val moteStatusEndretRepository = MoteStatusEndretRepository(database) val altinnMock = mockk() val altinnResponse = ReceiptExternal() @@ -180,7 +181,7 @@ class AvlysDialogmoteApiV2Spek : Spek({ verify(exactly = 0) { behandlerDialogmeldingProducer.sendDialogmelding(any()) } - val moteStatusEndretList = database.getMoteStatusEndretNotPublished() + val moteStatusEndretList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() moteStatusEndretList.size shouldBeEqualTo 2 moteStatusEndretList.forEach { moteStatusEndret -> @@ -467,7 +468,7 @@ class AvlysDialogmoteApiV2Spek : Spek({ LocalDateTime.now().isBefore(newDialogmoteDTO.tidSted.tid) isTodayBeforeDialogmotetid shouldBeEqualTo false - val moteStatusEndretList = database.getMoteStatusEndretNotPublished() + val moteStatusEndretList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() moteStatusEndretList.size shouldBeEqualTo 2 moteStatusEndretList.forEach { moteStatusEndret -> diff --git a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/FerdigstillDialogmoteApiV2AllowVarselMedFysiskBrevSpek.kt b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/FerdigstillDialogmoteApiV2AllowVarselMedFysiskBrevSpek.kt index 43bba9d2..6775c94b 100644 --- a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/FerdigstillDialogmoteApiV2AllowVarselMedFysiskBrevSpek.kt +++ b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/FerdigstillDialogmoteApiV2AllowVarselMedFysiskBrevSpek.kt @@ -14,8 +14,8 @@ import no.nav.syfo.brev.esyfovarsel.HendelseType import no.nav.syfo.client.oppfolgingstilfelle.toLatestOppfolgingstilfelle import no.nav.syfo.dialogmote.PdfService import no.nav.syfo.dialogmote.api.domain.DialogmoteDTO -import no.nav.syfo.dialogmote.database.repository.getMoteStatusEndretNotPublished import no.nav.syfo.dialogmote.database.getReferat +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository import no.nav.syfo.dialogmote.domain.DialogmoteStatus import no.nav.syfo.dialogmote.domain.DocumentComponentType import no.nav.syfo.testhelper.* @@ -46,6 +46,7 @@ class FerdigstillDialogmoteApiV2AllowVarselMedFysiskBrevSpek : Spek({ val externalMockEnvironment = ExternalMockEnvironment.getInstance() val database = externalMockEnvironment.database + val moteStatusEndretRepository = MoteStatusEndretRepository(database) val esyfovarselHendelse = generateInkallingHendelse() val esyfovarselProducerMock = mockk(relaxed = true) @@ -179,7 +180,7 @@ class FerdigstillDialogmoteApiV2AllowVarselMedFysiskBrevSpek : Spek({ pdfService.getPdf(database.getReferat(UUID.fromString(referat.uuid)).first().pdfId!!) pdf shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfReferat - val moteStatusEndretList = database.getMoteStatusEndretNotPublished() + val moteStatusEndretList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() moteStatusEndretList.size shouldBeEqualTo 2 moteStatusEndretList.forEach { moteStatusEndret -> diff --git a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/FerdigstillDialogmoteApiV2Spek.kt b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/FerdigstillDialogmoteApiV2Spek.kt index f61b22d8..61c9ab01 100644 --- a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/FerdigstillDialogmoteApiV2Spek.kt +++ b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/FerdigstillDialogmoteApiV2Spek.kt @@ -16,8 +16,8 @@ import no.nav.syfo.client.oppfolgingstilfelle.toLatestOppfolgingstilfelle import no.nav.syfo.dialogmote.PdfService import no.nav.syfo.dialogmote.api.domain.DialogmoteDTO import no.nav.syfo.dialogmote.api.domain.NewDialogmoteDTO -import no.nav.syfo.dialogmote.database.repository.getMoteStatusEndretNotPublished import no.nav.syfo.dialogmote.database.getReferat +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository import no.nav.syfo.dialogmote.domain.* import no.nav.syfo.testhelper.ExternalMockEnvironment import no.nav.syfo.testhelper.UserConstants.ARBEIDSTAKER_FNR @@ -49,6 +49,7 @@ class FerdigstillDialogmoteApiV2Spek : Spek({ val externalMockEnvironment = ExternalMockEnvironment.getInstance() val database = externalMockEnvironment.database + val moteStatusEndretRepository = MoteStatusEndretRepository(database) val behandlerDialogmeldingProducer = mockk() justRun { behandlerDialogmeldingProducer.sendDialogmelding(any()) } @@ -160,7 +161,7 @@ class FerdigstillDialogmoteApiV2Spek : Spek({ pdfService.getPdf(database.getReferat(UUID.fromString(referat.uuid)).first().pdfId!!) pdf shouldBeEqualTo externalMockEnvironment.ispdfgenMock.pdfReferat - val moteStatusEndretList = database.getMoteStatusEndretNotPublished() + val moteStatusEndretList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() moteStatusEndretList.size shouldBeEqualTo 2 moteStatusEndretList.forEach { moteStatusEndret -> diff --git a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteApiV2AllowVarselMedFysiskBrevSpek.kt b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteApiV2AllowVarselMedFysiskBrevSpek.kt index 8235513e..7fe3a792 100644 --- a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteApiV2AllowVarselMedFysiskBrevSpek.kt +++ b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteApiV2AllowVarselMedFysiskBrevSpek.kt @@ -19,7 +19,7 @@ import no.altinn.services.serviceengine.correspondence._2009._10.ICorrespondence import no.nav.syfo.brev.esyfovarsel.EsyfovarselProducer import no.nav.syfo.client.oppfolgingstilfelle.toLatestOppfolgingstilfelle import no.nav.syfo.dialogmote.api.domain.DialogmoteDTO -import no.nav.syfo.dialogmote.database.repository.getMoteStatusEndretNotPublished +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository import no.nav.syfo.dialogmote.domain.DocumentComponentType import no.nav.syfo.dialogmote.domain.MotedeltakerVarselType import no.nav.syfo.testhelper.* @@ -49,6 +49,7 @@ class PostDialogmoteApiV2AllowVarselMedFysiskBrevSpek : Spek({ val externalMockEnvironment = ExternalMockEnvironment.getInstance() val database = externalMockEnvironment.database + val moteStatusEndretRepository = MoteStatusEndretRepository(database) val altinnMock = mockk() val esyfovarselHendelse = generateInkallingHendelse() @@ -166,7 +167,7 @@ class PostDialogmoteApiV2AllowVarselMedFysiskBrevSpek : Spek({ dialogmoteDTO.sted shouldBeEqualTo newDialogmoteDTO.tidSted.sted dialogmoteDTO.videoLink shouldBeEqualTo "https://meet.google.com/xyz" - val moteStatusEndretList = database.getMoteStatusEndretNotPublished() + val moteStatusEndretList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() moteStatusEndretList.size shouldBeEqualTo 1 moteStatusEndretList.first().status.name shouldBeEqualTo dialogmoteDTO.status diff --git a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteApiV2Spek.kt b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteApiV2Spek.kt index df0cd613..58a11f52 100644 --- a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteApiV2Spek.kt +++ b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteApiV2Spek.kt @@ -22,7 +22,7 @@ import no.nav.syfo.brev.behandler.kafka.KafkaBehandlerDialogmeldingDTO import no.nav.syfo.brev.esyfovarsel.EsyfovarselProducer import no.nav.syfo.client.oppfolgingstilfelle.toLatestOppfolgingstilfelle import no.nav.syfo.dialogmote.api.domain.DialogmoteDTO -import no.nav.syfo.dialogmote.database.repository.getMoteStatusEndretNotPublished +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository import no.nav.syfo.dialogmote.domain.* import no.nav.syfo.testhelper.ExternalMockEnvironment import no.nav.syfo.testhelper.UserConstants.ARBEIDSTAKER_FNR @@ -62,6 +62,7 @@ class PostDialogmoteApiV2Spek : Spek({ val database = externalMockEnvironment.database val behandlerDialogmeldingProducer = mockk() + val moteStatusEndretRepository = MoteStatusEndretRepository(database) val esyfovarselHendelse = generateInkallingHendelse() val esyfovarselProducerMock = mockk(relaxed = true) @@ -199,7 +200,7 @@ class PostDialogmoteApiV2Spek : Spek({ dialogmoteDTO.sted shouldBeEqualTo newDialogmoteDTO.tidSted.sted dialogmoteDTO.videoLink shouldBeEqualTo "https://meet.google.com/xyz" - val moteStatusEndretList = database.getMoteStatusEndretNotPublished() + val moteStatusEndretList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() moteStatusEndretList.size shouldBeEqualTo 1 moteStatusEndretList.first().status.name shouldBeEqualTo dialogmoteDTO.status @@ -373,7 +374,7 @@ class PostDialogmoteApiV2Spek : Spek({ clearMocks(esyfovarselProducerMock) } - val moteStatusEndretList = database.getMoteStatusEndretNotPublished() + val moteStatusEndretList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() moteStatusEndretList.size shouldBeEqualTo 1 moteStatusEndretList.first().status.name shouldBeEqualTo DialogmoteStatus.INNKALT.name diff --git a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteTidStedApiV2Spek.kt b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteTidStedApiV2Spek.kt index 90668485..9683cb8f 100644 --- a/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteTidStedApiV2Spek.kt +++ b/src/test/kotlin/no/nav/syfo/dialogmote/api/v2/PostDialogmoteTidStedApiV2Spek.kt @@ -27,7 +27,7 @@ import no.nav.syfo.dialogmelding.domain.SvarType import no.nav.syfo.dialogmote.api.domain.DialogmoteDTO import no.nav.syfo.dialogmote.api.domain.EndreTidStedBegrunnelseDTO import no.nav.syfo.dialogmote.api.domain.EndreTidStedDialogmoteDTO -import no.nav.syfo.dialogmote.database.repository.getMoteStatusEndretNotPublished +import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository import no.nav.syfo.dialogmote.domain.* import no.nav.syfo.testhelper.ExternalMockEnvironment import no.nav.syfo.testhelper.UserConstants.ARBEIDSTAKER_FNR @@ -56,6 +56,7 @@ class PostDialogmoteTidStedApiV2Spek : Spek({ val externalMockEnvironment = ExternalMockEnvironment.getInstance() val database = externalMockEnvironment.database val esyfovarselEndringHendelse = generateEndringHendelse() + val moteStatusEndretRepository = MoteStatusEndretRepository(database) val esyfovarselProducerMock = mockk(relaxed = true) justRun { esyfovarselProducerMock.sendVarselToEsyfovarsel(esyfovarselEndringHendelse) } @@ -222,7 +223,7 @@ class PostDialogmoteTidStedApiV2Spek : Spek({ verify(exactly = 1) { esyfovarselProducerMock.sendVarselToEsyfovarsel(esyfovarselEndringHendelse) } verify(exactly = 1) { esyfovarselProducerMock.sendVarselToEsyfovarsel(esyfovarselEndringHendelse) } - val moteStatusEndretList = database.getMoteStatusEndretNotPublished() + val moteStatusEndretList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() moteStatusEndretList.size shouldBeEqualTo 2 moteStatusEndretList.forEach { moteStatusEndret -> diff --git a/src/test/kotlin/no/nav/syfo/janitor/JanitorServiceSpek.kt b/src/test/kotlin/no/nav/syfo/janitor/JanitorServiceSpek.kt index 973163e5..dc9f2800 100644 --- a/src/test/kotlin/no/nav/syfo/janitor/JanitorServiceSpek.kt +++ b/src/test/kotlin/no/nav/syfo/janitor/JanitorServiceSpek.kt @@ -18,7 +18,6 @@ import no.nav.syfo.dialogmote.api.v2.dialogmoteApiPersonIdentUrlPath import no.nav.syfo.dialogmote.api.v2.dialogmoteApiV2Basepath import no.nav.syfo.dialogmote.database.getDialogmoteList import no.nav.syfo.dialogmote.database.repository.MoteStatusEndretRepository -import no.nav.syfo.dialogmote.database.repository.getMoteStatusEndretNotPublished import no.nav.syfo.dialogmote.domain.DialogmoteStatus import no.nav.syfo.janitor.kafka.* import no.nav.syfo.testhelper.* @@ -57,9 +56,10 @@ class JanitorServiceSpek : Spek({ val eventStatusProducerMock = mockk(relaxed = true) justRun { eventStatusProducerMock.sendEventStatus(any()) } + val moteStatusEndretRepository = MoteStatusEndretRepository(database) val dialogmotestatusService = DialogmotestatusService( oppfolgingstilfelleClient = mockk(relaxed = true), - moteStatusEndretRepository = MoteStatusEndretRepository(database), + moteStatusEndretRepository = moteStatusEndretRepository, ) val dialogmotedeltakerService = DialogmotedeltakerService(database = database, arbeidstakerVarselService = mockk()) @@ -128,7 +128,7 @@ class JanitorServiceSpek : Spek({ ) runBlocking { janitorService.handle(event) } - val motestatusList = database.getMoteStatusEndretNotPublished() + val motestatusList = moteStatusEndretRepository.getMoteStatusEndretNotPublished() motestatusList.shouldNotBeEmpty() val motestatus = motestatusList.last() motestatus.status shouldBeEqualTo DialogmoteStatus.LUKKET @@ -224,8 +224,8 @@ class JanitorServiceSpek : Spek({ ) ) } - - database.getMoteStatusEndretNotPublished().shouldBeEmpty() + + moteStatusEndretRepository.getMoteStatusEndretNotPublished().shouldBeEmpty() verify(exactly = 0) { eventStatusProducerMock.sendEventStatus(any()) } } }