Skip to content

Commit

Permalink
OpenBankProject#927 fixed the failed tests, no public accounts for al…
Browse files Browse the repository at this point in the history
…l getAccounts endpoints.
  • Loading branch information
hongwei1 committed Feb 18, 2018
1 parent 64aa4dd commit 7121f50
Show file tree
Hide file tree
Showing 3 changed files with 154 additions and 154 deletions.
104 changes: 52 additions & 52 deletions src/test/scala/code/api/v1_2_1/API1_2_1Test.scala
Expand Up @@ -1085,30 +1085,30 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser
}

feature("Information about all the bank accounts for all banks"){
scenario("we get only the public bank accounts", API1_2, GetBankAccountsForAllBanks) {
accountTestsSpecificDBSetup()
Given("We will not use an access token")
When("the request is sent")
val reply = getBankAccountsForAllBanks(None)
Then("we should get a 200 ok code")
reply.code should equal (200)
val publicAccountsInfo = reply.body.extract[AccountsJSON]
And("some fields should not be empty")
publicAccountsInfo.accounts.foreach(a => {
a.id.nonEmpty should equal (true)
a.views_available.nonEmpty should equal (true)
a.views_available.foreach(
//check that all the views are public
v => v.is_public should equal (true)
)
})

And("There are accounts from more than one bank")
assertAccountsFromMoreThanOneBank(publicAccountsInfo)

And("There are no duplicate accounts")
assertNoDuplicateAccounts(publicAccountsInfo)
}
// scenario("we get only the public bank accounts", API1_2, GetBankAccountsForAllBanks) {
// accountTestsSpecificDBSetup()
// Given("We will not use an access token")
// When("the request is sent")
// val reply = getBankAccountsForAllBanks(None)
// Then("we should get a 200 ok code")
// reply.code should equal (200)
// val publicAccountsInfo = reply.body.extract[AccountsJSON]
// And("some fields should not be empty")
// publicAccountsInfo.accounts.foreach(a => {
// a.id.nonEmpty should equal (true)
// a.views_available.nonEmpty should equal (true)
// a.views_available.foreach(
// //check that all the views are public
// v => v.is_public should equal (true)
// )
// })
//
// And("There are accounts from more than one bank")
// assertAccountsFromMoreThanOneBank(publicAccountsInfo)
//
// And("There are no duplicate accounts")
// assertNoDuplicateAccounts(publicAccountsInfo)
// }
scenario("we get the bank accounts the user has access to", API1_2, GetBankAccountsForAllBanks) {
accountTestsSpecificDBSetup()
Given("We will use an access token")
Expand All @@ -1124,8 +1124,8 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser
})

//test that this call is a combination of accounts with more than public access, and accounts with public access
And("Some accounts should have only public views")
assertAtLeastOneAccountHasAllViewsWithCondition(accountsInfo, _.is_public)
// And("Some accounts should have only public views")
// assertAtLeastOneAccountHasAllViewsWithCondition(accountsInfo, _.is_public)
And("Some accounts should have only private views")
assertAtLeastOneAccountHasAllViewsWithCondition(accountsInfo, !_.is_public)

Expand Down Expand Up @@ -1201,30 +1201,30 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser
}

