Skip to content

Commit

Permalink
chore: fix tests and try to fix build
Browse files Browse the repository at this point in the history
Co-authored-by: Natalie Uranes <[email protected]>
Co-authored-by: Jørn-Are Flaten <[email protected]>
  • Loading branch information
3 people committed Nov 21, 2024
1 parent d9e739f commit d371f90
Show file tree
Hide file tree
Showing 17 changed files with 98 additions and 62 deletions.
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ dependencies {
because("overstyrer sårbar dependency fra com.opentable.components:otj-pg-embedded")
}
}
testImplementation(kotlin("test"))
}

tasks {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,22 @@ class DokarkivClient(
oppdaterJournalpostRequest: OppdaterJournalpostRequest,
sykmeldingId: String,
journalpostId: String,
) {
): ResponseEntity<String> {
val headers = HttpHeaders()
headers.contentType = MediaType.APPLICATION_JSON
headers.accept = listOf(MediaType.APPLICATION_JSON)
headers["Nav-Callid"] = sykmeldingId

try {
securelog.info("createOppdaterJournalpostRequest: ${objectMapper.writeValueAsString(oppdaterJournalpostRequest)}")
dokarkivRestTemplate.exchange(
val response = dokarkivRestTemplate.exchange(
"$url/$journalpostId",
HttpMethod.PUT,
HttpEntity(oppdaterJournalpostRequest, headers),
String::class.java,
)
log.info("Oppdatert journalpost $journalpostId for sykmelding $sykmeldingId")
return response
} catch (e: HttpClientErrorException) {
if (e.statusCode.value() == 401 || e.statusCode.value() == 403) {
log.warn("Veileder har ikke tilgang til å oppdatere journalpostId $journalpostId: ${e.message}")
Expand Down Expand Up @@ -425,7 +426,7 @@ class DokarkivClient(
listOf(
DokumentInfo(
dokumentInfoId = dokumentInfoId,
tittel = createTitleNasjonal(receivedSykmelding.sykmelding.perioder, avvist), //TODO skal receivedSykmelding være nullable?? why?
tittel = createTitleNasjonal(receivedSykmelding.sykmelding.perioder, avvist),
),
)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class NoOppgaveException(override val message: String) : RuntimeException(messag

class SykmelderNotFoundException(message: String) : RuntimeException(message)

class MissingJournalpostException(message: String) : RuntimeException(message)

class UnauthorizedException(message: String) : Exception(message)

class ValidationException(val validationResult: ValidationResult) : Exception()
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ class GlobalExceptionHandler {
return ResponseEntity.status(HttpStatus.NOT_FOUND).body("Sykmelder not found")
}

@ExceptionHandler(MissingJournalpostException::class)
fun handleMissingJournalpostException(e: MissingJournalpostException): ResponseEntity<String> {
log.error("Journalpost is missing: ${e.message}", e)
return ResponseEntity.status(HttpStatus.BAD_REQUEST).body("Journalpost is missing")
}

@ExceptionHandler(UnauthorizedException::class)
fun handleUnAuthorizedException(e: UnauthorizedException): ResponseEntity<String> {
log.warn("Caught UnauthorizedException ${e.message}", e)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package no.nav.sykdig.digitalisering.helsenett.client

import no.nav.sykdig.applog
import no.nav.sykdig.digitalisering.exceptions.SykmelderNotFoundException
import no.nav.sykdig.digitalisering.exceptions.UnauthorizedException
import no.nav.sykdig.digitalisering.helsenett.Behandler
import no.nav.sykdig.securelog
import org.springframework.beans.factory.annotation.Value
Expand All @@ -13,7 +11,6 @@ import org.springframework.http.HttpStatus
import org.springframework.stereotype.Component
import org.springframework.web.client.HttpClientErrorException
import org.springframework.web.client.RestTemplate
import java.io.IOException

@Component
class HelsenettClient(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class NasjonalSykmeldingService(
suspend fun sendPapirsykmelding(smRegistreringManuell: SmRegistreringManuell, navEnhet: String, callId: String, oppgaveId: Int): ResponseEntity<Any> {
val oppgave = nasjonalOppgaveService.findByOppgaveId(oppgaveId) ?: return ResponseEntity(HttpStatus.NOT_FOUND)
val sykmeldingId = oppgave.sykmeldingId
log.info("Forsøker å ferdigstille papirsykmelding med sykmeldingId $sykmeldingId")

val loggingMeta = getLoggingMeta(sykmeldingId, oppgave)
val sykmelder = getSykmelder(smRegistreringManuell, loggingMeta, callId)
Expand Down Expand Up @@ -113,18 +114,6 @@ class NasjonalSykmeldingService(
}

return handleOK(validationResult, receivedSykmelding.copy(validationResult = validationResult), ferdigstillRegistrering, loggingMeta)


// logging meta sykmeldingId, dokumentInfoId, journalpostId

// sender med et isUpdate - som sjekker om saksbehandler har superuseraccess. men dette brukes kun i endre, som ikke har blitt brukt

// sjekker om saksbehandler har tilgang, men jeg tror dette kan gjøres gjennom obo token i controlleren

// val sykmelderHpr
// val sykmelder = personServise.hentPerson(sykmeldderHpr) -- callId er en randomUUID - spørre seg om kanskje ha callId som sykmeldingId


}

private suspend fun handleOK(
Expand Down Expand Up @@ -156,7 +145,7 @@ class NasjonalSykmeldingService(
ferdigstiltAv = veileder.veilederIdent,
avvisningsgrunn = null,
)

log.info("Ferdigstilt papirsykmelding med sykmelding id ${receivedSykmelding.sykmelding.id}")
return ResponseEntity(HttpStatus.OK)
}
log.error(
Expand Down Expand Up @@ -319,7 +308,7 @@ class NasjonalSykmeldingService(
val nasjonalManuellOppgaveDAO =
NasjonalSykmeldingDAO(
sykmeldingId = receivedSykmelding.sykmelding.id,
sykmelding = receivedSykmelding,
sykmelding = receivedSykmelding.sykmelding,
timestamp = OffsetDateTime.now(ZoneOffset.UTC),
ferdigstiltAv = veileder.veilederIdent,
datoFerdigstilt = LocalDateTime.now(ZoneOffset.UTC),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,10 @@ class NasjonalOppgaveController(
@RequestHeader("X-Nav-Enhet") navEnhet: String,
@RequestBody papirSykmelding: SmRegistreringManuell,
): ResponseEntity<Any> {

// TODO: sjekk when oppgaveId er null: lage en guard og responder med bad request
// TODO: hvis accesstoken er null responder med unauthorized
val callId = UUID.randomUUID().toString()
nasjonalSykmeldingService.sendPapirsykmelding(papirSykmelding, navEnhet, callId, oppgaveId)
log.info("papirsykmelding: sender oppgave med oppgaveId $oppgaveId gjennom syk-dig proxy")
return smregistreringClient.postSendOppgaveRequest(authorization, oppgaveId, navEnhet, papirSykmelding)
return nasjonalSykmeldingService.sendPapirsykmelding(papirSykmelding, navEnhet, callId, oppgaveId)
//log.info("papirsykmelding: sender oppgave med oppgaveId $oppgaveId gjennom syk-dig proxy")
//return smregistreringClient.postSendOppgaveRequest(authorization, oppgaveId, navEnhet, papirSykmelding)
}

@GetMapping("/sykmelding/{sykmeldingId}/ferdigstilt")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package no.nav.sykdig.digitalisering.papirsykmelding.api

import net.logstash.logback.argument.StructuredArguments.kv
import no.nav.sykdig.applog
import no.nav.sykdig.digitalisering.papirsykmelding.db.model.ReceivedSykmeldingNasjonal
import no.nav.sykdig.digitalisering.sykmelding.ReceivedSykmelding
import no.nav.sykdig.digitalisering.sykmelding.ValidationResult
import no.nav.sykdig.securelog
import org.springframework.beans.factory.annotation.Value
Expand All @@ -24,7 +24,7 @@ class RegelClient(
val log = applog()
val securelog = securelog()

fun valider(sykmelding: ReceivedSykmeldingNasjonal, msgId: String): ValidationResult {
fun valider(sykmelding: ReceivedSykmelding, msgId: String): ValidationResult {
log.info("validating against rules {}", kv("sykmeldingId", sykmelding.sykmelding.id))
val headers = HttpHeaders()
headers["Nav-CallId"] = msgId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.sykdig.digitalisering.papirsykmelding.api.model

import java.time.LocalDate
import no.nav.sykdig.digitalisering.exceptions.ValidationException
import no.nav.sykdig.digitalisering.felles.Periode
import no.nav.sykdig.digitalisering.sykmelding.RuleInfo
import no.nav.sykdig.digitalisering.sykmelding.Status
import no.nav.sykdig.digitalisering.sykmelding.ValidationResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package no.nav.sykdig.digitalisering.papirsykmelding.db.model

import jakarta.persistence.GeneratedValue
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.Sykmelding
import no.nav.sykdig.digitalisering.felles.Sykmelding
import org.springframework.data.annotation.Id
import org.springframework.data.relational.core.mapping.Column
import org.springframework.data.relational.core.mapping.Table
import java.time.LocalDateTime
import java.time.OffsetDateTime
import java.util.UUID
import java.util.*

@Table(name = "nasjonal_sykmelding")
open class NasjonalSykmeldingDAO(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.sykdig.digitalisering.saf

import no.nav.syfo.oppgave.saf.model.DokumentMedTittel
import no.nav.sykdig.applog
import no.nav.sykdig.digitalisering.exceptions.MissingJournalpostException
import no.nav.sykdig.digitalisering.saf.graphql.DokumentInfo
import no.nav.sykdig.digitalisering.saf.graphql.Journalstatus
import no.nav.sykdig.digitalisering.saf.graphql.SafJournalpost
Expand Down Expand Up @@ -58,7 +59,7 @@ class SafJournalpostService(

fun erIkkeJournalfort(journalpostId: String): Boolean {
val journalpost = safJournalpostGraphQlClient.getJournalpostM2m(journalpostId)
if (journalpost.journalpost == null) return false
if (journalpost.journalpost == null) throw MissingJournalpostException("Journalpost med id $journalpostId finnes ikke i SAF")
return erIkkeJournalfort(journalpost.journalpost)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import no.nav.sykdig.applog
import no.nav.sykdig.digitalisering.SykDigOppgaveService
import no.nav.sykdig.digitalisering.dokarkiv.DokarkivClient
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.FerdigstillRegistrering
import no.nav.sykdig.digitalisering.papirsykmelding.db.model.ReceivedSykmeldingNasjonal
import no.nav.sykdig.digitalisering.pdl.PersonService
import no.nav.sykdig.digitalisering.saf.SafJournalpostService
import no.nav.sykdig.digitalisering.saf.graphql.SafJournalpost
import no.nav.sykdig.digitalisering.saf.graphql.TEMA_SYKEPENGER
import no.nav.sykdig.digitalisering.saf.graphql.TEMA_SYKMELDING
import no.nav.sykdig.digitalisering.saf.graphql.Type
import no.nav.sykdig.digitalisering.sykmelding.ReceivedSykmelding
import no.nav.sykdig.digitalisering.sykmelding.db.JournalpostSykmeldingRepository
import no.nav.sykdig.generated.types.Document
import no.nav.sykdig.generated.types.Journalpost
Expand Down Expand Up @@ -131,7 +131,7 @@ class JournalpostService(
}
suspend fun ferdigstillJournalpost(
ferdigstillRegistrering: FerdigstillRegistrering,
receivedSykmelding: ReceivedSykmeldingNasjonal?,
receivedSykmelding: ReceivedSykmelding,
loggingMeta: LoggingMeta,
) {
if (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import no.nav.helse.sm2013.NavnType
import no.nav.helse.sm2013.TeleCom
import no.nav.helse.sm2013.URL
import no.nav.sykdig.applog
import no.nav.sykdig.digitalisering.felles.*
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.*
import no.nav.sykdig.digitalisering.pdl.Person
import no.nav.sykdig.digitalisering.pdl.client.graphql.PdlPerson
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import no.nav.helse.sm2013.ArsakType
import no.nav.helse.sm2013.CS
import no.nav.helse.sm2013.CV
import no.nav.helse.sm2013.HelseOpplysningerArbeidsuforhet
import no.nav.sykdig.digitalisering.felles.*
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.*

fun HelseOpplysningerArbeidsuforhet.toSykmelding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.mockk.mockk
import kotlinx.coroutines.runBlocking
import no.nav.sykdig.digitalisering.exceptions.SykmelderNotFoundException
import no.nav.sykdig.digitalisering.helsenett.client.HelsenettClient
import no.nav.sykdig.digitalisering.helsenett.client.SmtssClient
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.Godkjenning
import no.nav.sykdig.digitalisering.papirsykmelding.api.model.Kode
import no.nav.sykdig.digitalisering.pdl.Navn
Expand All @@ -18,7 +19,9 @@ import org.junit.jupiter.api.Test
class SykmelderServiceTest {
private val pdlService = mockk<PersonService>()
private val helsenettClient = mockk<HelsenettClient>()
private val sykmelderService = SykmelderService(helsenettClient, pdlService)
private val personService = mockk<PersonService>()
private val smtssClient = mockk<SmtssClient>()
private val sykmelderService = SykmelderService(helsenettClient, personService, smtssClient)

@Test
fun `get sykmelder happy case`() {
Expand Down
84 changes: 56 additions & 28 deletions src/test/kotlin/no/nav/sykdig/saf/SafJournalpostServiceTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@ package no.nav.sykdig.saf

import io.mockk.every
import io.mockk.mockk
import no.nav.sykdig.digitalisering.exceptions.MissingJournalpostException
import no.nav.sykdig.digitalisering.saf.SafJournalpostGraphQlClient
import no.nav.sykdig.digitalisering.saf.SafJournalpostService
import no.nav.sykdig.digitalisering.saf.graphql.DokumentInfo
import no.nav.sykdig.digitalisering.saf.graphql.Dokumentvariant
import no.nav.sykdig.digitalisering.saf.graphql.Journalstatus
import no.nav.sykdig.digitalisering.saf.graphql.SafJournalpost
import no.nav.sykdig.digitalisering.saf.graphql.SafQueryJournalpost
import org.amshove.kluent.assertionError
import org.amshove.kluent.internal.assertFailsWith
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows

class SafJournalpostServiceTest {
private val safJournalpostGraphQlClient: SafJournalpostGraphQlClient = mockk()
Expand Down Expand Up @@ -116,35 +118,61 @@ class SafJournalpostServiceTest {
}

@Test
fun ``() {
fun `er ikke journalført fordi status er mottatt`() {
val journalpostId = "123"
val sykmeldingId = "syk-456"
val source = "rina"

every { safJournalpostGraphQlClient.getJournalpostM2m(journalpostId) } returns
SafQueryJournalpost(
SafJournalpost(
journalstatus = Journalstatus.MOTTATT,
dokumenter =
listOf(
DokumentInfo(
dokumentInfoId = "dok1",
tittel = "Dokument 1",
dokumentvarianter = listOf(Dokumentvariant(variantformat = "NON-ARKIV")),
brevkode = "1",
SafQueryJournalpost(
SafJournalpost(
journalstatus = Journalstatus.MOTTATT,
dokumenter =
listOf(
DokumentInfo(
dokumentInfoId = "dok1",
tittel = "Dokument 1",
dokumentvarianter = listOf(Dokumentvariant(variantformat = "NON-ARKIV")),
brevkode = "1",
),
),
),
kanal = "EESSI",
avsenderMottaker = null,
bruker = null,
tema = null,
),
)
kanal = "EESSI",
avsenderMottaker = null,
bruker = null,
tema = null,
),
)

val exception =
assertFailsWith<RuntimeException> {
safJournalpostService.getDokumenterM2m(journalpostId, sykmeldingId, source)
}
assertEquals("Journalpost mangler PDF, $sykmeldingId", exception.message)
val erIkkeJournalfort = safJournalpostService.erIkkeJournalfort(journalpostId)
assertTrue(erIkkeJournalfort)
}
@Test
fun `er ikke journalført fordi safjournalpost er null`() {
val journalpostId = "123"
every { safJournalpostGraphQlClient.getJournalpostM2m(journalpostId) } returns SafQueryJournalpost(null)
assertThrows<MissingJournalpostException>{safJournalpostService.erIkkeJournalfort(journalpostId)}
}
@Test
fun `er journalført fordi status er ukjent`() {
val journalpostId = "123"
every { safJournalpostGraphQlClient.getJournalpostM2m(journalpostId) } returns
SafQueryJournalpost(
SafJournalpost(
journalstatus = Journalstatus.UKJENT,
dokumenter =
listOf(
DokumentInfo(
dokumentInfoId = "dok1",
tittel = "Dokument 1",
dokumentvarianter = listOf(Dokumentvariant(variantformat = "NON-ARKIV")),
brevkode = "1",
),
),
kanal = "EESSI",
avsenderMottaker = null,
bruker = null,
tema = null,
),
)
val erIkkeJournalfort = safJournalpostService.erIkkeJournalfort(journalpostId)
assertFalse(erIkkeJournalfort)
}
}
8 changes: 8 additions & 0 deletions src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ no.nav.security.jwt:
client-id: client-id
client-secret: secretzz
client-auth-method: client_secret_basic
onbehalfof-smtss:
token-endpoint-url: http://localhost:${mock-oauth2-server.port}/azureator/token
grant-type: urn:ietf:params:oauth:grant-type:jwt-bearer
scope: smtss-client
authentication:
client-id: client-id
client-secret: secretzz
client-auth-method: client_secret_basic

AZURE_APP_PRE_AUTHORIZED_APPS: "[{\"name\":\"dev-gcp:teamsykmelding:syk-dig\",\"clientId\":\"syk-dig-client-id\"}]"

Expand Down

0 comments on commit d371f90

Please sign in to comment.