update TransactionController with transfer

This commit is contained in:
2025-09-13 11:42:16 +02:00
parent fe3283f5f1
commit c8897f7fc0
3 changed files with 116 additions and 0 deletions

View File

@@ -9,6 +9,7 @@ import ltd.lulz.exception.AccountNotFoundException
import ltd.lulz.exception.InsufficientFundsException
import ltd.lulz.model.AccountEntity
import ltd.lulz.model.Transaction
import ltd.lulz.model.Transfer
import ltd.lulz.service.TransactionService
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
@@ -23,6 +24,7 @@ class TransactionControllerTest {
companion object {
val amount: BigDecimal = BigDecimal.valueOf(0.01)
val uuid: UUID = UUID.fromString("00000000-0000-0000-0000-000000000000")
val receiver = UUID.fromString("00000000-0000-0000-0000-000000000001")
}
private val transactionService: TransactionService = mockk()
@@ -194,4 +196,92 @@ class TransactionControllerTest {
// then
result.expectStatus().is5xxServerError
}
@Test
fun `transfer success`() {
// given
val request = Transfer.Request(uuid, receiver, amount)
every { transactionService.transfer(any(), any(), any()) } returns Mono.empty()
// when
val result = webTestClient.post()
.uri("/transfer")
.contentType(APPLICATION_JSON)
.bodyValue(request)
.exchange()
// then
result.expectStatus().isCreated
}
@Test
fun `transfer fail amount to small`() {
// given
val request = Transfer.Request(uuid, receiver, BigDecimal.valueOf(0.009))
// when
val result = webTestClient.post()
.uri("/transfer")
.contentType(APPLICATION_JSON)
.bodyValue(request)
.exchange()
// then
result.expectStatus().isBadRequest
}
@Test
fun `transfer insufficient Funds`() {
// given
val request = Transfer.Request(uuid, receiver, amount)
every { transactionService.transfer(any(), any(), any()) } returns Mono.error(InsufficientFundsException())
// when
val result = webTestClient.post()
.uri("/transfer")
.contentType(APPLICATION_JSON)
.bodyValue(request)
.exchange()
// then
result.expectStatus().isEqualTo(NOT_ACCEPTABLE)
}
@Test
fun `transfer account not found`() {
// given
val request = Transfer.Request(uuid, receiver, amount)
every { transactionService.transfer(any(), any(), any()) } returns Mono.error(AccountNotFoundException())
// when
val result = webTestClient.post()
.uri("/transfer")
.contentType(APPLICATION_JSON)
.bodyValue(request)
.exchange()
// then
result.expectStatus().isNotFound
}
@Test
fun `transfer default error`() {
// given
val request = Transfer.Request(uuid, receiver, amount)
every { transactionService.transfer(any(), any(), any()) } returns Mono.error(RuntimeException())
// when
val result = webTestClient.post()
.uri("/transfer")
.contentType(APPLICATION_JSON)
.bodyValue(request)
.exchange()
// then
result.expectStatus().is5xxServerError
}
}