Lagt til dato i feilmeldingdatabase og test for dette

Co-authored-by: Markus A. R. Johansen <markus.aleksander.rakil.johansen@nav.no>
This commit is contained in:
Amalie Mansåker 2023-07-11 15:37:01 +02:00
parent 30a0ba6acc
commit f6cd7df4ff
4 changed files with 20 additions and 13 deletions

View file

@ -2,14 +2,16 @@ package no.nav.helse.sprik.db
import org.jetbrains.exposed.sql.insert import org.jetbrains.exposed.sql.insert
import org.jetbrains.exposed.sql.transactions.transaction import org.jetbrains.exposed.sql.transactions.transaction
import java.time.LocalDateTime
class FeilmeldingRepository { class FeilmeldingRepository {
fun lagre(tittel: String, beskrivelse: String){ fun lagre(tittel: String, beskrivelse: String, dato: LocalDateTime){
transaction { transaction {
FeilmeldingTable.run { FeilmeldingTable.run {
insert { insert {
it[FeilmeldingTable.tittel] = tittel it[FeilmeldingTable.tittel] = tittel
it[FeilmeldingTable.beskrivelse] = beskrivelse it[FeilmeldingTable.beskrivelse] = beskrivelse
it[FeilmeldingTable.dato] = dato
} }
} }
} }

View file

@ -1,8 +1,10 @@
package no.nav.helse.sprik.db package no.nav.helse.sprik.db
import org.jetbrains.exposed.sql.Table import org.jetbrains.exposed.sql.Table
import org.jetbrains.exposed.sql.javatime.datetime
object FeilmeldingTable : Table("feilmelding") { object FeilmeldingTable : Table("feilmelding") {
val tittel = text("tittel") val tittel = text("tittel")
val beskrivelse = text("beskrivelse") val beskrivelse = text("beskrivelse")
val dato = datetime("dato")
} }

View file

@ -0,0 +1 @@
ALTER TABLE feilmelding ADD dato TIMESTAMP

View file

@ -12,6 +12,7 @@ import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeAll
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.TestInstance import org.junit.jupiter.api.TestInstance
import java.time.LocalDateTime
import kotlin.test.assertEquals import kotlin.test.assertEquals
import org.jetbrains.exposed.sql.Database as ExposedDatabase import org.jetbrains.exposed.sql.Database as ExposedDatabase
@ -31,24 +32,25 @@ class FeilmeldingTest {
FeilmeldingTable.deleteAll() FeilmeldingTable.deleteAll()
} }
} }
@Test
fun `Lagrer feilmelding i databasen`() {
feilmeldingRepository.lagre("test", "testesen")
transaction {
val actual = FeilmeldingTable.selectAll().single()
assertEquals("test", actual[FeilmeldingTable.tittel])
assertEquals("testesen", actual[FeilmeldingTable.beskrivelse])
}
}
@Test @Test
fun `Sett opp testdatabasen riktig`(){ fun `Sett opp testdatabasen riktig`(){
feilmeldingRepository.lagre("Hællæ", "skjera bagera") feilmeldingRepository.lagre("Hællæ", "skjera bagera", LocalDateTime.of(2000,1,1,8,0))
transaction { transaction {
assertEquals(1, FeilmeldingTable.selectAll().map { assertEquals(1, FeilmeldingTable.selectAll().map {
it it
}.size) }.size)
} }
} }
@Test
fun `Lagrer feilmelding i databasen`() {
feilmeldingRepository.lagre("test", "testesen", LocalDateTime.of(2000,1,1,8,0))
transaction {
val actual = FeilmeldingTable.selectAll().single()
assertEquals("test", actual[FeilmeldingTable.tittel])
assertEquals("testesen", actual[FeilmeldingTable.beskrivelse])
assertEquals(LocalDateTime.of(2023, 1, 1, 8, 0), actual[FeilmeldingTable.dato])
}
}
} }