From f9e1265befff70d0c2d4eab2d533a27b400ec7cd Mon Sep 17 00:00:00 2001 From: Sandro Machado Date: Tue, 20 Feb 2018 15:09:07 +0000 Subject: [PATCH 1/2] Fix fixtures --- Tests/UtilTests/Fixtures.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Tests/UtilTests/Fixtures.swift b/Tests/UtilTests/Fixtures.swift index d14f69a..c43370a 100644 --- a/Tests/UtilTests/Fixtures.swift +++ b/Tests/UtilTests/Fixtures.swift @@ -198,7 +198,7 @@ public class Fixtures { let destinationMerchant = Merchant(city: fakerFields["destinationMerchantCity"]!, country: fakerFields["destinationMerchantCountry"]!, name: fakerFields["destinationMerchantName"]!, state: fakerFields["destinationMerchantState"]!, zipCode: fakerFields["destinationMerchantZipCode"]!) let destinationNode = Node(brand: fakerFields["destinationNodeBrand"]!, id: fakerFields["destinationNodeId"]!, type: fakerFields["destinationNodeType"]!) let denomination = Denomination(amount: fakerFields["denominationAmount"]!, currency: fakerFields["denominationCurrency"]!, pair: fakerFields["denominationPair"]!, rate: fakerFields["denominationRate"]!) - let destination = Destination(accountId: fakerFields["destinationAccountId"]!, cardId: fakerFields["destinationCardId"]!, accountType: fakerFields["destinationAccountType"]!, amount: fakerFields["destinationAmount"]!, base: fakerFields["destinationBase"]!, commission: fakerFields["destinationCommission"]!, currency: fakerFields["destinationCurrency"]!, description: fakerFields["destinationDescription"]!, fee: fakerFields["destinationFee"]!, merchant: destinationMerchant, node: destinationNode, rate: fakerFields["destinationRate"]!, type: fakerFields["destinationType"]!, username: fakerFields["destinationUsername"]!) + let destination = Destination(accountId: fakerFields["destinationAccountId"]!, cardId: fakerFields["destinationCardId"]!, accountType: fakerFields["destinationAccountType"]!, address: fakerFields["destinationAddress"]!, amount: fakerFields["destinationAmount"]!, base: fakerFields["destinationBase"]!, commission: fakerFields["destinationCommission"]!, currency: fakerFields["destinationCurrency"]!, description: fakerFields["destinationDescription"]!, fee: fakerFields["destinationFee"]!, merchant: destinationMerchant, node: destinationNode, rate: fakerFields["destinationRate"]!, type: fakerFields["destinationType"]!, username: fakerFields["destinationUsername"]!) let fees = [Fee(amount: fakerFields["feeAmount"]!, currency: fakerFields["feeCurrency"]!, percentage: fakerFields["feePercentage"]!, target: fakerFields["feeTarget"]!, type: fakerFields["feeType"]!)] var sources: [Source] = [] From 772618afd87db034a465945ec6e7ebeffa31ba82 Mon Sep 17 00:00:00 2001 From: Sandro Machado Date: Tue, 20 Feb 2018 15:08:53 +0000 Subject: [PATCH 2/2] Add security code to transaction commit --- .../TransactionCommitRequest.swift | 23 +++++++++++++ .../ModelTests/TransactionTest.swift | 34 +++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/Source/Model/Transaction/TransactionCommitRequest.swift b/Source/Model/Transaction/TransactionCommitRequest.swift index 770dafa..7860e2f 100644 --- a/Source/Model/Transaction/TransactionCommitRequest.swift +++ b/Source/Model/Transaction/TransactionCommitRequest.swift @@ -10,6 +10,9 @@ open class TransactionCommitRequest: Mappable { /// The transaction message. public private(set) final var message: String? + /// The transaction security code. + public private(set) final var securityCode: String? + /** Constructor. @@ -28,6 +31,15 @@ open class TransactionCommitRequest: Mappable { self.message = message } + /** + Constructor. + + - parameter securityCode: The transaction security code. + */ + public init(securityCode: String) { + self.securityCode = securityCode + } + /** Constructor. @@ -39,6 +51,17 @@ open class TransactionCommitRequest: Mappable { self.message = message } + /** + Constructor. + + - parameter message: The transaction message. + - parameter securityCode: The transaction security code. + */ + public init(message: String?, securityCode: String) { + self.message = message + self.securityCode = securityCode + } + // MARK: Required by the ObjectMapper. /** diff --git a/Tests/IntegrationTests/ModelTests/TransactionTest.swift b/Tests/IntegrationTests/ModelTests/TransactionTest.swift index edbf2f1..bcfcc10 100644 --- a/Tests/IntegrationTests/ModelTests/TransactionTest.swift +++ b/Tests/IntegrationTests/ModelTests/TransactionTest.swift @@ -262,6 +262,23 @@ class TransactionTest: UpholdTestCase { wait() } + func testCommitWithTransactionCommitRequestWithSecurityCodeShouldReturnTheTransaction() { + let testExpectation = expectation(description: "Transaction test: commit transaction.") + + let transaction: Transaction = Fixtures.loadTransaction(fields: ["transactionId": "foobar", "transactionStatus": "pending"]) + transaction.adapter = MockRestAdapter(body: Mapper().toJSONString(transaction)!) + + transaction.commit(transactionCommit: TransactionCommitRequest(securityCode: "1234")).then { (transaction: Transaction) -> Void in + XCTAssertEqual(transaction.id, "foobar", "Failed: Wrong transaction object.") + + testExpectation.fulfill() + }.catch(execute: { (_: Error) in + XCTFail("User test: create transaction transfer error.") + }) + + wait() + } + func testCommitWithTransactionCommitRequestWithBeneficiaryAndMessageShouldReturnTheTransaction() { let testExpectation = expectation(description: "Transaction test: commit transaction.") @@ -279,6 +296,23 @@ class TransactionTest: UpholdTestCase { wait() } + func testCommitWithTransactionCommitRequestWithMessageAndSecurityCodeShouldReturnTheTransaction() { + let testExpectation = expectation(description: "Transaction test: commit transaction.") + + let transaction: Transaction = Fixtures.loadTransaction(fields: ["transactionId": "foobar", "transactionStatus": "pending"]) + transaction.adapter = MockRestAdapter(body: Mapper().toJSONString(transaction)!) + + transaction.commit(transactionCommit: TransactionCommitRequest(message: "foobar", securityCode: "1234")).then { (transaction: Transaction) -> Void in + XCTAssertEqual(transaction.id, "foobar", "Failed: Wrong transaction object.") + + testExpectation.fulfill() + }.catch(execute: { (_: Error) in + XCTFail("User test: create transaction transfer error.") + }) + + wait() + } + func testCommitShouldReturnUnexpectedResponseErrorIfAccountIdIsNil() { let testExpectation = expectation(description: "Transaction test: commit transaction.")