-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #22 from uphold/feature/update-transaction
Update transaction model
- Loading branch information
Showing
15 changed files
with
474 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import Foundation | ||
import ObjectMapper | ||
|
||
/// Transaction commit request model. | ||
public class TransactionCommitRequest: Mappable { | ||
|
||
/// The transaction message. | ||
public private(set) final var message: String? | ||
|
||
/** | ||
Constructor. | ||
|
||
- parameter message: The transaction message. | ||
*/ | ||
public init(message: String) { | ||
self.message = message | ||
} | ||
|
||
// MARK: Required by the ObjectMapper. | ||
|
||
/** | ||
Constructor. | ||
*/ | ||
required public init?(_ map: Map) { | ||
} | ||
|
||
/** | ||
Maps the JSON to the Object. | ||
|
||
- parameter map: The object to map. | ||
*/ | ||
public func mapping(map: Map) { | ||
self.message <- map["message"] | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -115,20 +115,20 @@ class CardTest: UpholdTestCase { | |
|
||
card.createTransaction(transactionRequest).then { (transaction: Transaction) -> () in | ||
XCTAssertEqual(transaction.createdAt, "2014-08-27T00:01:11.616Z", "Failed: Wrong transaction createdAt.") | ||
XCTAssertEqual(transaction.denomination?.amount, "0.1", "Failed: Wrong transaction denomination amount.") | ||
XCTAssertEqual(transaction.denomination?.currency, "BTC", "Failed: Wrong transaction denomination currency.") | ||
XCTAssertEqual(transaction.denomination?.pair, "BTCBTC", "Failed: Wrong transaction denomination pair.") | ||
XCTAssertEqual(transaction.denomination?.rate, "1.00", "Failed: Wrong transaction denomination rate.") | ||
XCTAssertEqual(transaction.destination?.accountId, "fuz", "Failed: Wrong transaction destination accountId.") | ||
XCTAssertEqual(transaction.destination?.accountType, "buz", "Failed: Wrong transaction destination accountType.") | ||
XCTAssertEqual(transaction.destination?.amount, "0.1", "Failed: Wrong transaction destination amount.") | ||
XCTAssertEqual(transaction.destination?.base, "0.1", "Failed: Wrong transaction destination base.") | ||
XCTAssertEqual(transaction.destination?.commission, "0.00", "Failed: Wrong transaction destination commission.") | ||
XCTAssertEqual(transaction.destination?.currency, "BTC", "Failed: Wrong transaction destination currency.") | ||
XCTAssertEqual(transaction.destination?.description, "[email protected]", "Failed: Wrong transaction destination description.") | ||
XCTAssertEqual(transaction.destination?.fee, "0.00", "Failed: Wrong transaction destination fee.") | ||
XCTAssertEqual(transaction.destination?.rate, "1.00", "Failed: Wrong transaction destination rate.") | ||
XCTAssertEqual(transaction.destination?.type, "email", "Failed: Wrong transaction destination type.") | ||
XCTAssertEqual(transaction.denomination!.amount, "0.1", "Failed: Wrong transaction denomination amount.") | ||
XCTAssertEqual(transaction.denomination!.currency, "BTC", "Failed: Wrong transaction denomination currency.") | ||
XCTAssertEqual(transaction.denomination!.pair, "BTCBTC", "Failed: Wrong transaction denomination pair.") | ||
XCTAssertEqual(transaction.denomination!.rate, "1.00", "Failed: Wrong transaction denomination rate.") | ||
XCTAssertEqual(transaction.destination!.accountId, "fuz", "Failed: Wrong transaction destination accountId.") | ||
XCTAssertEqual(transaction.destination!.accountType, "buz", "Failed: Wrong transaction destination accountType.") | ||
XCTAssertEqual(transaction.destination!.amount, "0.1", "Failed: Wrong transaction destination amount.") | ||
XCTAssertEqual(transaction.destination!.base, "0.1", "Failed: Wrong transaction destination base.") | ||
XCTAssertEqual(transaction.destination!.commission, "0.00", "Failed: Wrong transaction destination commission.") | ||
XCTAssertEqual(transaction.destination!.currency, "BTC", "Failed: Wrong transaction destination currency.") | ||
XCTAssertEqual(transaction.destination!.description, "[email protected]", "Failed: Wrong transaction destination description.") | ||
XCTAssertEqual(transaction.destination!.fee, "0.00", "Failed: Wrong transaction destination fee.") | ||
XCTAssertEqual(transaction.destination!.rate, "1.00", "Failed: Wrong transaction destination rate.") | ||
XCTAssertEqual(transaction.destination!.type, "email", "Failed: Wrong transaction destination type.") | ||
XCTAssertEqual(transaction.id, "foobar", "Failed: Wrong transaction id.") | ||
XCTAssertEqual(transaction.message, "foobar", "Failed: Wrong transaction message.") | ||
XCTAssertEqual(transaction.normalized!.count, 1, "Failed: Wrong transaction normalized count.") | ||
|
@@ -137,25 +137,25 @@ class CardTest: UpholdTestCase { | |
XCTAssertEqual(transaction.normalized![0].currency, "BTC", "Failed: Wrong transaction normalized currency.") | ||
XCTAssertEqual(transaction.normalized![0].fee, "1.00", "Failed: Wrong transaction normalized fee.") | ||
XCTAssertEqual(transaction.normalized![0].rate, "2.00", "Failed: Wrong transaction normalized rate.") | ||
XCTAssertEqual(transaction.origin?.accountId, "fiz", "Failed: Wrong transaction origin accountId.") | ||
XCTAssertEqual(transaction.origin?.cardId, "bar", "Failed: Wrong transaction origin cardId.") | ||
XCTAssertEqual(transaction.origin?.accountType, "biz", "Failed: Wrong transaction origin accountType.") | ||
XCTAssertEqual(transaction.origin?.amount, "0.1", "Failed: Wrong transaction origin amount.") | ||
XCTAssertEqual(transaction.origin?.base, "0.1", "Failed: Wrong transaction origin base.") | ||
XCTAssertEqual(transaction.origin?.commission, "0.00", "Failed: Wrong transaction origin comission.") | ||
XCTAssertEqual(transaction.origin?.currency, "BTC", "Failed: Wrong transaction origin currency.") | ||
XCTAssertEqual(transaction.origin?.description, "Foo Bar", "Failed: Wrong transaction origin description.") | ||
XCTAssertEqual(transaction.origin?.fee, "0.00", "Failed: Wrong transaction origin fee.") | ||
XCTAssertEqual(transaction.origin?.rate, "1.00", "Failed: Wrong transaction origin rate.") | ||
XCTAssertEqual(transaction.origin?.type, "card", "Failed: Wrong transaction origin type.") | ||
XCTAssertEqual(transaction.origin?.username, "foobar", "Failed: Wrong transaction origin username.") | ||
XCTAssertEqual(transaction.params?.currency, "BTC", "Failed: Wrong transaction parameter currency.") | ||
XCTAssertEqual(transaction.params?.margin, "0.00", "Failed: Wrong transaction parameter margin.") | ||
XCTAssertEqual(transaction.params?.pair, "BTCBTC", "Failed: Wrong transaction parameter pair.") | ||
XCTAssertEqual(transaction.params?.rate, "1.00", "Failed: Wrong transaction parameter rate.") | ||
XCTAssertEqual(transaction.params?.refunds, "fizbiz", "Failed: Wrong transaction parameter refunds.") | ||
XCTAssertEqual(transaction.params?.ttl, 30000, "Failed: Wrong transaction parameter ttl.") | ||
XCTAssertEqual(transaction.params?.type, "invite", "Failed: Wrong transaction parameter type.") | ||
XCTAssertEqual(transaction.origin!.accountId, "fiz", "Failed: Wrong transaction origin accountId.") | ||
XCTAssertEqual(transaction.origin!.cardId, "bar", "Failed: Wrong transaction origin cardId.") | ||
XCTAssertEqual(transaction.origin!.accountType, "biz", "Failed: Wrong transaction origin accountType.") | ||
XCTAssertEqual(transaction.origin!.amount, "0.1", "Failed: Wrong transaction origin amount.") | ||
XCTAssertEqual(transaction.origin!.base, "0.1", "Failed: Wrong transaction origin base.") | ||
XCTAssertEqual(transaction.origin!.commission, "0.00", "Failed: Wrong transaction origin comission.") | ||
XCTAssertEqual(transaction.origin!.currency, "BTC", "Failed: Wrong transaction origin currency.") | ||
XCTAssertEqual(transaction.origin!.description, "Foo Bar", "Failed: Wrong transaction origin description.") | ||
XCTAssertEqual(transaction.origin!.fee, "0.00", "Failed: Wrong transaction origin fee.") | ||
XCTAssertEqual(transaction.origin!.rate, "1.00", "Failed: Wrong transaction origin rate.") | ||
XCTAssertEqual(transaction.origin!.type, "card", "Failed: Wrong transaction origin type.") | ||
XCTAssertEqual(transaction.origin!.username, "foobar", "Failed: Wrong transaction origin username.") | ||
XCTAssertEqual(transaction.params!.currency, "BTC", "Failed: Wrong transaction parameter currency.") | ||
XCTAssertEqual(transaction.params!.margin, "0.00", "Failed: Wrong transaction parameter margin.") | ||
XCTAssertEqual(transaction.params!.pair, "BTCBTC", "Failed: Wrong transaction parameter pair.") | ||
XCTAssertEqual(transaction.params!.rate, "1.00", "Failed: Wrong transaction parameter rate.") | ||
XCTAssertEqual(transaction.params!.refunds, "fizbiz", "Failed: Wrong transaction parameter refunds.") | ||
XCTAssertEqual(transaction.params!.ttl, 30000, "Failed: Wrong transaction parameter ttl.") | ||
XCTAssertEqual(transaction.params!.type, "invite", "Failed: Wrong transaction parameter type.") | ||
XCTAssertEqual(transaction.refundedById, "foobiz", "Failed: Wrong transaction refundedById.") | ||
XCTAssertEqual(transaction.status, "pending", "Failed: Wrong transaction status.") | ||
XCTAssertEqual(transaction.type, "transfer", "Failed: Wrong transaction type.") | ||
|
@@ -192,6 +192,22 @@ class CardTest: UpholdTestCase { | |
wait() | ||
} | ||
|
||
func testCreateTransactionWithCommitShouldReturnTheTransaction() { | ||
let card: Card = Fixtures.loadCard(nil) | ||
card.adapter = MockRestAdapter(body: "{ \"id\": \"foobar\" }") | ||
let expectation = expectationWithDescription("Card test: create transaction.") | ||
let transactionDenominationRequest = TransactionDenominationRequest(amount: "foo", currency: "bar") | ||
let transactionRequest = TransactionRequest(denomination: transactionDenominationRequest, destination: "foobar") | ||
|
||
card.createTransaction(true, transactionRequest: transactionRequest).then { (transaction: Transaction) -> () in | ||
XCTAssertEqual(transaction.id, "foobar", "Failed: Wrong transaction id.") | ||
|
||
expectation.fulfill() | ||
} | ||
|
||
wait() | ||
} | ||
|
||
func testGetTransactionsShouldReturnTheArrayOfTransactions() { | ||
let card: Card = Fixtures.loadCard(nil) | ||
let transactions: [Transaction] = [Fixtures.loadTransaction(["transactionId": "foobar"]), Fixtures.loadTransaction(["transactionId": "foobiz"])] | ||
|
Oops, something went wrong.