-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for getting me and my emails
- Loading branch information
1 parent
aae25f7
commit 380ef3f
Showing
4 changed files
with
105 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"page": 1, | ||
"pagelen": 10, | ||
"size": 1, | ||
"values": [ | ||
{ | ||
"email": "[email protected]", | ||
"is_confirmed": true, | ||
"is_primary": true, | ||
"links": { | ||
"self": { | ||
"href": "https://api.bitbucket.org/2.0/user/emails/[email protected]" | ||
} | ||
}, | ||
"type": "email" | ||
} | ||
] | ||
} |
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,29 @@ | ||
{ | ||
"created_on": "2011-12-20T16:34:07.132459+00:00", | ||
"display_name": "tutorials account", | ||
"links": { | ||
"avatar": { | ||
"href": "https://bitbucket-assetroot.s3.amazonaws.com/c/photos/2013/Nov/25/tutorials-avatar-1563784409-6_avatar.png" | ||
}, | ||
"followers": { | ||
"href": "https://api.bitbucket.org/2.0/users/tutorials/followers" | ||
}, | ||
"following": { | ||
"href": "https://api.bitbucket.org/2.0/users/tutorials/following" | ||
}, | ||
"html": { | ||
"href": "https://bitbucket.org/tutorials" | ||
}, | ||
"repositories": { | ||
"href": "https://api.bitbucket.org/2.0/repositories/tutorials" | ||
}, | ||
"self": { | ||
"href": "https://api.bitbucket.org/2.0/users/tutorials" | ||
} | ||
}, | ||
"location": "Santa Monica, CA", | ||
"type": "user", | ||
"username": "tutorials", | ||
"uuid": "{c788b2da-b7a2-404c-9e26-d3f077557007}", | ||
"website": "https://tutorials.bitbucket.org/" | ||
} |
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 |
---|---|---|
@@ -1,7 +1,19 @@ | ||
import XCTest | ||
import Nocilla | ||
import TrashCanKit | ||
|
||
class UserTests: XCTestCase { | ||
override func setUp() { | ||
super.setUp() | ||
LSNocilla.sharedInstance().start() | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
LSNocilla.sharedInstance().clearStubs() | ||
LSNocilla.sharedInstance().stop() | ||
} | ||
|
||
func testConstructFromJSON() { | ||
let subject = User(TestHelper.loadJSON("User")) | ||
XCTAssertEqual(subject.id, "{e9f0168c-cdf8-404a-95bb-3943dd2a65b6}") | ||
|
@@ -16,4 +28,42 @@ class UserTests: XCTestCase { | |
XCTAssertEqual(subject.email, "[email protected]") | ||
XCTAssertEqual(subject.type, "email") | ||
} | ||
|
||
func testMe() { | ||
let tokenConfig = TokenConfiguration("123456", refreshToken: "7890") | ||
stubRequest("GET", "https://bitbucket.org/api/2.0/user?access_token=123456").andReturn(200).withBody(TestHelper.loadJSONString("Me")) | ||
let expectation = expectationWithDescription("get_me") | ||
TrashCanKit(tokenConfig).me() { response in | ||
switch response { | ||
case .Success(let user): | ||
XCTAssertEqual(user.name, "tutorials account") | ||
expectation.fulfill() | ||
case .Failure: | ||
XCTAssertFalse(true) | ||
expectation.fulfill() | ||
} | ||
} | ||
waitForExpectationsWithTimeout(1) { error in | ||
XCTAssertNil(error) | ||
} | ||
} | ||
|
||
func testMyEmail() { | ||
let tokenConfig = TokenConfiguration("123456", refreshToken: "7890") | ||
stubRequest("GET", "https://bitbucket.org/api/2.0/user/emails?access_token=123456").andReturn(200).withBody(TestHelper.loadJSONString("Emails")) | ||
let expectation = expectationWithDescription("get_me") | ||
TrashCanKit(tokenConfig).emails() { response in | ||
switch response { | ||
case .Success(let emails): | ||
XCTAssertEqual(emails.first?.email, "[email protected]") | ||
expectation.fulfill() | ||
case .Failure: | ||
XCTAssertFalse(true) | ||
expectation.fulfill() | ||
} | ||
} | ||
waitForExpectationsWithTimeout(1) { error in | ||
XCTAssertNil(error) | ||
} | ||
} | ||
} |