mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 14:46:49 +00:00
Check if view already exists before creating, and tests
This commit is contained in:
parent
224dc997b8
commit
fe2a1930c9
@ -638,12 +638,17 @@ class MongoDBLocalStorage extends LocalStorage {
|
||||
}
|
||||
|
||||
def createView(bankAccount: BankAccount, view: ViewCreationJSON): Box[View] = {
|
||||
def generatePermalink(name: String): String = {
|
||||
name.replaceAllLiterally(" ","").toLowerCase
|
||||
val newViewPermalink = {
|
||||
view.name.replaceAllLiterally(" ","").toLowerCase
|
||||
}
|
||||
|
||||
if(view.name=="Owner")
|
||||
Failure("There is already an Owner view on this bank account")
|
||||
val hostedAccount = HostedAccount.find(By(HostedAccount.accountID,bankAccount.id))
|
||||
val existing = ViewImpl.find(
|
||||
By(ViewImpl.permalink_, newViewPermalink),
|
||||
By(ViewImpl.account, hostedAccount))
|
||||
|
||||
if(existing.isDefined)
|
||||
Failure(s"There is already a view with permalink $newViewPermalink on this bank account")
|
||||
else
|
||||
for{
|
||||
account <- HostedAccount.find(By(HostedAccount.accountID,bankAccount.id))
|
||||
@ -651,7 +656,7 @@ class MongoDBLocalStorage extends LocalStorage {
|
||||
val createdView = ViewImpl.create.
|
||||
name_(view.name).
|
||||
description_(view.description).
|
||||
permalink_(generatePermalink(view.name)).
|
||||
permalink_(newViewPermalink).
|
||||
isPublic_(view.is_public).
|
||||
account(account)
|
||||
|
||||
|
||||
@ -971,6 +971,20 @@ class API1_2_1Test extends ServerSetup{
|
||||
And("we should get an error message")
|
||||
reply.body.extract[ErrorMessage].error.nonEmpty should equal (true)
|
||||
}
|
||||
|
||||
scenario("We will not create a view because the view already exists", API1_2, PostView) {
|
||||
Given("We will use an access token")
|
||||
val bankId = randomBank
|
||||
val bankAccount : AccountJSON = randomPrivateAccount(bankId)
|
||||
val view = randomView(true, "")
|
||||
postView(bankId, bankAccount.id, view, user1)
|
||||
When("the request is sent")
|
||||
val reply = postView(bankId, bankAccount.id, view, user1)
|
||||
Then("we should get a 400 code")
|
||||
reply.code should equal (400)
|
||||
And("we should get an error message")
|
||||
reply.body.extract[ErrorMessage].error.nonEmpty should equal (true)
|
||||
}
|
||||
}
|
||||
|
||||
feature("Delete a view on a bank account"){
|
||||
|
||||
@ -967,6 +967,20 @@ class API1_2Test extends ServerSetup{
|
||||
And("we should get an error message")
|
||||
reply.body.extract[ErrorMessage].error.nonEmpty should equal (true)
|
||||
}
|
||||
|
||||
scenario("We will not create a view because the view already exists", API1_2, PostView) {
|
||||
Given("We will use an access token")
|
||||
val bankId = randomBank
|
||||
val bankAccount : AccountJSON = randomPrivateAccount(bankId)
|
||||
val view = randomView(true, "")
|
||||
postView(bankId, bankAccount.id, view, user1)
|
||||
When("the request is sent")
|
||||
val reply = postView(bankId, bankAccount.id, view, user1)
|
||||
Then("we should get a 400 code")
|
||||
reply.code should equal (400)
|
||||
And("we should get an error message")
|
||||
reply.body.extract[ErrorMessage].error.nonEmpty should equal (true)
|
||||
}
|
||||
}
|
||||
|
||||
feature("Delete a view on a bank account"){
|
||||
|
||||
Loading…
Reference in New Issue
Block a user