Skip to content

Commit

Permalink
Tatt med avsluttOppgave i ApiTest for å teste hele livsløpet til en o…
Browse files Browse the repository at this point in the history
…ppgave + nødvendige fikser.
  • Loading branch information
frodeli committed Sep 17, 2024
1 parent 2ef349b commit fb92c88
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package no.nav.aap.oppgave

import no.nav.aap.oppgave.opprett.Avklaringsbehovtype
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode
import java.util.UUID

data class AvsluttOppgaveDto(
val saksnummer: String? = null,
val behandlingRef: UUID? = null,
val referanse: UUID? = null,
val journalpostId: Long? = null,
val avklaringsbehovKode: AvklaringsbehovKode,
val avklaringsbehovtype: Avklaringsbehovtype,
)
4 changes: 2 additions & 2 deletions app/src/main/kotlin/no/nav/aap/oppgave/OppgaveAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ fun NormalOpenAPIRoute.avsluttOppgave(dataSource: DataSource, prometheus: Promet
val oppgaver = dataSource.transaction { connection ->
val oppgaverSomSkalAvsluttes = OppgaveRepository(connection).hentOppgaverForReferanse(
dto.saksnummer,
dto.behandlingRef,
dto.referanse,
dto.journalpostId,
dto.avklaringsbehovKode,
dto.avklaringsbehovtype,
ident()
)
oppgaverSomSkalAvsluttes.forEach {
Expand Down
26 changes: 17 additions & 9 deletions app/src/main/kotlin/no/nav/aap/oppgave/OppgaveRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package no.nav.aap.oppgave

import no.nav.aap.komponenter.dbconnect.DBConnection
import no.nav.aap.oppgave.filter.FilterDto
import no.nav.aap.oppgave.opprett.Avklaringsbehovtype
import no.nav.aap.oppgave.plukk.NesteOppgaveDto
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode
import no.nav.aap.oppgave.verdityper.OppgaveId
Expand Down Expand Up @@ -130,27 +131,34 @@ class OppgaveRepository(private val connection: DBConnection) {
}
}

fun hentOppgaverForReferanse(saksnummer: String?, behandlingRef: UUID?, journalpostId: Long?, avklaringsbehovKode: AvklaringsbehovKode, ident: String): List<OppgaveId> {
fun hentOppgaverForReferanse(saksnummer: String?, referanse: UUID?, journalpostId: Long?, avklaringsbehovtype: Avklaringsbehovtype, ident: String): List<OppgaveId> {
val saksnummerClause = if (saksnummer != null) "SAKSNUMMER = ?" else "SAKSNUMMER IS NULL"
val referanseClause = if (referanse != null) "BEHANDLING_REF = ?" else "BEHANDLING_REF IS NULL"
val journalpostIdClause = if (journalpostId != null) "JOURNALPOST_ID = ?" else "JOURNALPOST_ID IS NULL"
val oppgaverForReferanseQuery = """
SELECT
ID
FROM
OPPGAVE
WHERE
SAKSNUMMER = ? AND
BEHANDLING_REF = ? AND
JOURNALPOST_ID = ? AND
$saksnummerClause AND
$referanseClause AND
$journalpostIdClause AND
AVKLARINGSBEHOV_TYPE = ? AND
RESERVERT_AV = ?
""".trimIndent()

return connection.queryList<OppgaveId>(oppgaverForReferanseQuery) {
setParams {
setString(1, saksnummer)
setUUID(2, behandlingRef)
setLong(3, journalpostId)
setString(4, avklaringsbehovKode.kode)
setString(5, ident)
var index = 1
if (saksnummer != null) setString(index++, saksnummer)
if (referanse != null) setUUID(index++, referanse)
if (journalpostId != null ) setLong(index++, journalpostId)
setString(index++, avklaringsbehovtype.kode)
setString(index++, ident)
}
setRowMapper { row ->
OppgaveId(row.getLong("ID"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/kotlin/no/nav/aap/oppgave/plukk/PlukkAPI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ fun NormalOpenAPIRoute.plukkApi(dataSource: DataSource, prometheus: PrometheusMe
if (nesteOppgave != null) {
respond(nesteOppgave)
} else {
respondWithStatus(HttpStatusCode.NotFound)
respondWithStatus(HttpStatusCode.NoContent)
}
}
42 changes: 24 additions & 18 deletions app/src/test/kotlin/no/nav/aap/oppgave/ApiTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import no.nav.aap.oppgave.opprett.Behandlingstype
import no.nav.aap.oppgave.opprett.Definisjon
import no.nav.aap.oppgave.plukk.FinnNesteOppgaveDto
import no.nav.aap.oppgave.plukk.NesteOppgaveDto
import no.nav.aap.oppgave.verdityper.AvklaringsbehovKode
import no.nav.aap.oppgave.verdityper.OppgaveId
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.AfterAll
Expand All @@ -39,21 +38,28 @@ import java.util.UUID
class ApiTest {

@Test
fun `Opprett og plukk oppgave`() {
fun `Opprett, plukk og avslutt oppgave`() {
val saksnummer = "123456"
val referanse = UUID.randomUUID().toString()
val referanse = UUID.randomUUID()
val avklaringsbehovtype: Avklaringsbehovtype = Avklaringsbehovtype.AVKLAR_SYKDOM

// Opprett ny oppgave
val oppgaveId = opprettOppgave(saksnummer, referanse)
assertThat(oppgaveId).isNotNull()

val nesteOppgaveDto = hentNesteOppgave()
assertThat(nesteOppgaveDto).isNotNull()
assertThat(nesteOppgaveDto!!.oppgaveId).isEqualTo(oppgaveId!!)
// Plukk neste oppgave
var nesteOppgave = hentNesteOppgave()
assertThat(nesteOppgave).isNotNull()
assertThat(nesteOppgave!!.oppgaveId).isEqualTo(oppgaveId!!)

//TODO: fiks senere
// val oppgaveIder = avsluttOppgave(saksnummer, behandlingRef, avklaringsbehovKode)
// assertThat(oppgaveIder).hasSize(1)
// assertThat(oppgaveIder.first()).isEqualTo(oppgaveId)
// Avslutt plukket oppgave
val oppgaveIder = avsluttOppgave(saksnummer, referanse, avklaringsbehovtype)
assertThat(oppgaveIder).hasSize(1)
assertThat(oppgaveIder.first()).isEqualTo(oppgaveId)

// Sjekk at det ikkk er flere oppgaver i køen
nesteOppgave = hentNesteOppgave()
assertThat(nesteOppgave).isNull()
}


Expand All @@ -67,18 +73,18 @@ class ApiTest {
assertThat(filterListe).hasSize(2)
}

private fun opprettBehandlingshistorikk(saksnummer: String, referanse: String): BehandlingshistorikkRequest {
private fun opprettBehandlingshistorikk(saksnummer: String, referanse: UUID, avklaringsbehovtype: Avklaringsbehovtype): BehandlingshistorikkRequest {
return BehandlingshistorikkRequest(
personident = "01010012345",
saksnummer = saksnummer,
referanse = referanse,
referanse = referanse.toString(),
behandlingType = Behandlingstype.Førstegangsbehandling,
status = Behandlingstatus.OPPRETTET,
opprettetTidspunkt = LocalDateTime.now(),
avklaringsbehov = listOf(
AvklaringsbehovDto(
definisjon = Definisjon(
type = Avklaringsbehovtype.AVKLAR_SYKDOM.kode
type = avklaringsbehovtype.kode
),
status = Avklaringsbehovstatus.OPPRETTET,
endringer = listOf(
Expand All @@ -93,8 +99,8 @@ class ApiTest {
)
}

private fun opprettOppgave(saksnummer: String, referanse: String): OppgaveId? {
val request = opprettBehandlingshistorikk(saksnummer, referanse)
private fun opprettOppgave(saksnummer: String, referanse: UUID): OppgaveId? {
val request = opprettBehandlingshistorikk(saksnummer, referanse, Avklaringsbehovtype.AVKLAR_SYKDOM)
val oppgaveId:OppgaveId? = client.post(
URI.create("http://localhost:8080/opprett-oppgave"),
PostRequest(body = request)
Expand All @@ -110,14 +116,14 @@ class ApiTest {
return nesteOppgave
}

private fun avsluttOppgave(saksnummer: String, behandlingRef: UUID, avklaringsbehovKode: String): List<OppgaveId> {
private fun avsluttOppgave(saksnummer: String, referanse: UUID, avklaringsbehovtype: Avklaringsbehovtype): List<OppgaveId> {
val oppgaveIder: List<OppgaveId>? = client.post(
URI.create("http://localhost:8080/avslutt-oppgave"),
PostRequest(body = AvsluttOppgaveDto(
saksnummer = saksnummer,
behandlingRef = behandlingRef,
referanse = referanse,
journalpostId = null,
avklaringsbehovKode = AvklaringsbehovKode(avklaringsbehovKode))
avklaringsbehovtype = avklaringsbehovtype)
)
)
return oppgaveIder!!
Expand Down

0 comments on commit fb92c88

Please sign in to comment.