Created
February 6, 2017 09:27
-
-
Save laiso/faea773bd9f99f99b8dae137b1679931 to your computer and use it in GitHub Desktop.
ログイン成否のテスト書けそうな気がしてきた気がする #CodePiece
This file contains hidden or 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
import Quick | |
import Nimble | |
import RxTest | |
import RxBlocking | |
import RxSwift | |
import RxCocoa | |
import Result | |
@testable import customer | |
class SigninViewModelSpec: QuickSpec { | |
override func spec() { | |
var viewModel: SigninViewModel! | |
context("unauthrorized") { | |
struct MockAuthorization: AuthorizationProtocol { | |
func getAccessToken(email: String, password: String) -> Observable<Result<AccessToken, RxCocoaURLError>> { | |
return .just(.failure(.unknown)) | |
} | |
func saveAccessToken(token: AccessToken) -> Observable<Bool> { return .just(true) } | |
} | |
beforeEach { | |
viewModel = SigninViewModel((email: .just(""), | |
password: .just(""), | |
submitTap: .just()), | |
auth: MockAuthorization()) | |
} | |
it("should not be logged") { | |
let loggedIn = try! viewModel.loggedIn.toBlocking(timeout: 3).last() | |
expect(loggedIn).to(beFalse()) | |
} | |
} | |
context("authorization success") { | |
struct MockAuthorization: AuthorizationProtocol { | |
func getAccessToken(email: String, password: String) -> Observable<Result<AccessToken, RxCocoaURLError>> { | |
let token = AccessToken(value: "IM_DUMMY_TOKEN") | |
return .just(Result<AccessToken, RxCocoaURLError>.success(token)) | |
} | |
func saveAccessToken(token: AccessToken) -> Observable<Bool> { return .just(true) } | |
} | |
beforeEach { | |
viewModel = SigninViewModel((email: Observable.just(""), | |
password: Observable.just(""), | |
submitTap: Observable.just()), | |
auth: MockAuthorization()) | |
} | |
it("should be logged") { | |
let loggedIn = try! viewModel.loggedIn.toBlocking(timeout: 3).last() | |
expect(loggedIn).to(beTrue()) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment