refactor/fixed the PhysicalCardsTest

This commit is contained in:
hongwei 2024-10-22 16:18:37 +02:00
parent 1600ba2fe0
commit eeba479be9
5 changed files with 70 additions and 70 deletions

View File

@ -6,10 +6,8 @@ import code.api.util.ApiTag._
import code.api.util.ErrorMessages._
import code.api.util.FutureUtil.EndpointContext
import code.api.util.NewStyle.HttpCode
import code.api.util.{ErrorMessages, NewStyle}
import code.api.util.{ApiRole, NewStyle}
import code.api.v1_2_1.JSONFactory
import code.bankconnectors.Connector
import code.model.BankX
import com.openbankproject.commons.model.BankId
import com.openbankproject.commons.util.ApiVersion
import com.openbankproject.commons.ExecutionContext.Implicits.global
@ -99,24 +97,24 @@ trait APIMethods130 {
EmptyBody,
physicalCardsJSON,
List(UserNotLoggedIn,BankNotFound, UnknownError),
List(apiTagCard, apiTagOldStyle))
List(apiTagCard))
lazy val getCardsForBank : OBPEndpoint = {
case "banks" :: BankId(bankId) :: "cards" :: Nil JsonGet _ => {
cc => {
implicit val ec = EndpointContext(Some(cc))
for {
u <- cc.user ?~! ErrorMessages.UserNotLoggedIn
(bank, callContext) <- BankX(bankId, Some(cc)) ?~! {ErrorMessages.BankNotFound}
cards <- Connector.connector.vend.getPhysicalCardsForBankLegacy(bank, u , Nil)//This `queryParams` will be used from V310
(Full(u), callContext) <- authenticatedAccess(cc)
httpParams <- NewStyle.function.extractHttpParamsFromUrl(cc.url)
(obpQueryParams, callContext) <- createQueriesByHttpParamsFuture(httpParams, callContext)
_ <- NewStyle.function.hasEntitlement(bankId.value, u.userId, ApiRole.canGetCardsForBank, callContext)
(bank, callContext) <- NewStyle.function.getBank(bankId, callContext)
(cards, callContext) <- NewStyle.function.getPhysicalCardsForBank(bank, u, obpQueryParams, callContext)
} yield {
val cardsJson = JSONFactory1_3_0.createPhysicalCardsJSON(cards, u)
successJsonResponse(Extraction.decompose(cardsJson))
(JSONFactory1_3_0.createPhysicalCardsJSON(cards, u), HttpCode.`200`(callContext))
}
}
}
}
}
}

View File

