generated from aura-ascend/template-service
infinity money bug :D
This is here to show a small miss with big problems. - add missing test to - TransactionEndpoints - TransactionControllerTest - update Transfer with validation for sender receiver - add SenderReceiverValidator - add SenderReceiver
This commit is contained in:
15
src/main/kotlin/ltd/lulz/annotation/SenderReceiver.kt
Normal file
15
src/main/kotlin/ltd/lulz/annotation/SenderReceiver.kt
Normal file
@@ -0,0 +1,15 @@
|
||||
package ltd.lulz.annotation
|
||||
|
||||
import jakarta.validation.Constraint
|
||||
import jakarta.validation.Payload
|
||||
import kotlin.reflect.KClass
|
||||
import ltd.lulz.annotation.validator.SenderReceiverValidator
|
||||
|
||||
@Constraint(validatedBy = [SenderReceiverValidator::class])
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
annotation class SenderReceiver(
|
||||
val message: String = "Receiver and Sender cant be the same account",
|
||||
val groups: Array<KClass<*>> = [],
|
||||
val payload: Array<KClass<out Payload>> = [],
|
||||
)
|
||||
@@ -0,0 +1,14 @@
|
||||
package ltd.lulz.annotation.validator
|
||||
|
||||
import jakarta.validation.ConstraintValidator
|
||||
import jakarta.validation.ConstraintValidatorContext
|
||||
import ltd.lulz.annotation.SenderReceiver
|
||||
import ltd.lulz.model.Transfer.Request
|
||||
|
||||
class SenderReceiverValidator : ConstraintValidator<SenderReceiver, Request> {
|
||||
|
||||
override fun isValid(
|
||||
request: Request,
|
||||
context: ConstraintValidatorContext,
|
||||
): Boolean = request.receiver != request.account
|
||||
}
|
||||
@@ -3,9 +3,11 @@ package ltd.lulz.model
|
||||
import jakarta.validation.constraints.DecimalMin
|
||||
import java.math.BigDecimal
|
||||
import java.util.UUID
|
||||
import ltd.lulz.annotation.SenderReceiver
|
||||
|
||||
object Transfer {
|
||||
|
||||
@SenderReceiver
|
||||
data class Request(
|
||||
val account: UUID,
|
||||
val receiver: UUID,
|
||||
|
||||
@@ -195,6 +195,25 @@ class TransactionEndpoints {
|
||||
result.expectStatus().isEqualTo(CREATED)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `deposit - fail same account`() {
|
||||
// given
|
||||
val request = Transfer.Request(
|
||||
account = UUID.fromString("00000000-0000-7000-0000-000000000001"),
|
||||
receiver = UUID.fromString("00000000-0000-7000-0000-000000000001"),
|
||||
amount = BigDecimal.valueOf(1.00),
|
||||
)
|
||||
|
||||
// when
|
||||
val result = webClient.post()
|
||||
.uri("/transfer")
|
||||
.bodyValue(request)
|
||||
.exchange()
|
||||
|
||||
// then
|
||||
result.expectStatus().isEqualTo(BAD_REQUEST)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `deposit - fail amount to small`() {
|
||||
// given
|
||||
|
||||
@@ -215,6 +215,24 @@ class TransactionControllerTest {
|
||||
result.expectStatus().isCreated
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `transfer fail same accounts`() {
|
||||
// given
|
||||
val request = Transfer.Request(uuid, uuid, 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().isBadRequest
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `transfer fail amount to small`() {
|
||||
// given
|
||||
|
||||
Reference in New Issue
Block a user