feat(billing): implement REST API, database config, and tests for billing service

- **REST API:** Added `BillingController` with endpoints for managing participant accounts and transactions, including history retrieval.
- **Database Configuration:** Introduced `BillingDatabaseConfiguration` to initialize database schema using Exposed.
- **Testing:** Added integration tests for `TeilnehmerKontoService` using H2 in-memory database.
This commit is contained in:
2026-04-10 12:26:57 +02:00
parent 21f3a57e6e
commit eef17b3067
8 changed files with 476 additions and 20 deletions
@@ -0,0 +1,64 @@
@file:OptIn(ExperimentalUuidApi::class)
package at.mocode.billing.service
import at.mocode.billing.domain.model.BuchungsTyp
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.ActiveProfiles
import kotlin.uuid.ExperimentalUuidApi
import kotlin.uuid.Uuid
@SpringBootTest
@ActiveProfiles("test")
class TeilnehmerKontoServiceTest {
@Autowired
lateinit var service: TeilnehmerKontoService
@Test
fun `Konto erstellen und buchen`() {
val veranstaltungId = Uuid.random()
val personId = Uuid.random()
val personName = "Max Mustermann"
// 1. Konto erstellen
val konto = service.getOrCreateKonto(veranstaltungId, personId, personName)
assertNotNull(konto)
assertEquals(personName, konto.personName)
assertEquals(0L, konto.saldoCent)
// 2. Buchung durchführen
val updatedKonto = service.buche(
kontoId = konto.kontoId,
betragCent = 1500L,
typ = BuchungsTyp.NENNGEBUEHR,
zweck = "Nennung Bewerb 1"
)
assertEquals(1500L, updatedKonto.saldoCent)
// 3. Buchungshistorie prüfen
val buchungen = service.getBuchungsHistorie(konto.kontoId)
assertEquals(1, buchungen.size)
assertEquals(1500L, buchungen[0].betragCent)
assertEquals("Nennung Bewerb 1", buchungen[0].verwendungszweck)
}
@Test
fun `Mehrere Buchungen summieren sich korrekt`() {
val vId = Uuid.random()
val pId = Uuid.random()
val konto = service.getOrCreateKonto(vId, pId, "Susi Sorglos")
service.buche(konto.kontoId, 2000L, BuchungsTyp.STARTGEBUEHR, "Startgeld")
val finalKonto = service.buche(konto.kontoId, -500L, BuchungsTyp.STORNIERUNG, "Storno")
assertEquals(1500L, finalKonto.saldoCent)
val historian = service.getBuchungsHistorie(konto.kontoId)
assertEquals(2, historian.size)
}
}
@@ -0,0 +1,9 @@
spring:
datasource:
url: jdbc:h2:mem:billing_test;DB_CLOSE_DELAY=-1
driver-class-name: org.h2.Driver
username: sa
password: ""
h2:
console:
enabled: true