update AccountService with getById

This commit is contained in:
2025-09-11 14:06:48 +02:00
parent 0f8e6ab852
commit 942750d9d8
2 changed files with 23 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package ltd.lulz.service package ltd.lulz.service
import io.github.oshai.kotlinlogging.KotlinLogging import io.github.oshai.kotlinlogging.KotlinLogging
import java.util.UUID
import ltd.lulz.model.AccountEntity import ltd.lulz.model.AccountEntity
import ltd.lulz.repository.AccountRepository import ltd.lulz.repository.AccountRepository
import org.springframework.stereotype.Service import org.springframework.stereotype.Service
@@ -16,4 +17,7 @@ class AccountService(
fun create(entity: AccountEntity): Mono<AccountEntity> = accountRepository fun create(entity: AccountEntity): Mono<AccountEntity> = accountRepository
.save(entity) .save(entity)
.doOnNext { log.debug { "account created with id: ${it.id}" } } .doOnNext { log.debug { "account created with id: ${it.id}" } }
fun getById(id: UUID): Mono<AccountEntity> = accountRepository.findById(id)
.doOnNext { log.debug { "found account by id: ${it.id}" } }
} }

View File

@@ -50,4 +50,23 @@ class AccountServiceTest {
verify { repository.save(any()) } verify { repository.save(any()) }
} }
@Test
fun `get by id`() {
// given
val capture = slot<UUID>()
every { repository.findById(capture(capture)) }
.answers { Mono.just(AccountEntity(capture.captured, name, amount)) }
// when stepped
StepVerifier.create(service.getById(uuid))
.assertNext { result ->
assertThat(result.id).isEqualTo(uuid)
assertThat(result.name).isEqualTo(name)
assertThat(result.amount).isEqualTo(amount)
}
.verifyComplete()
verify { repository.findById(any(UUID::class)) }
}
} }