Skip to content

Commit

Permalink
Add security code to transaction commit
Browse files Browse the repository at this point in the history
  • Loading branch information
SandroMachado committed Feb 20, 2018
1 parent f9e1265 commit 772618a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
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

0 comments on commit 772618a

Please sign in to comment.