File tree Expand file tree Collapse file tree
main/kotlin/lmirabal/bank/http
test/kotlin/lmirabal/bank/http Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ fun bankHttp() = bankHttp(BankService(InMemoryBankAccountRepository()))
2323
2424internal const val BANK_ACCOUNTS_BASE_URL = " /bank/accounts"
2525internal const val BANK_ACCOUNT_DEPOSIT_PATH = " /{id}/deposit"
26+ internal const val BANK_ACCOUNT_WITHDRAWAL_PATH = " /{id}/withdraw"
2627internal val bankAccountLens = Body .auto<BankAccount >().toLens()
2728internal val bankAccountListLens = Body .auto<List <BankAccount >>().toLens()
2829internal val accountIdLens = Path .map({ BankAccountId (UUID .fromString(it)) }, { it.value.toString() }).of(" id" )
@@ -40,6 +41,12 @@ internal fun bankHttp(bank: Bank): HttpHandler {
4041 val amount = amountLens(request)
4142
4243 Response (OK ).with (bankAccountLens of bank.deposit(accountId, amount))
44+ },
45+ BANK_ACCOUNT_WITHDRAWAL_PATH bind POST to { request ->
46+ val accountId = accountIdLens(request)
47+ val amount = amountLens(request)
48+
49+ Response (OK ).with (bankAccountLens of bank.withdraw(accountId, amount))
4350 }
4451 ),
4552 )
Original file line number Diff line number Diff line change @@ -22,14 +22,18 @@ class BankHttpClient(val http: HttpHandler) : Bank {
2222 }
2323
2424 override fun deposit (id : BankAccountId , amount : Amount ): BankAccount {
25+ return changeBalanceAction(BANK_ACCOUNT_DEPOSIT_PATH , id, amount)
26+ }
27+
28+ override fun withdraw (id : BankAccountId , amount : Amount ): BankAccount {
29+ return changeBalanceAction(BANK_ACCOUNT_WITHDRAWAL_PATH , id, amount)
30+ }
31+
32+ private fun changeBalanceAction (actionPath : String , id : BankAccountId , amount : Amount ): BankAccount {
2533 val response = http(
26- Request (POST , BANK_ACCOUNTS_BASE_URL + BANK_ACCOUNT_DEPOSIT_PATH )
34+ Request (POST , BANK_ACCOUNTS_BASE_URL + actionPath )
2735 .with (accountIdLens of id, amountLens of amount)
2836 )
2937 return bankAccountLens(response)
3038 }
31-
32- override fun withdraw (id : BankAccountId , amount : Amount ): BankAccount {
33- TODO (" Not yet implemented" )
34- }
3539}
Original file line number Diff line number Diff line change @@ -9,7 +9,9 @@ import org.http4k.server.SunHttp
99import org.http4k.server.asServer
1010import org.junit.jupiter.api.AfterEach
1111import org.junit.jupiter.api.BeforeEach
12+ import org.junit.jupiter.api.Tag
1213
14+ @Tag(" ImplementationReady" )
1315class BankHttpIntegrationTest : BankTest () {
1416 private val server = bankHttp().asServer(SunHttp ())
1517 override val bank = BankHttpClient (
Original file line number Diff line number Diff line change 11package lmirabal.bank.http
22
33import lmirabal.bank.BankTest
4+ import org.junit.jupiter.api.Tag
45
6+ @Tag(" ImplementationReady" )
57class BankHttpTest : BankTest () {
68 override val bank = BankHttpClient (bankHttp())
79}
You can’t perform that action at this time.
0 commit comments