Skip to content

Commit

Permalink
Update tests format
Browse files Browse the repository at this point in the history
  • Loading branch information
diogoguimaraes committed Nov 10, 2015
1 parent 0d820a4 commit f5479d3
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 62 deletions.
72 changes: 32 additions & 40 deletions Tests/Integration/Client/UpholdClientTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,22 @@ class UpholdClientTest: UpholdTestCase {

func testGetTickersShouldReturnTheArrayOfTickers() {
let expectation = expectationWithDescription("Uphold client test.")

let json: String = "[" +
"{" +
"\"ask\": \"foo\"," +
"\"bid\": \"bar\"," +
"\"currency\": \"foobar\"," +
"\"pair\": \"foobiz\"" +
"}, {" +
"\"ask\": \"fiz\"," +
"\"bid\": \"biz\"," +
"\"currency\": \"foobiz\"," +
"\"pair\": \"bar\"" +
"}, {" +
"\"ask\": \"foobar\"," +
"\"bid\": \"foobaz\"," +
"\"currency\": \"bar\"," +
"\"pair\": \"foo\"" +
"}" +
"]"

let json: String = "[{" +
"\"ask\": \"foo\"," +
"\"bid\": \"bar\"," +
"\"currency\": \"foobar\"," +
"\"pair\": \"foobiz\"" +
"}, {" +
"\"ask\": \"fiz\"," +
"\"bid\": \"biz\"," +
"\"currency\": \"foobiz\"," +
"\"pair\": \"bar\"" +
"}, {" +
"\"ask\": \"foobar\"," +
"\"bid\": \"foobaz\"," +
"\"currency\": \"bar\"," +
"\"pair\": \"foo\"" +
"}]"
let client = UpholdClient()
client.token.adapter = MockRestAdapter(body: json)

Expand All @@ -55,26 +51,22 @@ class UpholdClientTest: UpholdTestCase {

func testGetTickersByCurrencyShouldReturnTheArrayOfTickers() {
let expectation = expectationWithDescription("Uphold client test.")

let json: String = "[" +
"{" +
"\"ask\": \"foo\"," +
"\"bid\": \"bar\"," +
"\"currency\": \"foobar\"," +
"\"pair\": \"foobiz\"" +
"}, {" +
"\"ask\": \"fiz\"," +
"\"bid\": \"biz\"," +
"\"currency\": \"foobiz\"," +
"\"pair\": \"bar\"" +
"}, {" +
"\"ask\": \"foobar\"," +
"\"bid\": \"foobaz\"," +
"\"currency\": \"bar\"," +
"\"pair\": \"foo\"" +
"}" +
"]"

let json: String = "[{" +
"\"ask\": \"foo\"," +
"\"bid\": \"bar\"," +
"\"currency\": \"foobar\"," +
"\"pair\": \"foobiz\"" +
"}, {" +
"\"ask\": \"fiz\"," +
"\"bid\": \"biz\"," +
"\"currency\": \"foobiz\"," +
"\"pair\": \"bar\"" +
"}, {" +
"\"ask\": \"foobar\"," +
"\"bid\": \"foobaz\"," +
"\"currency\": \"bar\"," +
"\"pair\": \"foo\"" +
"}]"
let client = UpholdClient()
client.token.adapter = MockRestAdapter(body: json)

Expand Down
19 changes: 0 additions & 19 deletions Tests/Integration/Client/UpholdRestAdapterTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,11 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildEmptyResponseShouldReturnBadRequestError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let mockRequest = MockRequest(body: nil, code: 400, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
let promise: Promise<Response> = UpholdRestAdapter().buildEmptyResponse(request)

promise.recover { (error: ErrorType) -> Promise<Response> in

guard let badRequestError = error as? BadRequestError else {
XCTFail("Error should be BadRequestError.")

Expand All @@ -44,7 +42,6 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildEmptyResponseShouldReturnFulfilledPromise() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let mockRequest = MockRequest(body: nil, code: 200, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
let promise: Promise<Response> = UpholdRestAdapter().buildEmptyResponse(request)
Expand All @@ -61,13 +58,11 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildEmptyResponseShouldReturnLogicError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let mockRequest = MockRequest(body: "foobar", code: 200, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
let promise: Promise<Response> = UpholdRestAdapter().buildEmptyResponse(request)

promise.recover { (error: ErrorType) -> Promise<Response> in

guard let logicError = error as? LogicError else {
XCTFail("Error should be LogicError.")

Expand All @@ -87,7 +82,6 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildResponseShouldReturnBadRequestError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let json = "{" +
"\"ask\":\"1.2\"," +
"\"bid\":\"1\"," +
Expand All @@ -99,7 +93,6 @@ class UpholdRestAdapterTest: UpholdTestCase {
let promise: Promise<Rate> = UpholdRestAdapter().buildResponse(request)

promise.recover { (error: ErrorType) -> Promise<Rate> in

guard let badRequestError = error as? BadRequestError else {
XCTFail("Error should be BadRequestError.")

Expand All @@ -119,13 +112,11 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildResponseShouldReturnEmptyBodyLogicError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let mockRequest = MockRequest(body: nil, code: 200, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
let promise: Promise<Rate> = UpholdRestAdapter().buildResponse(request)

promise.recover { (error: ErrorType) -> Promise<Rate> in

guard let logicError = error as? LogicError else {
XCTFail("Error should be LogicError.")

Expand All @@ -145,7 +136,6 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildResponseShouldReturnFailedMapLogicError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let json = "{[" +
"\"ask\":\"1.2\"," +
"\"bid\":\"1\"," +
Expand All @@ -157,7 +147,6 @@ class UpholdRestAdapterTest: UpholdTestCase {
let promise: Promise<Rate> = UpholdRestAdapter().buildResponse(request)

promise.recover { (error: ErrorType) -> Promise<Rate> in

guard let logicError = error as? LogicError else {
XCTFail("Error should be LogicError.")

Expand All @@ -177,7 +166,6 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildResponseShouldReturnFulfilledPromise() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let json = "{" +
"\"ask\":\"1.2\"," +
"\"bid\":\"1\"," +
Expand All @@ -202,14 +190,12 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildResponseArrayShouldReturnBadRequestError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let json = "[{\"ask\":\"1\"}, {\"ask\":\"440.99\"}]"
let mockRequest = MockRequest(body: json, code: 400, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
let promise: Promise<[Rate]> = UpholdRestAdapter().buildResponse(request)

promise.recover { (error: ErrorType) -> Promise<[Rate]> in

guard let badRequestError = error as? BadRequestError else {
XCTFail("Error should be BadRequestError.")

Expand All @@ -229,13 +215,11 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildResponseArrayShouldReturnEmptyBodyLogicError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let mockRequest = MockRequest(body: nil, code: 200, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
let promise: Promise<[Rate]> = UpholdRestAdapter().buildResponse(request)

promise.recover { (error: ErrorType) -> Promise<[Rate]> in

guard let logicError = error as? LogicError else {
XCTFail("Error should be LogicError.")

Expand All @@ -255,14 +239,12 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildResponseArrayShouldReturnFailedMapLogicError() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let jsonRates = "[[{\"ask\":\"1\"}, {\"ask\":\"440.99\"}]"
let mockRequest = MockRequest(body: jsonRates, code: 200, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
let promise: Promise<[Rate]> = UpholdRestAdapter().buildResponse(request)

promise.recover { (error: ErrorType) -> Promise<[Rate]> in

guard let logicError = error as? LogicError else {
XCTFail("Error should be LogicError.")

Expand All @@ -282,7 +264,6 @@ class UpholdRestAdapterTest: UpholdTestCase {

func testBuildResponseArrayShouldReturnFulfilledPromise() {
let expectation = expectationWithDescription("Uphold REST adapter response test.")

let jsonRates = "[{\"ask\":\"1\"}, {\"ask\":\"440.99\"}]"
let mockRequest = MockRequest(body: jsonRates, code: 200, errorHandler: {(error: NSError) -> Void in}, headers: nil, method: "foo")
let request = UpholdRestAdapter().buildRequest(mockRequest)
Expand Down
26 changes: 25 additions & 1 deletion Tests/Integration/Model/CardTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,31 @@ import ObjectMapper
class CardTest: XCTestCase {

func testCardMapperShouldReturnACard() {
let card = Mapper<Card>().map("{ \"address\": { \"bitcoin\": \"fuzbuz\" }, \"available\": \"87.52\", \"balance\": \"87.52\", \"currency\": \"EUR\", \"id\": \"foobar\", \"label\": \"Foo card\", \"lastTransactionAt\": \"foobiz\", \"settings\": { \"position\": 4, \"starred\": true }, \"addresses\": [ { \"id\": \"fiz\", \"network\": \"biz\" } ], \"normalized\": [ { \"available\": \"99.04\", \"balance\": \"99.04\", \"currency\": \"USD\" } ] }")
let json: String = "{" +
"\"address\": {" +
"\"bitcoin\": \"fuzbuz\"" +
"}," +
"\"available\": \"87.52\"," +
"\"balance\": \"87.52\"," +
"\"currency\": \"EUR\"," +
"\"id\": \"foobar\"," +
"\"label\": \"Foo card\"," +
"\"lastTransactionAt\": \"foobiz\"," +
"\"settings\": {" +
"\"position\": 4," +
"\"starred\": true" +
"}," +
"\"addresses\": [{" +
"\"id\": \"fiz\"," +
"\"network\": \"biz\"" +
"}]," +
"\"normalized\": [{" +
"\"available\": \"99.04\"," +
"\"balance\": \"99.04\"," +
"\"currency\": \"USD\"" +
"}]" +
"}"
let card = Mapper<Card>().map(json)

XCTAssertEqual(card!.id!, "foobar", "Failed: Card id didn't match.")
XCTAssertFalse(card!.address!.isEmpty, "Failed: Address didn't match.")
Expand Down
52 changes: 51 additions & 1 deletion Tests/Integration/Model/TransactionTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,57 @@ import ObjectMapper
class TransactionTest: XCTestCase {

func testTransactionMapperShouldReturnATransaction() {
let transaction = Mapper<Transaction>().map("{\"id\":\"foobar\",\"type\":\"transfer\",\"message\":\"foobar message\",\"status\":\"pending\",\"RefundedById\":\"foobiz\",\"createdAt\":\"fuz\",\"denomination\":{\"amount\":\"0.1\",\"currency\":\"BTC\",\"pair\":\"BTCBTC\",\"rate\":\"1.00\"},\"origin\":{\"CardId\":\"fizbiz\",\"amount\":\"0.1\",\"base\":\"0.1\",\"commission\":\"0.00\",\"currency\":\"BTC\",\"description\":\"Fuz Buz\",\"fee\":\"0.00\",\"rate\":\"1.00\",\"sources\":[{\"id\":\"fizbuz\",\"amount\":\"2.00\"}],\"type\":\"card\",\"username\":\"fuzbuz\"},\"destination\":{\"CardId\": \"fuzbuz\", \"amount\":\"0.1\",\"base\":\"0.1\",\"commission\":\"0.00\",\"currency\":\"BTC\",\"description\":\"[email protected]\",\"fee\":\"0.00\",\"rate\":\"1.00\",\"type\":\"email\", \"username\": \"fizbiz\"},\"params\":{\"currency\":\"BTC\",\"margin\":\"0.00\",\"pair\":\"BTCBTC\",\"rate\":\"1.00\",\"ttl\":30000,\"type\":\"invite\"}}")
let json: String = "{" +
"\"id\": \"foobar\"," +
"\"type\": \"transfer\"," +
"\"message\": \"foobar message\"," +
"\"status\": \"pending\"," +
"\"RefundedById\": \"foobiz\"," +
"\"createdAt\": \"fuz\"," +
"\"denomination\": {" +
"\"amount\": \"0.1\"," +
"\"currency\": \"BTC\"," +
"\"pair\": \"BTCBTC\"," +
"\"rate\": \"1.00\"" +
"}," +
"\"origin\": {" +
"\"CardId\": \"fizbiz\"," +
"\"amount\": \"0.1\"," +
"\"base\": \"0.1\"," +
"\"commission\": \"0.00\"," +
"\"currency\": \"BTC\"," +
"\"description\": \"Fuz Buz\"," +
"\"fee\": \"0.00\"," +
"\"rate\": \"1.00\"," +
"\"sources\": [{" +
"\"id\": \"fizbuz\"," +
"\"amount\": \"2.00\"" +
"}]," +
"\"type\": \"card\"," +
"\"username\": \"fuzbuz\"" +
"}," +
"\"destination\": {" +
"\"CardId\": \"fuzbuz\"," +
"\"amount\": \"0.1\"," +
"\"base\": \"0.1\"," +
"\"commission\": \"0.00\"," +
"\"currency\": \"BTC\"," +
"\"description\": \"[email protected]\"," +
"\"fee\": \"0.00\"," +
"\"rate\": \"1.00\"," +
"\"type\": \"email\"," +
"\"username\": \"fizbiz\"" +
"}," +
"\"params\": {" +
"\"currency\": \"BTC\"," +
"\"margin\": \"0.00\"," +
"\"pair\": \"BTCBTC\"," +
"\"rate\": \"1.00\"," +
"\"ttl\": 30000," +
"\"type\": \"invite\"" +
"}" +
"}"
let transaction = Mapper<Transaction>().map(json)

XCTAssertEqual(transaction!.id!, "foobar", "Failed: Transaction id didn't match.")
XCTAssertEqual(transaction!.createdAt!, "fuz", "Failed: Transaction createdAt didn't match.")
Expand Down
32 changes: 31 additions & 1 deletion Tests/Integration/Model/UserTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,37 @@ import ObjectMapper
class UserTest: XCTestCase {

func testUserMapperShouldReturnAUser() {
let user = Mapper<User>().map("{\"country\":\"US\",\"currencies\":[\"BTC\"],\"email\":\"[email protected]\",\"firstName\":\"Foo\",\"lastName\":\"Bar\",\"name\":\"Foo Bar\",\"settings\":{\"currency\":\"USD\",\"hasOtpEnabled\":true,\"hasNewsSubscription\":true,\"intl\":{\"dateTimeFormat\":{\"locale\":\"foo\"},\"language\":{\"locale\":\"bar\"},\"numberFormat\":{\"locale\":\"biz\"}},\"theme\":\"vintage\"},\"state\":\"WA\",\"status\":\"ok\",\"username\":\"foobar\"}")
let json: String = "{" +
"\"country\": \"US\"," +
"\"currencies\": [" +
"\"BTC\"" +
"]," +
"\"email\": \"[email protected]\"," +
"\"firstName\": \"Foo\"," +
"\"lastName\": \"Bar\"," +
"\"name\": \"Foo Bar\"," +
"\"settings\": {" +
"\"currency\": \"USD\"," +
"\"hasOtpEnabled\": true," +
"\"hasNewsSubscription\": true," +
"\"intl\": {" +
"\"dateTimeFormat\": {" +
"\"locale\": \"foo\"" +
"}," +
"\"language\": {" +
"\"locale\": \"bar\"" +
"}," +
"\"numberFormat\": {" +
"\"locale\": \"biz\"" +
"}" +
"}," +
"\"theme\": \"vintage\"" +
"}," +
"\"state\": \"WA\"," +
"\"status\": \"ok\"," +
"\"username\": \"foobar\"" +
"}"
let user = Mapper<User>().map(json)

XCTAssertEqual(user!.country!, "US", "Failed: User country didn't match.")
XCTAssertEqual(user!.currencies!.count, 1, "Failed: User currencies didn't match.")
Expand Down

0 comments on commit f5479d3

Please sign in to comment.