Skip to content

Commit

Permalink
Merge pull request #69 from uphold/feature/add-security-code-transact…
Browse files Browse the repository at this point in the history
…ion-commit

Add security code transaction commit
  • Loading branch information
d-moreira authored Feb 22, 2018
2 parents 23d54fa + 772618a commit 9dc3061
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
23 changes: 23 additions & 0 deletions Source/Model/Transaction/TransactionCommitRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.

Expand All @@ -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.

/**
Expand Down
34 changes: 34 additions & 0 deletions Tests/IntegrationTests/ModelTests/TransactionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand All @@ -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.")

Expand Down
2 changes: 1 addition & 1 deletion Tests/UtilTests/Fixtures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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] = []

Expand Down

0 comments on commit 9dc3061

Please sign in to comment.