Skip to content

Commit

Permalink
Merge pull request #2386 from constantine2nd/develop
Browse files Browse the repository at this point in the history
Balances
  • Loading branch information
simonredfern authored May 17, 2024
2 parents eb31062 + 3f15adb commit cd79538
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 4 deletions.
6 changes: 3 additions & 3 deletions obp-api/src/main/scala/code/api/v4_0_0/APIMethods400.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3373,9 +3373,9 @@ trait APIMethods400 extends MdcLoggable {
}

staticResourceDocs += ResourceDoc(
getBankAccountBalances,
getBankAccountBalancesForCurrentUser,
implementedInApiVersion,
nameOf(getBankAccountBalances),
nameOf(getBankAccountBalancesForCurrentUser),
"GET",
"/banks/BANK_ID/accounts/ACCOUNT_ID/balances",
"Get Account Balances",
Expand All @@ -3386,7 +3386,7 @@ trait APIMethods400 extends MdcLoggable {
apiTagAccount :: apiTagPSD2AIS :: apiTagPsd2 :: Nil
)

lazy val getBankAccountBalances : OBPEndpoint = {
lazy val getBankAccountBalancesForCurrentUser : OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "balances" :: Nil JsonGet _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
Expand Down
37 changes: 37 additions & 0 deletions obp-api/src/main/scala/code/api/v5_1_0/APIMethods510.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import code.api.v3_0_0.JSONFactory300
import code.api.v3_0_0.JSONFactory300.createAggregateMetricJson
import code.api.v3_1_0.ConsentJsonV310
import code.api.v3_1_0.JSONFactory310.createBadLoginStatusJson
import code.api.v4_0_0.JSONFactory400.createAccountBalancesJson
import code.api.v4_0_0.{JSONFactory400, PostAccountAccessJsonV400, PostApiCollectionJson400, RevokedJsonV400}
import code.api.v5_1_0.JSONFactory510.{createRegulatedEntitiesJson, createRegulatedEntityJson}
import code.atmattribute.AtmAttribute
Expand Down Expand Up @@ -2153,7 +2154,43 @@ trait APIMethods510 {
}
}

staticResourceDocs += ResourceDoc(
getBankAccountBalances,
implementedInApiVersion,
nameOf(getBankAccountBalances),
"GET",
"/banks/BANK_ID/accounts/ACCOUNT_ID/views/VIEW_ID/balances",
"Get Account Balances by BANK_ID and ACCOUNT_ID through the VIEW_ID",
"""Get the Balances for the Account specified by BANK_ID and ACCOUNT_ID through the VIEW_ID.""",
EmptyBody,
accountBalanceV400,
List(
$UserNotLoggedIn,
$BankNotFound,
$BankAccountNotFound,
UserNoPermissionAccessView,
UnknownError
),
apiTagAccount :: apiTagPSD2AIS :: apiTagPsd2 :: Nil
)

lazy val getBankAccountBalances : OBPEndpoint = {
case "banks" :: BankId(bankId) :: "accounts" :: AccountId(accountId) :: "views" :: ViewId(viewId) :: "balances" :: Nil JsonGet _ => {
cc => implicit val ec = EndpointContext(Some(cc))
for {
(Full(u), callContext) <- SS.user
bankIdAccountId = BankIdAccountId(bankId, accountId)
view <- NewStyle.function.checkViewAccessAndReturnView(viewId, bankIdAccountId, Full(u), callContext)
failMsg = ViewDoesNotPermitAccess + " You need the permission canSeeBankAccountBalance."
_ <- Helper.booleanToFuture(failMsg, 403, cc = callContext) {
view.canSeeBankAccountBalance
}
(accountBalances, callContext) <- NewStyle.function.getBankAccountBalances(bankIdAccountId, callContext)
} yield{
(createAccountBalancesJson(accountBalances), HttpCode.`200`(callContext))
}
}
}



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AccountBalanceTest extends V400ServerSetup {
*/
object VersionOfApi extends Tag(ApiVersion.v4_0_0.toString)
object ApiEndpoint1 extends Tag(nameOf(Implementations4_0_0.getBankAccountsBalances))
object ApiEndpoint2 extends Tag(nameOf(Implementations4_0_0.getBankAccountBalances))
object ApiEndpoint2 extends Tag(nameOf(Implementations4_0_0.getBankAccountBalancesForCurrentUser))

lazy val bankId = randomBankId
lazy val bankAccount = randomPrivateAccountViaEndpoint(bankId)
Expand Down
49 changes: 49 additions & 0 deletions obp-api/src/test/scala/code/api/v5_1_0/AccountBalanceTest.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package code.api.v5_1_0

import code.api.util.APIUtil.OAuth._
import code.api.util.ErrorMessages.UserNotLoggedIn
import code.api.v5_1_0.OBPAPI5_1_0.Implementations5_1_0
import com.github.dwickern.macros.NameOf.nameOf
import com.openbankproject.commons.model.ErrorMessage
import com.openbankproject.commons.util.ApiVersion
import org.scalatest.Tag

class AccountBalanceTest extends V510ServerSetup {
/**
* Test tags
* Example: To run tests with tag "getPermissions":
* mvn test -D tagsToInclude
*
* This is made possible by the scalatest maven plugin
*/
object VersionOfApi extends Tag(ApiVersion.v5_1_0.toString)
object ApiEndpoint1 extends Tag(nameOf(Implementations5_1_0.getBankAccountBalances))

lazy val bankId = randomBankId
lazy val bankAccount = randomPrivateAccountViaEndpoint(bankId)
def requestGetAccountBalances(viewId: String = "None") = (v5_1_0_Request / "banks" / bankAccount.bank_id / "accounts" / bankAccount.id / "views" / viewId / "balances").GET

feature(s"test $ApiEndpoint1 version $VersionOfApi - Unauthorized access") {
scenario("We will call the endpoint without user credentials", ApiEndpoint1, VersionOfApi) {
When(s"We make a request $ApiEndpoint1")
val responseGetAccountBalances = makeGetRequest(requestGetAccountBalances())
Then("We should get a 401")
responseGetAccountBalances.code should equal(401)
responseGetAccountBalances.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
}
}
feature(s"test $ApiEndpoint1 version $VersionOfApi - Authorized access, no proper view") {
scenario("We will call the endpoint with user credentials", VersionOfApi, ApiEndpoint1) {
val responseGetAccountBalances = makeGetRequest(requestGetAccountBalances() <@ user1)
Then("We should get a 403")
responseGetAccountBalances.code should equal(403)
}
}
feature(s"test $ApiEndpoint1 version $VersionOfApi - Authorized access with proper view") {
scenario("We will call the endpoint with user credentials", VersionOfApi, ApiEndpoint1) {
val responseGetAccountBalances = makeGetRequest(requestGetAccountBalances("owner") <@ user1)
Then("We should get a 200")
responseGetAccountBalances.code should equal(200)
}
}
}

0 comments on commit cd79538

Please sign in to comment.