-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✅ SignUpInteractorTests 추가, Mock Worker final 수정
- Loading branch information
Showing
9 changed files
with
404 additions
and
32 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
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
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
159 changes: 159 additions & 0 deletions
159
iOS/Layover/LayoverTests/Scenes/SignUp/SignUpInteractorTests.swift
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,159 @@ | ||
// | ||
// SignUpInteractorTests.swift | ||
// Layover | ||
// | ||
// Created by 김인환 on 1/6/24. | ||
// Copyright (c) 2024 CodeBomber. All rights reserved. | ||
// | ||
// This file was generated by the Clean Swift Xcode Templates so | ||
// you can apply clean architecture to your iOS and Mac projects, | ||
// see http://clean-swift.com | ||
// | ||
|
||
@testable import Layover | ||
import XCTest | ||
|
||
final class SignUpInteractorTests: XCTestCase { | ||
// MARK: Subject under test | ||
|
||
var sut: SignUpInteractor! | ||
|
||
typealias Models = SignUpModels | ||
|
||
// MARK: - Test lifecycle | ||
|
||
override func setUp() { | ||
super.setUp() | ||
setupSignUpInteractor() | ||
} | ||
|
||
// MARK: - Test setup | ||
|
||
func setupSignUpInteractor() { | ||
sut = SignUpInteractor() | ||
} | ||
|
||
// MARK: - Test doubles | ||
|
||
final class SignUpPresentationLogicSpy: SignUpPresentationLogic { | ||
var presentSignUpSuccessDidCalled = false | ||
var presentNicknameValidationDidCalled = false | ||
var presentNicknameValidationResponse: Models.ValidateNickname.Response! | ||
var presentNicknameDuplicationDidCalled = false | ||
var presentNicknameDupllicationResponse: Models.CheckDuplication.Response! | ||
|
||
func presentSignUpSuccess() { | ||
presentSignUpSuccessDidCalled = true | ||
} | ||
|
||
func presentNicknameValidation(with response: Models.ValidateNickname.Response) { | ||
presentNicknameValidationDidCalled = true | ||
presentNicknameValidationResponse = response | ||
} | ||
|
||
func presentNicknameDuplication(with response: Models.CheckDuplication.Response) { | ||
presentNicknameDuplicationDidCalled = true | ||
presentNicknameDupllicationResponse = response | ||
} | ||
} | ||
|
||
final class UserWorkerSpy: MockUserWorker { | ||
var validateNicknameCalled = false | ||
var checkNotDuplicationCalled = false | ||
|
||
override func validateNickname(_ nickname: String) -> NicknameState { | ||
validateNicknameCalled = true | ||
return super.validateNickname(nickname) | ||
} | ||
|
||
override func checkNotDuplication(for userName: String) async -> Bool? { | ||
checkNotDuplicationCalled = true | ||
return await super.checkNotDuplication(for: userName) | ||
} | ||
} | ||
|
||
final class SignUpWorkerSpy: MockSignUpWorker { | ||
var signUpWithKakaoCalled = false | ||
var signUpWithAppleCalled = false | ||
|
||
override func signUp(withKakao token: String, username: String) async -> Bool { | ||
signUpWithKakaoCalled = true | ||
return await super.signUp(withKakao: token, username: username) | ||
} | ||
|
||
override func signUp(withApple identityToken: String, username: String) async -> Bool { | ||
signUpWithAppleCalled = true | ||
return await super.signUp(withApple: identityToken, username: username) | ||
} | ||
} | ||
|
||
// MARK: - Tests | ||
|
||
func test_유효한_닉네임값으로_validateNickname을_호출하면_UserWorker를_통해_닉네임_유효성_검사를_요청하고_valid_결과를_presenter의_presentNicknameValidation를_호출한다() { | ||
// arrange | ||
let presenterSpy = SignUpPresentationLogicSpy() | ||
sut.presenter = presenterSpy | ||
let userWorkerSpy = UserWorkerSpy() | ||
sut.userWorker = userWorkerSpy | ||
|
||
// act | ||
sut.validateNickname(with: Models.ValidateNickname.Request(nickname: "안유진")) | ||
|
||
// assert | ||
XCTAssertTrue(userWorkerSpy.validateNicknameCalled) | ||
XCTAssertTrue(presenterSpy.presentNicknameValidationDidCalled) | ||
XCTAssertNotNil(presenterSpy.presentNicknameValidationResponse.nicknameState) | ||
} | ||
|
||
func test_checkDuplication을_호출하면_UserWorker를_통해_닉네임_중복_검사를_요청하고_결과를_presenter의_presentNicknameDuplication를_호출하여_전달한다() async { | ||
// arrange | ||
let presenterSpy = SignUpPresentationLogicSpy() | ||
sut.presenter = presenterSpy | ||
let userWorkerSpy = UserWorkerSpy() | ||
sut.userWorker = userWorkerSpy | ||
let signUpWorkerSpy = SignUpWorkerSpy() | ||
sut.signUpWorker = signUpWorkerSpy | ||
|
||
// act | ||
await sut.checkDuplication(with: Models.CheckDuplication.Request(nickname: "안유진")) | ||
|
||
// assert | ||
XCTAssertTrue(userWorkerSpy.checkNotDuplicationCalled) | ||
XCTAssertTrue(presenterSpy.presentNicknameDuplicationDidCalled) | ||
XCTAssertNotNil(presenterSpy.presentNicknameDupllicationResponse.isValid) | ||
} | ||
|
||
func test_카카오_signUp을_호출하면_SignUpWorker를_통해_회원가입을_요청하고_presenter의_presentSignUpSuccess를_호출한다() async { | ||
// arrange | ||
let presenterSpy = SignUpPresentationLogicSpy() | ||
sut.presenter = presenterSpy | ||
let signUpWorkerSpy = SignUpWorkerSpy() | ||
signUpWorkerSpy.signUpWithKakaoCalled = true | ||
sut.signUpWorker = signUpWorkerSpy | ||
sut.signUpType = .kakao | ||
sut.socialToken = "1234" | ||
|
||
// act | ||
await sut.signUp(with: Models.SignUp.Request(nickname: "안유진")) | ||
|
||
// assert | ||
XCTAssertTrue(presenterSpy.presentSignUpSuccessDidCalled) | ||
} | ||
|
||
func test_애플_signUp을_호출하면_SignUpWorker를_통해_회원가입을_요청하고_presenter의_presentSignUpSuccess를_호출한다() async { | ||
// arrange | ||
let presenterSpy = SignUpPresentationLogicSpy() | ||
sut.presenter = presenterSpy | ||
let signUpWorkerSpy = SignUpWorkerSpy() | ||
signUpWorkerSpy.signUpWithAppleCalled = true | ||
sut.signUpWorker = signUpWorkerSpy | ||
sut.signUpType = .apple | ||
sut.socialToken = "1234" | ||
|
||
// act | ||
await sut.signUp(with: Models.SignUp.Request(nickname: "안유진")) | ||
|
||
// assert | ||
XCTAssertTrue(presenterSpy.presentSignUpSuccessDidCalled) | ||
} | ||
} |
Oops, something went wrong.