-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4664 from navikt/refactor/forenkle-frikoble-konta…
…ktperson Refactor/forenkle frikoble kontaktperson
- Loading branch information
Showing
6 changed files
with
96 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,6 @@ import io.kotest.matchers.shouldBe | |
import io.kotest.matchers.shouldNotBe | ||
import kotlinx.serialization.json.Json | ||
import kotliquery.Query | ||
import kotliquery.queryOf | ||
import no.nav.mulighetsrommet.api.arrangor.db.ArrangorRepository | ||
import no.nav.mulighetsrommet.api.arrangor.model.ArrangorKontaktperson | ||
import no.nav.mulighetsrommet.api.clients.norg2.Norg2Type | ||
|
@@ -38,7 +37,6 @@ import no.nav.mulighetsrommet.domain.Tiltakskode | |
import no.nav.mulighetsrommet.domain.constants.ArenaMigrering | ||
import no.nav.mulighetsrommet.domain.dbo.TiltaksgjennomforingOppstartstype | ||
import no.nav.mulighetsrommet.domain.dto.* | ||
import org.intellij.lang.annotations.Language | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
import java.util.* | ||
|
@@ -757,64 +755,60 @@ class TiltaksgjennomforingRepositoryTest : FunSpec({ | |
} | ||
|
||
context("Frikoble kontaktperson fra arrangør") { | ||
// Add some data to tiltaksgjennomforing_arrangor_kontaktperson-table | ||
val kontaktperson1 = ArrangorKontaktperson( | ||
id = UUID.randomUUID(), | ||
arrangorId = ArrangorFixtures.underenhet1.id, | ||
navn = "Aran Goran", | ||
telefon = "", | ||
epost = "[email protected]", | ||
beskrivelse = "", | ||
) | ||
|
||
val kontaktperson2 = ArrangorKontaktperson( | ||
id = UUID.randomUUID(), | ||
arrangorId = ArrangorFixtures.underenhet1.id, | ||
navn = "Gibli Bobli", | ||
telefon = "", | ||
epost = "[email protected]", | ||
beskrivelse = "", | ||
) | ||
|
||
val testDomain = MulighetsrommetTestDomain( | ||
arrangorKontaktpersoner = listOf(kontaktperson1, kontaktperson2), | ||
tiltakstyper = listOf(TiltakstypeFixtures.Oppfolging), | ||
avtaler = listOf(AvtaleFixtures.oppfolging), | ||
gjennomforinger = listOf( | ||
Oppfolging1.copy(arrangorKontaktpersoner = listOf(kontaktperson1.id)), | ||
Oppfolging2.copy(arrangorKontaktpersoner = listOf(kontaktperson2.id)), | ||
), | ||
) | ||
|
||
val tiltaksgjennomforinger = TiltaksgjennomforingRepository(database.db) | ||
test("Skal fjerne kontaktperson fra koblingstabell") { | ||
tiltaksgjennomforinger.upsert(Oppfolging1) | ||
tiltaksgjennomforinger.upsert(Oppfolging2) | ||
|
||
val arrangorKontaktperson = ArrangorKontaktperson( | ||
id = UUID.randomUUID(), | ||
arrangorId = ArrangorFixtures.underenhet1.id, | ||
navn = "Aran Goran", | ||
telefon = "", | ||
epost = "[email protected]", | ||
beskrivelse = "", | ||
) | ||
test("Skal fjerne kontaktperson fra koblingstabell") { | ||
testDomain.initialize(database.db) | ||
|
||
val arrangorKontaktperson2 = ArrangorKontaktperson( | ||
id = UUID.randomUUID(), | ||
arrangorId = ArrangorFixtures.underenhet1.id, | ||
navn = "Gibli Bobli", | ||
telefon = "", | ||
epost = "[email protected]", | ||
beskrivelse = "", | ||
) | ||
tiltaksgjennomforinger.get(testDomain.gjennomforinger[0].id).shouldNotBeNull().should { | ||
it.arrangor.kontaktpersoner.first().id.shouldBe(kontaktperson1.id) | ||
} | ||
tiltaksgjennomforinger.get(testDomain.gjennomforinger[1].id).shouldNotBeNull().should { | ||
it.arrangor.kontaktpersoner.first().id.shouldBe(kontaktperson2.id) | ||
} | ||
|
||
@Language("PostgreSQL") | ||
val upsertKontaktpersonerQuery = """ | ||
insert into arrangor_kontaktperson(id, navn, telefon, epost, beskrivelse, arrangor_id) values | ||
('${arrangorKontaktperson.id}', '${arrangorKontaktperson.navn}', '${arrangorKontaktperson.telefon}', '${arrangorKontaktperson.epost}', '${arrangorKontaktperson.beskrivelse}', '${arrangorKontaktperson.arrangorId}'), | ||
('${arrangorKontaktperson2.id}', '${arrangorKontaktperson2.navn}', '${arrangorKontaktperson2.telefon}', '${arrangorKontaktperson2.epost}', '${arrangorKontaktperson2.beskrivelse}', '${arrangorKontaktperson2.arrangorId}') | ||
""".trimIndent() | ||
queryOf(upsertKontaktpersonerQuery).asExecute.let { database.db.run(it) } | ||
|
||
@Language("PostgreSQL") | ||
val upsertQuery = """ | ||
insert into tiltaksgjennomforing_arrangor_kontaktperson(arrangor_kontaktperson_id, tiltaksgjennomforing_id) values | ||
('${arrangorKontaktperson.id}', '${Oppfolging1.id}'), | ||
('${arrangorKontaktperson2.id}', '${Oppfolging2.id}') | ||
""".trimIndent() | ||
queryOf(upsertQuery).asExecute.let { database.db.run(it) } | ||
|
||
@Language("PostgreSQL") | ||
val selectQuery = """ | ||
select arrangor_kontaktperson_id from tiltaksgjennomforing_arrangor_kontaktperson | ||
""".trimIndent() | ||
|
||
val results = | ||
queryOf(selectQuery).map { it.uuid("arrangor_kontaktperson_id") }.asList.let { database.db.run(it) } | ||
results.size shouldBe 2 | ||
database.db.transaction { tx -> | ||
tiltaksgjennomforinger.frikobleKontaktpersonFraGjennomforing( | ||
arrangorKontaktperson.id, | ||
kontaktperson1.id, | ||
Oppfolging1.id, | ||
tx, | ||
) | ||
} | ||
val resultsAfterFrikobling = | ||
queryOf(selectQuery).map { it.uuid("arrangor_kontaktperson_id") }.asList.let { database.db.run(it) } | ||
resultsAfterFrikobling.size shouldBe 1 | ||
|
||
tiltaksgjennomforinger.get(testDomain.gjennomforinger[0].id).shouldNotBeNull().should { | ||
it.arrangor.kontaktpersoner.shouldBeEmpty() | ||
} | ||
tiltaksgjennomforinger.get(testDomain.gjennomforinger[1].id).shouldNotBeNull().should { | ||
it.arrangor.kontaktpersoner.first().id.shouldBe(kontaktperson2.id) | ||
} | ||
} | ||
} | ||
}) |