Skip to content

Commit

Permalink
ProfileTests 구현 완료
Browse files Browse the repository at this point in the history
  • Loading branch information
Hyunsik-Yoo committed Jul 25, 2020
1 parent 061abab commit 53030f0
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 21 deletions.
36 changes: 19 additions & 17 deletions thereto-ios/thereto-ios/features/membership/ProfileViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,25 @@ class ProfileViewModel: BaseViewModel {
let user = User(nickname: nickname, social: idSocial.1, id: idSocial.0, profileURL: profileURL)

self.output.showLoading.accept(true)
self.userService.signUp(user: user).subscribe(onNext: { (user) in
// 메인 화면으로 이동
self.userDefaults.setUserToken(token: user.id)
self.userDefaults.setNormalLaunch(isNormal: true) // 다시 로그인할때는 메인으로 돌아가도록
if let fcmToken = self.userDefaults.getFCMToken() {
self.userService.updateFCMToken(userId: user.id, fcmToken: fcmToken)
}
self.output.goToMain.accept(())
self.output.showLoading.accept(false)
}, onError: { (error) in
if let error = error as? CommonError {
self.output.showAlert.accept(error.description)
} else {
self.output.showAlert.accept(error.localizedDescription)
}
self.output.showLoading.accept(false)
}).disposed(by: self.disposeBag)
self.userService
.signUp(user: user)
.subscribe(onNext: { (user) in
// 메인 화면으로 이동
self.userDefaults.setUserToken(token: user.id)
self.userDefaults.setNormalLaunch(isNormal: true) // 다시 로그인할때는 메인으로 돌아가도록
if let fcmToken = self.userDefaults.getFCMToken() {
self.userService.updateFCMToken(userId: user.id, fcmToken: fcmToken)
}
self.output.goToMain.accept(())
self.output.showLoading.accept(false)
}, onError: { (error) in
if let error = error as? CommonError {
self.output.showAlert.accept(error.description)
} else {
self.output.showAlert.accept(error.localizedDescription)
}
self.output.showLoading.accept(false)
}).disposed(by: self.disposeBag)
} else {
self.output.errorMsg.accept("닉네임을 설정해주세요.")
}
Expand Down
71 changes: 67 additions & 4 deletions thereto-ios/theretoTests/membership/ProfileTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,79 @@ class ProfileTests: XCTestCase {
schedular.createColdObservable([.next(210, "")])
.bind(to: viewModel.input.nicknameText)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(220, "312")])
.bind(to: viewModel.output.profileImage)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(230, ("id", "facebook"))])
schedular.createColdObservable([.next(210, ("id", "facebook"))])
.bind(to: viewModel.idSocialPublisher)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(210, "")])
.bind(to: viewModel.output.profileImage)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(240, ())])
.bind(to: viewModel.input.tapConfirm)
.disposed(by: disposeBag)
schedular.start()

XCTAssertRecordedElements(errorMsgExpectation.events, ["닉네임을 설정해주세요."])
}

func testSignUpWithoutProfile() {
let showLoadingExpectation = schedular.createObserver(Bool.self)
let goToMainExpectation = schedular.createObserver(Void.self)

viewModel.output.showLoading
.bind(to: showLoadingExpectation)
.disposed(by: disposeBag)
viewModel.output.goToMain
.bind(to: goToMainExpectation)
.disposed(by: disposeBag)

// Input 추가
// 닉네임, 이미지, socialID 추가
schedular.createColdObservable([.next(210, "nickname")])
.bind(to: viewModel.input.nicknameText)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(210, ("id","facebook"))])
.bind(to: viewModel.idSocialPublisher)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(210, "")])
.bind(to: viewModel.output.profileImage)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(220, ())])
.bind(to: viewModel.input.tapConfirm)
.disposed(by: disposeBag)
schedular.start()

XCTAssertRecordedElements(showLoadingExpectation.events, [true, false])
XCTAssertEqual(goToMainExpectation.events.count, 1)
}

func testSignUpWithProfile() {
let showLoadingExpectation = schedular.createObserver(Bool.self)
let goToMainExpectation = schedular.createObserver(Void.self)

viewModel.output.showLoading
.bind(to: showLoadingExpectation)
.disposed(by: disposeBag)
viewModel.output.goToMain
.bind(to: goToMainExpectation)
.disposed(by: disposeBag)

// Input 추가
// 닉네임, 이미지, socialID 추가
schedular.createColdObservable([.next(210, "nickname")])
.bind(to: viewModel.input.nicknameText)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(210, ("id","facebook"))])
.bind(to: viewModel.idSocialPublisher)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(210, "profileImageURL")])
.bind(to: viewModel.output.profileImage)
.disposed(by: disposeBag)
schedular.createColdObservable([.next(220, ())])
.bind(to: viewModel.input.tapConfirm)
.disposed(by: disposeBag)
schedular.start()

XCTAssertRecordedElements(showLoadingExpectation.events, [true, false])
XCTAssertEqual(goToMainExpectation.events.count, 1)
}
}
Binary file not shown.

0 comments on commit 53030f0

Please sign in to comment.