version 6.0.0 banks bank_id, bank_code, full_name

This commit is contained in:
simonredfern 2026-01-29 14:31:24 +01:00
parent 78229c8fa6
commit 4ffb8dcdf4
3 changed files with 72 additions and 5 deletions

View File

@ -938,7 +938,7 @@ trait APIMethods600 {
EmptyBody,
BanksJsonV600(List(BankJsonV600(
bank_id = "gh.29.uk",
short_name = "short_name",
bank_code = "bank_code",
full_name = "full_name",
logo = "logo",
website = "www.openbankproject.com",
@ -978,7 +978,7 @@ trait APIMethods600 {
EmptyBody,
BankJsonV600(
bank_id = "gh.29.uk",
short_name = "short_name",
bank_code = "bank_code",
full_name = "full_name",
logo = "logo",
website = "www.openbankproject.com",
@ -1728,8 +1728,9 @@ trait APIMethods600 {
json.extract[PostBankJson600]
}
// TODO: Improve this error message to not hardcode "16" - should reference the max length from checkOptionalShortString function
checkShortStringValue = APIUtil.checkOptionalShortString(postJson.bank_id)
_ <- Helper.booleanToFuture(failMsg = s"$checkShortStringValue.", cc = cc.callContext) {
_ <- Helper.booleanToFuture(failMsg = s"$InvalidJsonFormat BANK_ID: $checkShortStringValue BANK_ID must contain only characters A-Z, a-z, 0-9, -, _, . and be max 16 characters.", cc = cc.callContext) {
checkShortStringValue == SILENCE_IS_GOLDEN
}

View File

@ -336,7 +336,7 @@ case class StoredProcedureConnectorHealthJsonV600(
case class BankJsonV600(
bank_id: String,
short_name: String,
bank_code: String,
full_name: String,
logo: String,
website: String,
@ -1419,7 +1419,7 @@ object JSONFactory600 extends CustomJsonFormats with MdcLoggable {
}
BankJsonV600(
bank_id = stringOrNull(bank.bankId.value),
short_name = stringOrNull(bank.shortName),
bank_code = stringOrNull(bank.shortName),
full_name = stringOrNull(bank.fullName),
logo = stringOrNull(bank.logoUrl),
website = stringOrNull(bank.websiteUrl),

View File

@ -6,11 +6,13 @@ import code.api.util.ApiRole.CanCreateBank
import code.api.util.ErrorMessages
import code.api.util.ErrorMessages.UserHasMissingRoles
import code.api.v6_0_0.APIMethods600.Implementations6_0_0
import code.entitlement.Entitlement
import code.setup.DefaultUsers
import com.github.dwickern.macros.NameOf.nameOf
import com.openbankproject.commons.model.ErrorMessage
import com.openbankproject.commons.util.ApiVersion
import net.liftweb.json.Serialization.write
import net.liftweb.util.Helpers.randomString
import org.scalatest.Tag
class BankTests extends V600ServerSetup with DefaultUsers {
@ -54,6 +56,70 @@ class BankTests extends V600ServerSetup with DefaultUsers {
response.code should equal(403)
response.body.extract[ErrorMessage].message should equal(UserHasMissingRoles + CanCreateBank)
}
scenario("Successfully create a bank with a 16-character bank_id (max length)", ApiEndpoint1, VersionOfApi) {
// Add the required entitlement
val addedEntitlement = Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, CanCreateBank.toString)
// Generate a 16-character bank_id (maximum allowed by checkOptionalShortString validation)
val longBankId = "bank." + randomString(11).toLowerCase // 5 + 11 = 16 characters
When("We create a bank with a 16-character bank_id")
val postJson = PostBankJson600(
bank_id = longBankId,
bank_code = "test_code",
full_name = Some("Test Bank with Long ID"),
logo = Some("https://example.com/logo.png"),
website = Some("https://example.com"),
bank_routings = None
)
val request = (v6_0_0_Request / "banks").POST <@ (user1)
val response = try {
makePostRequest(request, write(postJson))
} finally {
// Clean up entitlement
Entitlement.entitlement.vend.deleteEntitlement(addedEntitlement)
}
Then("We should get a 201")
response.code should equal(201)
And("The response should contain the bank with the 16-character bank_id")
val responseJson = response.body
(responseJson \ "bank_id").extract[String] should equal(longBankId)
(responseJson \ "bank_id").extract[String].length should equal(16)
}
scenario("Fail to create a bank with bank_id exceeding 16 characters", ApiEndpoint1, VersionOfApi) {
// Add the required entitlement
val addedEntitlement = Entitlement.entitlement.vend.addEntitlement("", resourceUser1.userId, CanCreateBank.toString)
// Generate a 17-character bank_id (exceeds maximum of 16)
val tooLongBankId = "bank." + randomString(12).toLowerCase // 5 + 12 = 17 characters
When("We try to create a bank with a 17-character bank_id")
val postJson = PostBankJson600(
bank_id = tooLongBankId,
bank_code = "test_code",
full_name = Some("Test Bank with Too Long ID"),
logo = Some("https://example.com/logo.png"),
website = Some("https://example.com"),
bank_routings = None
)
val request = (v6_0_0_Request / "banks").POST <@ (user1)
val response = try {
makePostRequest(request, write(postJson))
} finally {
// Clean up entitlement
Entitlement.entitlement.vend.deleteEntitlement(addedEntitlement)
}
Then("We should get a 400")
response.code should equal(400)
And("The error message should indicate BANK_ID validation failed")
response.body.extract[ErrorMessage].message should include("BANK_ID")
}
}
}