From 39f5aea60966eeec3764d3be416fa652913fb358 Mon Sep 17 00:00:00 2001 From: hongwei Date: Fri, 14 Jun 2019 14:49:53 +0200 Subject: [PATCH] added the accountAttributes in create account --- .../SwaggerDefinitionsJSON.scala | 10 ++++++++++ .../scala/code/api/v3_1_0/APIMethods310.scala | 6 +++--- .../code/api/v3_1_0/JSONFactory3.1.0.scala | 6 +++--- .../scala/code/api/v3_1_0/AccountTest.scala | 17 ++++++++--------- .../commons/model/CommonModel.scala | 1 + 5 files changed, 25 insertions(+), 15 deletions(-) diff --git a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala index e907b93b7..2d5f8853d 100644 --- a/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala +++ b/obp-api/src/main/scala/code/api/ResourceDocs1_4_0/SwaggerDefinitionsJSON.scala @@ -3337,6 +3337,16 @@ object SwaggerDefinitionsJSON { customer_id = customerIdExample.value ) + val createAccountJsonV310 = CreateAccountJsonV310( + user_id = userIdExample.value, + label = labelExample.value, + `type` = accountTypeExample.value, + balance = amountOfMoneyJsonV121, + branch_id = branchIdExample.value, + account_routing = accountRoutingJsonV121, + account_attributes= List(accountAttributeResponseJson) + ) + val physicalCardsJsonV310 = PhysicalCardsJsonV310(List(physicalCardJsonV310)) //The common error or success format. diff --git a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala index e3a540312..58d5c0df4 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/APIMethods310.scala @@ -4782,7 +4782,7 @@ trait APIMethods310 { | |Note: The Amount must be zero.""".stripMargin, createAccountJSONV220, - createAccountJSONV220, + createAccountJsonV310, List( InvalidJsonFormat, BankNotFound, @@ -4859,7 +4859,7 @@ trait APIMethods310 { callContext ) (productAttributes, callContext) <- NewStyle.function.getProductAttributesByBankAndCode(bankId, ProductCode(accountType), callContext) - (_, callContext) <- NewStyle.function.createAccountAttributes( + (accountAttributes, callContext) <- NewStyle.function.createAccountAttributes( bankId, accountId, ProductCode(accountType), @@ -4871,7 +4871,7 @@ trait APIMethods310 { //2 Add permission to the user //3 Set the user as the account holder BankAccountCreation.setAsOwner(bankId, accountId, postedOrLoggedInUser) - (JSONFactory220.createAccountJSON(userIdAccountOwner, bankAccount), HttpCode.`200`(callContext)) + (JSONFactory310.createAccountJSON(userIdAccountOwner, bankAccount, accountAttributes), HttpCode.`200`(callContext)) } } } diff --git a/obp-api/src/main/scala/code/api/v3_1_0/JSONFactory3.1.0.scala b/obp-api/src/main/scala/code/api/v3_1_0/JSONFactory3.1.0.scala index 9e40662c2..a65d861bc 100644 --- a/obp-api/src/main/scala/code/api/v3_1_0/JSONFactory3.1.0.scala +++ b/obp-api/src/main/scala/code/api/v3_1_0/JSONFactory3.1.0.scala @@ -579,7 +579,7 @@ case class PhysicalCardWithAttributesJsonV310( case class PhysicalCardsJsonV310( cards : List[PhysicalCardJsonV310]) -case class CreateAccountJSONV310( +case class CreateAccountJsonV310( user_id : String, label : String, `type` : String, @@ -1165,8 +1165,8 @@ object JSONFactory310{ ) } - def createAccountJSON(userId: String, account: BankAccount, accountAttributes: List[AccountAttribute]): CreateAccountJSONV310 = { - CreateAccountJSONV310( + def createAccountJSON(userId: String, account: BankAccount, accountAttributes: List[AccountAttribute]): CreateAccountJsonV310 = { + CreateAccountJsonV310( user_id = userId, label = account.label, `type` = account.accountType, diff --git a/obp-api/src/test/scala/code/api/v3_1_0/AccountTest.scala b/obp-api/src/test/scala/code/api/v3_1_0/AccountTest.scala index a13dd1a04..5116fd4fa 100644 --- a/obp-api/src/test/scala/code/api/v3_1_0/AccountTest.scala +++ b/obp-api/src/test/scala/code/api/v3_1_0/AccountTest.scala @@ -21,7 +21,7 @@ class AccountTest extends V310ServerSetup with DefaultUsers { object ApiEndpoint1 extends Tag(nameOf(Implementations3_1_0.updateAccount)) object ApiEndpoint2 extends Tag(nameOf(Implementations3_1_0.createAccount)) - lazy val testBankId = randomBankId + lazy val testBankId = testBankId1 lazy val putCreateAccountJSONV310 = SwaggerDefinitionsJSON.createAccountJSONV220.copy(user_id = resourceUser1.userId) lazy val putCreateAccountOtherUserJsonV310 = SwaggerDefinitionsJSON.createAccountJSONV220.copy(user_id = resourceUser2.userId) @@ -29,12 +29,11 @@ class AccountTest extends V310ServerSetup with DefaultUsers { feature("test Update Account") { scenario("We will test Update Account Api", ApiEndpoint1, VersionOfApi) { Given("The test bank and test account") - val testBank = testBankId1 val testAccount = testAccountId1 val testPutJson = updateAccountRequestJsonV310 Then(s"We call the update api without proper role: ${ApiRole.canUpdateAccount}") - val requestPut = (v3_1_0_Request / "management" / "banks" / testBank.value / "accounts" / testAccount.value).PUT <@ (user1) + val requestPut = (v3_1_0_Request / "management" / "banks" / testBankId.value / "accounts" / testAccount.value).PUT <@ (user1) val responsePut = makePutRequest(requestPut, write(testPutJson)) And("We should get 403 and the error message missing can CanUpdateAccount role") responsePut.code should equal(403) @@ -53,7 +52,7 @@ class AccountTest extends V310ServerSetup with DefaultUsers { responsePut2.body.extract[UpdateAccountResponseJsonV310].account_routing.address should be (testPutJson.account_routing.address) - val requestGet = (v3_1_0_Request /"my"/ "banks" / testBank.value / "accounts" / testAccount.value/"account").PUT <@ (user1) + val requestGet = (v3_1_0_Request /"my"/ "banks" / testBankId.value / "accounts" / testAccount.value/"account").PUT <@ (user1) val responseGet = makeGetRequest(requestGet) And("We should get 200 and updated account data") responseGet.code should equal(200) @@ -69,7 +68,7 @@ class AccountTest extends V310ServerSetup with DefaultUsers { feature("Create Account v3.1.0 - Unauthorized access") { scenario("We will call the endpoint without user credentials", ApiEndpoint2, VersionOfApi) { When("We make a request v3.1.0") - val request310 = (v3_1_0_Request / "banks" / testBankId / "accounts" / "ACCOUNT_ID" ).PUT + val request310 = (v3_1_0_Request / "banks" / testBankId.value / "accounts" / "ACCOUNT_ID" ).PUT val response310 = makePutRequest(request310, write(putCreateAccountJSONV310)) Then("We should get a 400") response310.code should equal(400) @@ -80,7 +79,7 @@ class AccountTest extends V310ServerSetup with DefaultUsers { feature("Create Account v3.1.0 - Authorized access") { scenario("We will call the endpoint with user credentials", ApiEndpoint2, VersionOfApi) { When("We make a request v3.1.0") - val request310 = (v3_1_0_Request / "banks" / testBankId / "accounts" / "TEST_ACCOUNT_ID" ).PUT <@(user1) + val request310 = (v3_1_0_Request / "banks" / testBankId.value / "accounts" / "TEST_ACCOUNT_ID" ).PUT <@(user1) val response310 = makePutRequest(request310, write(putCreateAccountJSONV310)) Then("We should get a 200") response310.code should equal(200) @@ -95,7 +94,7 @@ class AccountTest extends V310ServerSetup with DefaultUsers { account.account_routing should be (putCreateAccountJSONV310.account_routing) Then("We make a request v3.1.0 but with other user") - val request310WithNewAccountId = (v3_1_0_Request / "banks" / testBankId / "accounts" / "TEST_ACCOUNT_ID2" ).PUT <@(user1) + val request310WithNewAccountId = (v3_1_0_Request / "banks" / testBankId.value / "accounts" / "TEST_ACCOUNT_ID2" ).PUT <@(user1) val responseWithNoRole = makePutRequest(request310WithNewAccountId, write(putCreateAccountOtherUserJsonV310)) Then("We should get a 403 and some error message") responseWithNoRole.code should equal(403) @@ -103,10 +102,10 @@ class AccountTest extends V310ServerSetup with DefaultUsers { Then("We grant the roles and test it again") - Entitlement.entitlement.vend.addEntitlement(testBankId1.value, resourceUser1.userId, ApiRole.canCreateAccount.toString) + Entitlement.entitlement.vend.addEntitlement(testBankId.value, resourceUser1.userId, ApiRole.canCreateAccount.toString) val responseWithOtherUesrV310 = makePutRequest(request310WithNewAccountId, write(putCreateAccountOtherUserJsonV310)) - val account2 = responseWithOtherUesrV310.body.extract[CreateAccountJSONV220] + val account2 = responseWithOtherUesrV310.body.extract[CreateAccountJsonV310] account2.`type` should be (putCreateAccountOtherUserJsonV310.`type`) account2.`label` should be (putCreateAccountOtherUserJsonV310.`label`) account2.balance.amount.toDouble should be (putCreateAccountOtherUserJsonV310.balance.amount.toDouble) diff --git a/obp-commons/src/main/scala/com/openbankproject/commons/model/CommonModel.scala b/obp-commons/src/main/scala/com/openbankproject/commons/model/CommonModel.scala index afbe157fb..dcc51a3ec 100644 --- a/obp-commons/src/main/scala/com/openbankproject/commons/model/CommonModel.scala +++ b/obp-commons/src/main/scala/com/openbankproject/commons/model/CommonModel.scala @@ -67,6 +67,7 @@ case class ProductAttributeCommons( name :String, attributeType : ProductAttributeType.Value, value :String) extends ProductAttribute +object ProductAttributeCommons extends Converter[ProductAttribute, ProductAttributeCommons] case class ProductCollectionCommons(