1
+ import io.kotest.assertions.throwables.shouldThrow
1
2
import io.kotest.matchers.collections.shouldBeEmpty
3
+ import io.kotest.matchers.nulls.shouldNotBeNull
4
+ import io.kotest.matchers.shouldBe
2
5
import no.nav.helsearbeidsgiver.DialogEntitet
6
+ import no.nav.helsearbeidsgiver.DialogRepository
7
+ import org.jetbrains.exposed.exceptions.ExposedSQLException
3
8
import org.jetbrains.exposed.sql.Database
4
9
import org.jetbrains.exposed.sql.ResultRow
5
10
import org.jetbrains.exposed.sql.selectAll
@@ -21,13 +26,46 @@ class TestRepo(
21
26
22
27
class DialogRepositoryTest :
23
28
FunSpecWithDb (listOf (DialogEntitet ), { db ->
24
-
25
- // val inntektsmeldingRepo = DialogRepository(db)
26
29
val testRepo = TestRepo (db)
30
+ val dialogRepo = DialogRepository (db)
31
+
32
+ val sykmeldingId = UUID .randomUUID()
33
+ val dialogId = UUID .randomUUID()
27
34
28
- test(" skal lagre inntektsmeldingskjema og inntektsmelding " ) {
35
+ test(" lagreDialog skal lagre dialog " ) {
29
36
transaction {
30
37
DialogEntitet .selectAll().toList()
31
38
}.shouldBeEmpty()
39
+ dialogRepo.lagreDialog(dialogId = dialogId, sykmeldingId = sykmeldingId)
40
+
41
+ val record = testRepo.hentRecordFraDialog(sykmeldingId).shouldNotBeNull()
42
+ record.getOrNull(DialogEntitet .dialogId) shouldBe dialogId
43
+ }
44
+
45
+ test(" finnDialogId skal finne dialogId for sykmeldingId" ) {
46
+ transaction {
47
+ DialogEntitet .selectAll().toList()
48
+ }.shouldBeEmpty()
49
+
50
+ dialogRepo.lagreDialog(dialogId = dialogId, sykmeldingId = sykmeldingId)
51
+ dialogRepo.finnDialogId(sykmeldingId) shouldBe dialogId
52
+ }
53
+
54
+ test(" lagreDialog skal kaste feil dersom den forsøker å lagre dialog med dialogId som allerede finnes" ) {
55
+ transaction {
56
+ DialogEntitet .selectAll().toList()
57
+ }.shouldBeEmpty()
58
+ dialogRepo.lagreDialog(dialogId = dialogId, sykmeldingId = sykmeldingId)
59
+
60
+ shouldThrow<ExposedSQLException > { dialogRepo.lagreDialog(dialogId = dialogId, sykmeldingId = UUID .randomUUID()) }
61
+ }
62
+
63
+ test(" lagreDialog skal kaste feil dersom den forsøker å lagre dialog med sykmeldingId som allerede finnes" ) {
64
+ transaction {
65
+ DialogEntitet .selectAll().toList()
66
+ }.shouldBeEmpty()
67
+ dialogRepo.lagreDialog(dialogId = dialogId, sykmeldingId = sykmeldingId)
68
+
69
+ shouldThrow<ExposedSQLException > { dialogRepo.lagreDialog(dialogId = UUID .randomUUID(), sykmeldingId = sykmeldingId) }
32
70
}
33
71
})
0 commit comments