mirror of
https://github.com/OpenBankProject/OBP-API.git
synced 2026-02-06 17:56:46 +00:00
Add Card Attribute Documentation
This commit is contained in:
parent
9a8ba45c58
commit
8fe040db3c
@ -3706,9 +3706,27 @@ object SwaggerDefinitionsJSON {
|
||||
|
||||
val transactionAttributeDocumentationResponseJsonV400 =
|
||||
customerAttributeDocumentationResponseJsonV400.copy(category = AttributeCategory.Transaction.toString)
|
||||
|
||||
val cardAttributeDocumentationJsonV400 =
|
||||
customerAttributeDocumentationJsonV400.copy(category = AttributeCategory.Card.toString)
|
||||
|
||||
val cardAttributeDocumentationResponseJsonV400 =
|
||||
customerAttributeDocumentationResponseJsonV400.copy(category = AttributeCategory.Card.toString)
|
||||
|
||||
val transactionAttributeDocumentationsResponseJsonV400 = AttributeDocumentationsResponseJsonV400(
|
||||
attributes = List(transactionAttributeDocumentationResponseJsonV400)
|
||||
)
|
||||
val cardAttributeDocumentationsResponseJsonV400 = AttributeDocumentationsResponseJsonV400(
|
||||
attributes = List(cardAttributeDocumentationResponseJsonV400)
|
||||
)
|
||||
val accountAttributeDocumentationsResponseJsonV400 = AttributeDocumentationsResponseJsonV400(
|
||||
attributes = List(accountAttributeDocumentationResponseJsonV400)
|
||||
)
|
||||
val customerAttributeDocumentationsResponseJsonV400 = AttributeDocumentationsResponseJsonV400(
|
||||
attributes = List(customerAttributeDocumentationResponseJsonV400)
|
||||
)
|
||||
val productAttributeDocumentationsResponseJsonV400 = AttributeDocumentationsResponseJsonV400(
|
||||
attributes = List(productAttributeDocumentationResponseJsonV400)
|
||||
)
|
||||
|
||||
//The common error or success format.
|
||||
|
||||
@ -507,7 +507,16 @@ object ApiRole {
|
||||
lazy val canDeleteTransactionAttributeDocumentationAtOneBank = CanDeleteTransactionAttributeDocumentationAtOneBank()
|
||||
|
||||
case class CanGetTransactionAttributeDocumentationAtOneBank(requiresBankId: Boolean = true) extends ApiRole
|
||||
lazy val canGetTransactionAttributeDocumentationAtOneBank = CanGetTransactionAttributeDocumentationAtOneBank()
|
||||
lazy val canGetTransactionAttributeDocumentationAtOneBank = CanGetTransactionAttributeDocumentationAtOneBank()
|
||||
|
||||
case class CanGetCardAttributeDocumentationAtOneBank(requiresBankId: Boolean = true) extends ApiRole
|
||||
lazy val canGetCardAttributeDocumentationAtOneBank = CanGetCardAttributeDocumentationAtOneBank()
|
||||
|
||||
case class CanDeleteCardAttributeDocumentationAtOneBank(requiresBankId: Boolean = true) extends ApiRole
|
||||
lazy val canDeleteCardAttributeDocumentationAtOneBank = CanDeleteCardAttributeDocumentationAtOneBank()
|
||||
|
||||
case class CanCreateCardAttributeDocumentationAtOneBank(requiresBankId: Boolean = true) extends ApiRole
|
||||
lazy val canCreateCardAttributeDocumentationAtOneBank = CanCreateCardAttributeDocumentationAtOneBank()
|
||||
|
||||
private val dynamicApiRoles = new ConcurrentHashMap[String, ApiRole]
|
||||
|
||||
|
||||
@ -2977,6 +2977,70 @@ trait APIMethods400 {
|
||||
|
||||
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
createOrUpdateCardAttributeDocumentation,
|
||||
implementedInApiVersion,
|
||||
nameOf(createOrUpdateCardAttributeDocumentation),
|
||||
"PUT",
|
||||
"/banks/BANK_ID/attribute-documentation/card",
|
||||
"Create or Update Card Attribute Documentation",
|
||||
s""" Create or Update Card Attribute Documentation
|
||||
|
|
||||
|The category field must be ${AttributeCategory.Card}
|
||||
|
|
||||
|The type field must be one of; ${AttributeType.DOUBLE}, ${AttributeType.STRING}, ${AttributeType.INTEGER} and ${AttributeType.DATE_WITH_DAY}
|
||||
|
|
||||
|${authenticationRequiredMessage(true)}
|
||||
|
|
||||
|""",
|
||||
cardAttributeDocumentationJsonV400,
|
||||
cardAttributeDocumentationResponseJsonV400,
|
||||
List(
|
||||
$UserNotLoggedIn,
|
||||
$BankNotFound,
|
||||
InvalidJsonFormat,
|
||||
UnknownError
|
||||
),
|
||||
Catalogs(notCore, notPSD2, notOBWG),
|
||||
List(apiTagTransaction, apiTagNewStyle),
|
||||
Some(List(canCreateCardAttributeDocumentationAtOneBank)))
|
||||
|
||||
lazy val createOrUpdateCardAttributeDocumentation : OBPEndpoint = {
|
||||
case "banks" :: BankId(bankId) :: "attribute-documentation" :: "card" :: Nil JsonPut json -> _=> {
|
||||
cc =>
|
||||
val failMsg = s"$InvalidJsonFormat The Json body should be the $AttributeDocumentationJsonV400 "
|
||||
for {
|
||||
postedData <- NewStyle.function.tryons(failMsg, 400, cc.callContext) {
|
||||
json.extract[AttributeDocumentationJsonV400]
|
||||
}
|
||||
failMsg = s"$InvalidJsonFormat The `Type` filed can only accept the following field: " +
|
||||
s"${AttributeType.DOUBLE}(12.1234), ${AttributeType.STRING}(TAX_NUMBER), ${AttributeType.INTEGER} (123)and ${AttributeType.DATE_WITH_DAY}(2012-04-23)"
|
||||
attributeType <- NewStyle.function.tryons(failMsg, 400, cc.callContext) {
|
||||
AttributeType.withName(postedData.`type`)
|
||||
}
|
||||
failMsg = s"$InvalidJsonFormat The `Category` filed can only accept the following field: " +
|
||||
s"${AttributeCategory.Card}"
|
||||
category <- NewStyle.function.tryons(failMsg, 400, cc.callContext) {
|
||||
AttributeCategory.withName(postedData.category)
|
||||
}
|
||||
(attributeDocumentation, callContext) <- createOrUpdateAttributeDocumentation(
|
||||
bankId,
|
||||
postedData.name,
|
||||
category,
|
||||
attributeType,
|
||||
postedData.description,
|
||||
postedData.alias,
|
||||
postedData.is_active,
|
||||
cc.callContext
|
||||
)
|
||||
} yield {
|
||||
(JSONFactory400.createAttributeDocumentationJson(attributeDocumentation), HttpCode.`201`(callContext))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
deleteTransactionAttributeDocumentation,
|
||||
implementedInApiVersion,
|
||||
@ -3130,6 +3194,45 @@ trait APIMethods400 {
|
||||
(Full(deleted), HttpCode.`200`(callContext))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
deleteCardAttributeDocumentation,
|
||||
implementedInApiVersion,
|
||||
nameOf(deleteCardAttributeDocumentation),
|
||||
"DELETE",
|
||||
"/banks/BANK_ID/attribute-documentation/ATTRIBUTE_DOCUMENTATION_ID/card",
|
||||
"Delete Card Attribute Documentation",
|
||||
s""" Delete Card Attribute Documentation by ATTRIBUTE_DOCUMENTATION_ID
|
||||
|
|
||||
|${authenticationRequiredMessage(true)}
|
||||
|
|
||||
|""",
|
||||
emptyObjectJson,
|
||||
emptyObjectJson,
|
||||
List(
|
||||
$UserNotLoggedIn,
|
||||
$BankNotFound,
|
||||
UnknownError
|
||||
),
|
||||
Catalogs(notCore, notPSD2, notOBWG),
|
||||
List(apiTagProduct, apiTagNewStyle),
|
||||
Some(List(canDeleteCardAttributeDocumentationAtOneBank)))
|
||||
|
||||
lazy val deleteCardAttributeDocumentation : OBPEndpoint = {
|
||||
case "banks" :: BankId(bankId) :: "attribute-documentation" :: attributeDocumentationId :: "card" :: Nil JsonDelete _ => {
|
||||
cc =>
|
||||
for {
|
||||
(deleted, callContext) <- deleteAttributeDocumentation(
|
||||
attributeDocumentationId,
|
||||
AttributeCategory.withName(AttributeCategory.Card.toString),
|
||||
cc.callContext
|
||||
)
|
||||
} yield {
|
||||
(Full(deleted), HttpCode.`200`(callContext))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -3146,7 +3249,7 @@ trait APIMethods400 {
|
||||
|
|
||||
|""",
|
||||
emptyObjectJson,
|
||||
transactionAttributeDocumentationsResponseJsonV400,
|
||||
productAttributeDocumentationsResponseJsonV400,
|
||||
List(
|
||||
$UserNotLoggedIn,
|
||||
$BankNotFound,
|
||||
@ -3184,7 +3287,7 @@ trait APIMethods400 {
|
||||
|
|
||||
|""",
|
||||
emptyObjectJson,
|
||||
transactionAttributeDocumentationsResponseJsonV400,
|
||||
customerAttributeDocumentationsResponseJsonV400,
|
||||
List(
|
||||
$UserNotLoggedIn,
|
||||
$BankNotFound,
|
||||
@ -3222,7 +3325,7 @@ trait APIMethods400 {
|
||||
|
|
||||
|""",
|
||||
emptyObjectJson,
|
||||
transactionAttributeDocumentationsResponseJsonV400,
|
||||
accountAttributeDocumentationsResponseJsonV400,
|
||||
List(
|
||||
$UserNotLoggedIn,
|
||||
$BankNotFound,
|
||||
@ -3285,6 +3388,45 @@ trait APIMethods400 {
|
||||
}
|
||||
|
||||
|
||||
|
||||
resourceDocs += ResourceDoc(
|
||||
getCardAttributeDocumentation,
|
||||
implementedInApiVersion,
|
||||
nameOf(getCardAttributeDocumentation),
|
||||
"GET",
|
||||
"/banks/BANK_ID/attribute-documentation/card",
|
||||
"Get Card Attribute Documentation",
|
||||
s""" Get Card Attribute Documentation
|
||||
|
|
||||
|${authenticationRequiredMessage(true)}
|
||||
|
|
||||
|""",
|
||||
emptyObjectJson,
|
||||
cardAttributeDocumentationsResponseJsonV400,
|
||||
List(
|
||||
$UserNotLoggedIn,
|
||||
$BankNotFound,
|
||||
UnknownError
|
||||
),
|
||||
Catalogs(notCore, notPSD2, notOBWG),
|
||||
List(apiTagTransaction, apiTagNewStyle),
|
||||
Some(List(canGetCardAttributeDocumentationAtOneBank)))
|
||||
|
||||
lazy val getCardAttributeDocumentation : OBPEndpoint = {
|
||||
case "banks" :: BankId(bankId) :: "attribute-documentation" :: "card" :: Nil JsonGet _ => {
|
||||
cc =>
|
||||
for {
|
||||
(attributeDocumentations, callContext) <- getAttributeDocumentation(
|
||||
AttributeCategory.withName(AttributeCategory.Card.toString),
|
||||
cc.callContext
|
||||
)
|
||||
} yield {
|
||||
(JSONFactory400.createAttributeDocumentationsJson(attributeDocumentations), HttpCode.`200`(callContext))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,96 @@
|
||||
package code.api.v4_0_0
|
||||
|
||||
import code.api.ResourceDocs1_4_0.SwaggerDefinitionsJSON
|
||||
import code.api.util.APIUtil.OAuth._
|
||||
import code.api.util.ErrorMessages.{UserHasMissingRoles, UserNotLoggedIn}
|
||||
import code.api.v4_0_0.OBPAPI4_0_0.Implementations4_0_0
|
||||
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 org.scalatest.Tag
|
||||
|
||||
class AttributeDocumentationCardTest extends V400ServerSetup {
|
||||
/**
|
||||
* 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.v4_0_0.toString)
|
||||
object ApiEndpoint1 extends Tag(nameOf(Implementations4_0_0.createOrUpdateCardAttributeDocumentation))
|
||||
object ApiEndpoint2 extends Tag(nameOf(Implementations4_0_0.getCardAttributeDocumentation))
|
||||
object ApiEndpoint3 extends Tag(nameOf(Implementations4_0_0.deleteCardAttributeDocumentation))
|
||||
|
||||
|
||||
lazy val bankId = randomBankId
|
||||
lazy val putJson = SwaggerDefinitionsJSON.cardAttributeDocumentationJsonV400
|
||||
|
||||
feature(s"test $ApiEndpoint1 version $VersionOfApi - Unauthorized access") {
|
||||
scenario("We will call the endpoint without user credentials", ApiEndpoint1, VersionOfApi) {
|
||||
When("We make a request v4.0.0")
|
||||
val request400 = (v4_0_0_Request / "banks" / bankId / "attribute-documentation" / "card").PUT
|
||||
val response400 = makePutRequest(request400, write(putJson))
|
||||
Then("We should get a 400")
|
||||
response400.code should equal(400)
|
||||
response400.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
|
||||
}
|
||||
}
|
||||
feature(s"test $ApiEndpoint2 version $VersionOfApi - Unauthorized access") {
|
||||
scenario("We will call the endpoint without user credentials", ApiEndpoint2, VersionOfApi) {
|
||||
When("We make a request v4.0.0")
|
||||
val request400 = (v4_0_0_Request / "banks" / bankId / "attribute-documentation" / "card").GET
|
||||
val response400 = makeGetRequest(request400)
|
||||
Then("We should get a 400")
|
||||
response400.code should equal(400)
|
||||
response400.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
|
||||
}
|
||||
}
|
||||
feature(s"test $ApiEndpoint3 version $VersionOfApi - Unauthorized access") {
|
||||
scenario("We will call the endpoint without user credentials", ApiEndpoint3, VersionOfApi) {
|
||||
When("We make a request v4.0.0")
|
||||
val request400 = (v4_0_0_Request / "banks" / bankId / "attribute-documentation"
|
||||
/ "ATTRIBUTE_DOCUMENTATION_ID" / "card").DELETE
|
||||
val response400 = makeDeleteRequest(request400)
|
||||
Then("We should get a 400")
|
||||
response400.code should equal(400)
|
||||
response400.body.extract[ErrorMessage].message should equal(UserNotLoggedIn)
|
||||
}
|
||||
}
|
||||
|
||||
feature(s"test $ApiEndpoint1 version $VersionOfApi - authorized access- missing role") {
|
||||
scenario("We will call the endpoint with user credentials", ApiEndpoint1, VersionOfApi) {
|
||||
When("We make a request v4.0.0")
|
||||
val request400 = (v4_0_0_Request / "banks" / bankId / "attribute-documentation" / "card").PUT <@ (user1)
|
||||
val response400 = makePutRequest(request400, write(putJson))
|
||||
Then("We should get a 403")
|
||||
response400.code should equal(403)
|
||||
response400.body.extract[ErrorMessage].message.toString contains (UserHasMissingRoles) should be (true)
|
||||
}
|
||||
}
|
||||
feature(s"test $ApiEndpoint2 version $VersionOfApi - authorized access- missing role") {
|
||||
scenario("We will call the endpoint with user credentials", ApiEndpoint2, VersionOfApi) {
|
||||
When("We make a request v4.0.0")
|
||||
val request400 = (v4_0_0_Request / "banks" / bankId / "attribute-documentation" / "card").GET <@ (user1)
|
||||
val response400 = makeGetRequest(request400)
|
||||
Then("We should get a 403")
|
||||
response400.code should equal(403)
|
||||
response400.body.extract[ErrorMessage].message.toString contains (UserHasMissingRoles) should be (true)
|
||||
}
|
||||
}
|
||||
feature(s"test $ApiEndpoint3 version $VersionOfApi - authorized access- missing role") {
|
||||
scenario("We will call the endpoint with user credentials", ApiEndpoint3, VersionOfApi) {
|
||||
When("We make a request v4.0.0")
|
||||
val request400 = (v4_0_0_Request / "banks" / bankId / "attribute-documentation"
|
||||
/ "ATTRIBUTE_DOCUMENTATION_ID" / "card").DELETE <@ (user1)
|
||||
val response400 = makeDeleteRequest(request400)
|
||||
Then("We should get a 403")
|
||||
response400.code should equal(403)
|
||||
response400.body.extract[ErrorMessage].message.toString contains (UserHasMissingRoles) should be (true)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -130,4 +130,5 @@ object AttributeCategory extends OBPEnumeration[AttributeCategory]{
|
||||
object Product extends Value
|
||||
object Account extends Value
|
||||
object Transaction extends Value
|
||||
object Card extends Value
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user