@ -637,7 +637,6 @@ trait Connector extends MdcLoggable {
def deletePhysicalCardForBank(bankId: BankId, cardId: String, callContext:Option[CallContext]) : OBPReturnType[Box[Boolean]] = Future{(Failure(setUnimplementedError(nameOf(deletePhysicalCardForBank _))), callContext)}
def getPhysicalCardsForBankLegacy(bank: Bank, user : User, queryParams: List[OBPQueryParam]) : Box[List[PhysicalCard]] = Failure(setUnimplementedError(nameOf(getPhysicalCardsForBankLegacy _)))
def getPhysicalCardsForBank(bank: Bank, user : User, queryParams: List[OBPQueryParam], callContext:Option[CallContext]) : OBPReturnType[Box[List[PhysicalCard]]] = Future{(Failure(setUnimplementedError(nameOf(getPhysicalCardsForBank _))), callContext)}
def createPhysicalCardLegacy(

View File

@ -1408,7 +1408,7 @@ object LocalMappedConnector extends Connector with MdcLoggable {
override def getPhysicalCardsForBank(bank: Bank, user: User, queryParams: List[OBPQueryParam], callContext: Option[CallContext]): OBPReturnType[Box[List[PhysicalCard]]] = Future {
(
getPhysicalCardsForBankLegacy(bank: Bank, user: User, queryParams),
LocalMappedConnectorInternal.getPhysicalCardsForBankLocal(bank: Bank, user: User, queryParams),
callContext
)
}
@ -1420,37 +1420,6 @@ object LocalMappedConnector extends Connector with MdcLoggable {
)
}
override def getPhysicalCardsForBankLegacy(bank: Bank, user: User, queryParams: List[OBPQueryParam]): Box[List[PhysicalCard]] = {
val list = code.cards.PhysicalCard.physicalCardProvider.vend.getPhysicalCardsForBank(bank, user, queryParams)
val cardList = for (l <- list) yield
new PhysicalCard(
cardId = l.cardId,
bankId = l.bankId,
bankCardNumber = l.bankCardNumber,
cardType = l.cardType,
nameOnCard = l.nameOnCard,
issueNumber = l.issueNumber,
serialNumber = l.serialNumber,
validFrom = l.validFrom,
expires = l.expires,
enabled = l.enabled,
cancelled = l.cancelled,
onHotList = l.onHotList,
technology = l.technology,
networks = l.networks,
allows = l.allows,
account = l.account,
replacement = l.replacement,
pinResets = l.pinResets,
collected = l.collected,
posted = l.posted,
customerId = l.customerId,
cvv = l.cvv,
brand = l.brand
)
Full(cardList)
}
override def getPhysicalCardForBank(bankId: BankId, cardId: String, callContext: Option[CallContext]): OBPReturnType[Box[PhysicalCardTrait]] = Future {
(code.cards.PhysicalCard.physicalCardProvider.vend.getPhysicalCardForBank(bankId: BankId, cardId: String, callContext),
callContext)

View File

@ -530,4 +530,35 @@ object LocalMappedConnectorInternal extends MdcLoggable {
Full(transactionRequestTypeCharge)
}
def getPhysicalCardsForBankLocal(bank: Bank, user: User, queryParams: List[OBPQueryParam]): Box[List[PhysicalCard]] = {
val list = code.cards.PhysicalCard.physicalCardProvider.vend.getPhysicalCardsForBank(bank, user, queryParams)
val cardList = for (l <- list) yield
new PhysicalCard(
cardId = l.cardId,
bankId = l.bankId,
bankCardNumber = l.bankCardNumber,
cardType = l.cardType,
nameOnCard = l.nameOnCard,
issueNumber = l.issueNumber,
serialNumber = l.serialNumber,
validFrom = l.validFrom,
expires = l.expires,
enabled = l.enabled,
cancelled = l.cancelled,
onHotList = l.onHotList,
technology = l.technology,
networks = l.networks,
allows = l.allows,
account = l.account,
replacement = l.replacement,
pinResets = l.pinResets,
collected = l.collected,
posted = l.posted,
customerId = l.customerId,
cvv = l.cvv,
brand = l.brand
)
Full(cardList)
}
}

View File

@ -22,6 +22,19 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers with DefaultConne
lazy val accountCurrency = "EUR"
lazy val account = createAccount(bank.bankId, AccountId(accId), accountCurrency)
override def beforeAll() {
super.beforeAll()
//use the mock connector
Connector.connector.default.set(MockedCardConnector)
}
override def afterAll() {
super.afterAll()
//reset the default connector
Connector.connector.default.set(Connector.buildOne)
wipeTestData()
}
def createCard(number : String) = PhysicalCard(
cardId ="",
bankId= bank.bankId.value,
@ -61,11 +74,13 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers with DefaultConne
implicit override val nameOfConnector = "MockedCardConnector"
override def getBankLegacy(bankId : BankId, callContext: Option[CallContext]) = Full(bank, callContext)
override def getBankLegacy(bankId: BankId, callContext: Option[CallContext]) = Full(bank, callContext)
//these methods are required in this test, there is no need to extends connector.
override def getPhysicalCardsForUser(user : User, callContext: Option[CallContext]) = {
val cardList = if(user == resourceUser1) {
override def getPhysicalCardsForUser(user: User, callContext: Option[CallContext]) = {
val cardList = if (user == resourceUser1) {
user1AllCards
} else if (user == resourceUser2) {
user2AllCards
@ -74,9 +89,9 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers with DefaultConne
}
Future(Full(cardList), callContext)
}
override def getPhysicalCardsForBankLegacy(bank: Bank, user: User, queryParams: List[OBPQueryParam]) = {
val cardList = if(user == resourceUser1) {
override def getPhysicalCardsForBank(bank: Bank, user: User, queryParams: List[OBPQueryParam], callContext: Option[CallContext]) = Future {
val cardList = if (user == resourceUser1) {
user1CardsForOneBank
} else if (user == resourceUser2) {
user2CardsForOneBank
@ -84,23 +99,9 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers with DefaultConne
List()
}
Full(cardList)
}
}
override def beforeAll() {
super.beforeAll()
//use the mock connector
Connector.connector.default.set(MockedCardConnector)
}
override def afterAll() {
super.afterAll()
//reset the default connector
Connector.connector.default.set(Connector.buildOne)
wipeTestData()
}
feature("Getting details of physical cards") {
}.map((_, callContext))
feature("Getting details of physical cards") {
scenario("A user wants to get details of all their cards across all banks") {
When("A user requests their cards")
@ -143,5 +144,7 @@ class PhysicalCardsTest extends ServerSetup with DefaultUsers with DefaultConne
}
}
}
}