Skip to content

Commit

Permalink
Add test for getting me and my emails
Browse files Browse the repository at this point in the history
  • Loading branch information
pietbrauer committed Nov 4, 2015
1 parent aae25f7 commit 380ef3f
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
8 changes: 8 additions & 0 deletions TrashCanKit.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
231B685A1BE9A3DD007AE2A6 /* TokenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 231B68591BE9A3DD007AE2A6 /* TokenTests.swift */; };
231B685C1BE9A699007AE2A6 /* refresh_token_error.json in Resources */ = {isa = PBXBuildFile; fileRef = 231B685B1BE9A699007AE2A6 /* refresh_token_error.json */; };
231B685F1BE9AAC6007AE2A6 /* Repositories.json in Resources */ = {isa = PBXBuildFile; fileRef = 231B685D1BE9AA66007AE2A6 /* Repositories.json */; };
231B68611BE9AD30007AE2A6 /* Me.json in Resources */ = {isa = PBXBuildFile; fileRef = 231B68601BE9AD30007AE2A6 /* Me.json */; };
231B68631BE9AD8D007AE2A6 /* Emails.json in Resources */ = {isa = PBXBuildFile; fileRef = 231B68621BE9AD8D007AE2A6 /* Emails.json */; };
236364741BE22F1000AA7104 /* TrashCanKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 236364731BE22F1000AA7104 /* TrashCanKit.h */; settings = {ATTRIBUTES = (Public, ); }; };
2363647B1BE22F1000AA7104 /* TrashCanKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 236364701BE22F1000AA7104 /* TrashCanKit.framework */; };
2363648E1BE22FCC00AA7104 /* TrashCanKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2363648A1BE22FCC00AA7104 /* TrashCanKit.swift */; };
Expand Down Expand Up @@ -69,6 +71,8 @@
231B68591BE9A3DD007AE2A6 /* TokenTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = TokenTests.swift; sourceTree = "<group>"; };
231B685B1BE9A699007AE2A6 /* refresh_token_error.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = refresh_token_error.json; sourceTree = "<group>"; };
231B685D1BE9AA66007AE2A6 /* Repositories.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Repositories.json; path = Fixtures/Repositories.json; sourceTree = "<group>"; };
231B68601BE9AD30007AE2A6 /* Me.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = Me.json; sourceTree = "<group>"; };
231B68621BE9AD8D007AE2A6 /* Emails.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; name = Emails.json; path = Fixtures/Emails.json; sourceTree = "<group>"; };
236364701BE22F1000AA7104 /* TrashCanKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = TrashCanKit.framework; sourceTree = BUILT_PRODUCTS_DIR; };
236364731BE22F1000AA7104 /* TrashCanKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = TrashCanKit.h; sourceTree = "<group>"; };
236364751BE22F1000AA7104 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
Expand Down Expand Up @@ -168,6 +172,8 @@
231B68571BE9A13C007AE2A6 /* authorize.json */,
231B685B1BE9A699007AE2A6 /* refresh_token_error.json */,
231B685D1BE9AA66007AE2A6 /* Repositories.json */,
231B68601BE9AD30007AE2A6 /* Me.json */,
231B68621BE9AD8D007AE2A6 /* Emails.json */,
);
name = Fixtures;
sourceTree = "<group>";
Expand Down Expand Up @@ -280,11 +286,13 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
231B68611BE9AD30007AE2A6 /* Me.json in Resources */,
231B685F1BE9AAC6007AE2A6 /* Repositories.json in Resources */,
231B68581BE9A13C007AE2A6 /* authorize.json in Resources */,
231B685C1BE9A699007AE2A6 /* refresh_token_error.json in Resources */,
236364A51BE2313B00AA7104 /* Email.json in Resources */,
236364A71BE2313B00AA7104 /* User.json in Resources */,
231B68631BE9AD8D007AE2A6 /* Emails.json in Resources */,
236364A61BE2313B00AA7104 /* Repository.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
18 changes: 18 additions & 0 deletions TrashCanKitTests/Fixtures/Emails.json
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"
}
]
}
29 changes: 29 additions & 0 deletions TrashCanKitTests/Me.json
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/"
}
50 changes: 50 additions & 0 deletions TrashCanKitTests/UserTests.swift
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}")
Expand All @@ -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)
}
}
}

0 comments on commit 380ef3f

Please sign in to comment.