feature("Information about all the bank accounts for a single bank"){
scenario("we get only the public bank accounts", API1_2, GetBankAccounts) {
accountTestsSpecificDBSetup()
Given("We will not use an access token")
When("the request is sent")
val reply = getBankAccounts(randomBank, None)
Then("we should get a 200 ok code")
reply.code should equal (200)
val publicAccountsInfo = reply.body.extract[AccountsJSON]
And("some fields should not be empty")
publicAccountsInfo.accounts.foreach(a => {
a.id.nonEmpty should equal (true)
a.views_available.nonEmpty should equal (true)
a.views_available.foreach(
//check that all the views are public
v => v.is_public should equal (true)
)
})

And("The accounts are only from one bank")
assertAccountsFromOneBank(publicAccountsInfo)

And("There are no duplicate accounts")
assertNoDuplicateAccounts(publicAccountsInfo)
}
// scenario("we get only the public bank accounts", API1_2, GetBankAccounts) {
// accountTestsSpecificDBSetup()
// Given("We will not use an access token")
// When("the request is sent")
// val reply = getBankAccounts(randomBank, None)
// Then("we should get a 200 ok code")
// reply.code should equal (200)
// val publicAccountsInfo = reply.body.extract[AccountsJSON]
// And("some fields should not be empty")
// publicAccountsInfo.accounts.foreach(a => {
// a.id.nonEmpty should equal (true)
// a.views_available.nonEmpty should equal (true)
// a.views_available.foreach(
// //check that all the views are public
// v => v.is_public should equal (true)
// )
// })
//
// And("The accounts are only from one bank")
// assertAccountsFromOneBank(publicAccountsInfo)
//
// And("There are no duplicate accounts")
// assertNoDuplicateAccounts(publicAccountsInfo)
// }
scenario("we get the bank accounts the user have access to", API1_2, GetBankAccounts) {
accountTestsSpecificDBSetup()
Given("We will use an access token")
Expand All @@ -1242,8 +1242,8 @@ class API1_2_1Test extends User1AllPrivileges with DefaultUsers with PrivateUser
//test that this call is a combination of accounts with more than public access, and accounts with public access
And("Some accounts should have only public views")

assertAtLeastOneAccountHasAllViewsWithCondition(accountsInfo, _.is_public)
And("Some accounts should have only private views")
// assertAtLeastOneAccountHasAllViewsWithCondition(accountsInfo, _.is_public)
// And("Some accounts should have only private views")
assertAtLeastOneAccountHasAllViewsWithCondition(accountsInfo, !_.is_public)

And("The accounts are only from one bank")
Expand Down
64 changes: 32 additions & 32 deletions src/test/scala/code/api/v2_0_0/AccountTest.scala
Expand Up @@ -26,22 +26,22 @@ class AccountTest extends V200ServerSetup with DefaultUsers {
And("We should get a 200")
responsePut.code should equal(200)

When("We make the anonymous access request")
val requestGet = (v2_0Request / "accounts").GET
val responseGet = makeGetRequest(requestGet)

Then("We should get a 200")
responseGet.code should equal(200)

val isPublic: List[Boolean] =
for {
JObject(o) <- responseGet.body
JField("is_public", JBool(isPublic)) <- o
} yield {
isPublic
}
And("All received accounts have to be public")
isPublic.forall(_ == true) should equal(true)
// When("We make the anonymous access request")
// val requestGet = (v2_0Request / "accounts").GET
// val responseGet = makeGetRequest(requestGet)
//
// Then("We should get a 200")
// responseGet.code should equal(200)
//
// val isPublic: List[Boolean] =
// for {
// JObject(o) <- responseGet.body
// JField("is_public", JBool(isPublic)) <- o
// } yield {
// isPublic
// }
// And("All received accounts have to be public")
// isPublic.forall(_ == true) should equal(true)

When("We make the authenticated access request")
val requestGetAll = (v2_0Request / "accounts").GET <@ (user1)
Expand Down Expand Up @@ -74,22 +74,22 @@ class AccountTest extends V200ServerSetup with DefaultUsers {
And("We should get a 200")
responsePut.code should equal(200)

When("We make the anonymous access request")
val requestGet = (v2_0Request / "banks" / testBank.value / "accounts").GET
val responseGet = makeGetRequest(requestGet)

Then("We should get a 200")
responseGet.code should equal(200)

val isPublic: List[Boolean] =
for {
JObject(o) <- responseGet.body
JField("is_public", JBool(isPublic)) <- o
} yield {
isPublic
}
And("All received accounts have to be public")
isPublic.forall(_ == true) should equal(true)
// When("We make the anonymous access request")
// val requestGet = (v2_0Request / "banks" / testBank.value / "accounts").GET
// val responseGet = makeGetRequest(requestGet)
//
// Then("We should get a 200")
// responseGet.code should equal(200)
//
// val isPublic: List[Boolean] =
// for {
// JObject(o) <- responseGet.body
// JField("is_public", JBool(isPublic)) <- o
// } yield {
// isPublic
// }
// And("All received accounts have to be public")
// isPublic.forall(_ == true) should equal(true)

When("We make the authenticated access request")
val requestGetAll = (v2_0Request / "banks" / testBank.value / "accounts").GET <@ (user1)
Expand Down
140 changes: 70 additions & 70 deletions src/test/scala/code/management/AccountsAPITest.scala
@@ -1,70 +1,70 @@
package code.management

import code.api.util.APIUtil.OAuth.{Consumer, Token, _}
import code.api.v1_2_1._
import code.setup.{APIResponse, DefaultUsers, PrivateUser2AccountsAndSetUpWithTestData, User1AllPrivileges}
import org.scalatest.Tag

class AccountsAPITest extends API1_2_1Test with User1AllPrivileges with DefaultUsers with PrivateUser2AccountsAndSetUpWithTestData {

//define Tags
object Management extends Tag("Management")
object DeleteBankAccount extends Tag("deleteBankAccount")

def managementRequest = baseRequest / "internal" / "v1.0"

def deleteBankAccount(bankId : String, accountId : String, consumerAndToken: Option[(Consumer, Token)]) : APIResponse = {
val request = (managementRequest / "banks" / bankId / "accounts" / accountId).DELETE <@ (consumerAndToken)
makeDeleteRequest(request)
}

val OK: Int = 200
val OK_NO_CONTENT: Int = 204
val CREATED: Int = 201
val BAD_REQUEST: Int = 400
val SERVER_ERROR: Int = 500

//Tests start here
/*
// internal/v1.0 has been removed.
feature("Delete an account resource") {
scenario("User deletes one of his private accounts", Management, DeleteBankAccount) {
accountTestsSpecificDBSetup()
//get an account
val reply = getPrivateAccountsForAllBanks(consumerAndToken = user1)
reply.code should equal(OK)
//get one of those
val account = reply.body.extract[AccountsJSON].accounts.head
//delete the account
val response = deleteBankAccount(bankId = account.bank_id, accountId = account.id, consumerAndToken = user1)
response.code should equal(OK_NO_CONTENT)
//check that it's gone
Connector.connector.vend.getBankAccount(BankId(account.bank_id), AccountId(account.id)) should equal(Empty)
}
scenario("User tries to delete a private account of another user", Management, DeleteBankAccount) {
accountTestsSpecificDBSetup()
//get an account
val reply = getPrivateAccountsForAllBanks(consumerAndToken = user2)
reply.code should equal(OK)
//get one of those
val account = reply.body.extract[AccountsJSON].accounts.head
When("Deleting the account with another user that does not have owner permissions")
val response = deleteBankAccount(bankId = account.bank_id, accountId = account.id, consumerAndToken = user1)
response.code should equal(SERVER_ERROR)
Then("The account should still be there")
Connector.connector.vend.getBankAccount(BankId(account.bank_id), AccountId(account.id)) should not equal(Empty)
}
}
*/
}
//package code.management
//
//import code.api.util.APIUtil.OAuth.{Consumer, Token, _}
//import code.api.v1_2_1._
//import code.setup.{APIResponse, DefaultUsers, PrivateUser2AccountsAndSetUpWithTestData, User1AllPrivileges}
//import org.scalatest.Tag
//
//class AccountsAPITest extends API1_2_1Test with User1AllPrivileges with DefaultUsers with PrivateUser2AccountsAndSetUpWithTestData {
//
// //define Tags
// object Management extends Tag("Management")
// object DeleteBankAccount extends Tag("deleteBankAccount")
//
// def managementRequest = baseRequest / "internal" / "v1.0"
//
// def deleteBankAccount(bankId : String, accountId : String, consumerAndToken: Option[(Consumer, Token)]) : APIResponse = {
// val request = (managementRequest / "banks" / bankId / "accounts" / accountId).DELETE <@ (consumerAndToken)
// makeDeleteRequest(request)
// }
//
// val OK: Int = 200
// val OK_NO_CONTENT: Int = 204
// val CREATED: Int = 201
// val BAD_REQUEST: Int = 400
// val SERVER_ERROR: Int = 500
//
// //Tests start here
///*
//
//// internal/v1.0 has been removed.
//
// feature("Delete an account resource") {
// scenario("User deletes one of his private accounts", Management, DeleteBankAccount) {
// accountTestsSpecificDBSetup()
//
// //get an account
// val reply = getPrivateAccountsForAllBanks(consumerAndToken = user1)
// reply.code should equal(OK)
//
// //get one of those
// val account = reply.body.extract[AccountsJSON].accounts.head
//
// //delete the account
// val response = deleteBankAccount(bankId = account.bank_id, accountId = account.id, consumerAndToken = user1)
// response.code should equal(OK_NO_CONTENT)
//
// //check that it's gone
// Connector.connector.vend.getBankAccount(BankId(account.bank_id), AccountId(account.id)) should equal(Empty)
// }
//
// scenario("User tries to delete a private account of another user", Management, DeleteBankAccount) {
// accountTestsSpecificDBSetup()
//
// //get an account
// val reply = getPrivateAccountsForAllBanks(consumerAndToken = user2)
// reply.code should equal(OK)
//
// //get one of those
// val account = reply.body.extract[AccountsJSON].accounts.head
//
// When("Deleting the account with another user that does not have owner permissions")
// val response = deleteBankAccount(bankId = account.bank_id, accountId = account.id, consumerAndToken = user1)
// response.code should equal(SERVER_ERROR)
//
// Then("The account should still be there")
// Connector.connector.vend.getBankAccount(BankId(account.bank_id), AccountId(account.id)) should not equal(Empty)
// }
// }
// */
//}

0 comments on commit 7121f50

Please sign in to comment.