Skip to content

Commit

Permalink
[MERGE] Challenge Unit test code 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
kimscastle authored Dec 3, 2023
2 parents 9876065 + 070f0be commit cf035e2
Show file tree
Hide file tree
Showing 21 changed files with 643 additions and 169 deletions.
167 changes: 88 additions & 79 deletions LionHeart-iOS/LionHeart-iOS.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES"
shouldAutocreateTestPlan = "YES">
shouldUseLaunchSchemeArgsEnv = "YES">
<TestPlans>
<TestPlanReference
reference = "container:LionHeart-iOS.xctestplan"
default = "YES">
</TestPlanReference>
</TestPlans>
<Testables>
<TestableReference
skipped = "NO"
Expand All @@ -41,7 +46,7 @@
</BuildableReference>
</TestableReference>
<TestableReference
skipped = "NO"
skipped = "YES"
parallelizable = "YES">
<BuildableReference
BuildableIdentifier = "primary"
Expand Down
37 changes: 37 additions & 0 deletions LionHeart-iOS/LionHeart-iOS.xctestplan
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"configurations" : [
{
"id" : "B451EF4F-252F-4B7B-989D-F08BEE407A4A",
"name" : "Test Scheme Action",
"options" : {

}
}
],
"defaultOptions" : {
"targetForVariableExpansion" : {
"containerPath" : "container:LionHeart-iOS.xcodeproj",
"identifier" : "B532E82D2A5525C600F0DB19",
"name" : "LionHeart-iOS"
}
},
"testTargets" : [
{
"target" : {
"containerPath" : "container:LionHeart-iOS.xcodeproj",
"identifier" : "B532E8432A5525C800F0DB19",
"name" : "LionHeart-iOSTests"
}
},
{
"enabled" : false,
"parallelizable" : true,
"target" : {
"containerPath" : "container:LionHeart-iOS.xcodeproj",
"identifier" : "B532E84D2A5525C800F0DB19",
"name" : "LionHeart-iOSUITests"
}
}
],
"version" : 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation

@frozen
enum NetworkError: Error, CustomStringConvertible {
enum NetworkError: Error, CustomStringConvertible, Equatable {
case urlEncodingError
case jsonDecodingError
case badCasting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class ChallengeDayCheckCollectionViewCollectionViewCell: UICollectionViewC

enum ChallengeCellType { case read, yet }

private let countLabel = LHLabel(type: .body2M, color: .gray700, alignment: .center)
let countLabel = LHLabel(type: .body2M, color: .gray700, alignment: .center)
private let lineView = LHUnderLine(lineColor: .gray900)

override init(frame: CGRect) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import UIKit

struct ChallengeData: AppData {
struct ChallengeData: AppData, Equatable {
let babyDaddyName: String
let howLongDay: Int
let daddyLevel: String
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ final class ChallengeViewController: UIViewController, ChallengeViewControllerab

private let leftSeperateLine = LHUnderLine(lineColor: .background)
private let rightSeperateLine = LHUnderLine(lineColor: .background)
private lazy var navigationBar = LHNavigationBarView(type: .challenge, viewController: self)
private let nicknameLabel = LHLabel(type: .body2R, color: .gray200)
private let challengeDayLabel = LHLabel(type: .head3, color: .white)
private let challengelevelLabel = LHLabel(type: .body4, color: .gray500)
private let levelBadge = LHImageView(in: ImageLiterals.ChallengeBadge.level05, contentMode: .scaleToFill)
lazy var navigationBar = LHNavigationBarView(type: .challenge, viewController: self)
let nicknameLabel = LHLabel(type: .body2R, color: .gray200)
let challengeDayLabel = LHLabel(type: .head3, color: .white)
let challengelevelLabel = LHLabel(type: .body4, color: .gray500)
let levelBadge = LHImageView(in: ImageLiterals.ChallengeBadge.level05, contentMode: .scaleToFill)
private lazy var lottieImageView = LHLottie()
private let challengeDayCheckCollectionView = LHCollectionView()
let challengeDayCheckCollectionView = LHCollectionView()
private var diffableDataSource: UICollectionViewDiffableDataSource<ChallengeSection, Int>!

init(viewModel: some ChallengeViewModel) {
Expand Down Expand Up @@ -80,7 +80,7 @@ final class ChallengeViewController: UIViewController, ChallengeViewControllerab
}
}

private extension ChallengeViewController {
extension ChallengeViewController {
func configureData(_ input: ChallengeData) {
setText(by: input)
setImage(by: input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import Combine

final class ChallengeViewModelImpl: ChallengeViewModel, ChallengeViewModelPresentable {

private enum FlowType { case bookmarkButtonTapped, myPageButtonTapped }
enum FlowType { case bookmarkButtonTapped, myPageButtonTapped }

private let navigationSubject = PassthroughSubject<FlowType, Never>()
var navigationSubject = PassthroughSubject<FlowType, Never>()
private var cancelBag = Set<AnyCancellable>()
private let errorSubject = PassthroughSubject<NetworkError, Never>()
let errorSubject = PassthroughSubject<NetworkError, Never>()

private var navigator: ChallengeNavigation
private var manager: ChallengeManager
Expand Down Expand Up @@ -44,11 +44,15 @@ final class ChallengeViewModelImpl: ChallengeViewModel, ChallengeViewModelPresen
.store(in: &cancelBag)

input.navigationLeftButtonTapped
.sink { [weak self] in self?.navigationSubject.send(.bookmarkButtonTapped) }
.sink { [weak self] in
self?.navigationSubject.send(.bookmarkButtonTapped)
}
.store(in: &cancelBag)

input.navigationRightButtonTapped
.sink { [weak self] in self?.navigationSubject.send(.myPageButtonTapped) }
.sink {
[weak self] in self?.navigationSubject.send(.myPageButtonTapped)
}
.store(in: &cancelBag)

let viewWillAppearSubject = input.viewWillAppearSubject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ final class CurriculumListWeekViewController: UIViewController, CurriculumArticl

private lazy var navigationBar = LHNavigationBarView(type: .curriculumByWeek, viewController: self)
private var datasoruce: UITableViewDiffableDataSource<CurriculumListWeekSection, CurriculumListWeekItem>!
private lazy var headerView = CurriculumArticleByWeekHeaderView(frame: .init(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.width*(200 / 375)))
private lazy var headerView =
CurriculumArticleByWeekHeaderView(frame: .init(x: 0, y: 0, width: view.frame.size.width, height: view.frame.size.width*(200 / 375)))

private let curriculumListByWeekTableView = CurriculumListByWeekTableView()

private let viewModel: any CurriculumListWeekViewModel
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"code": "N004",
"message": "클라이언트에러"
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"code": "I001",
"message": "서버에러가발생했습니다"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"code": "SUCCESS",
"message": "정보조회에성공했습니다",
"data": {
"babyNickname": "Test닉네임",
"day": 10,
"level": "LEVEL_ONE",
"attendances": [
"11/1",
"11/2",
"11/3"
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//
// ChallengeServiceTests.swift
// LionHeart-iOSTests
//
// Created by 김의성 on 12/01/23.
//

import XCTest
@testable import LionHeart_iOS

final class ChallengeServiceTests: XCTestCase {

var apiService: Requestable!
var urlSession: URLSessionStub!
var jsonLoader: JSONLoader!
var url: URL!

override func setUpWithError() throws {
self.jsonLoader = JSONLoader()
}

override func tearDownWithError() throws {
self.jsonLoader = nil
self.url = nil
}

func test_챌린지API_호출을_성공했을때() async throws {
//given
let urlRequest = try self.setChallengeAPITest(fileName: "ChallengeSuccess")

//when
let returnData: ChallengeDataResponse? = try await self.apiService.request(urlRequest)
let result = try XCTUnwrap(returnData, "언래핑실패")

//then
let expectation = ChallengeDataResponse(babyNickname: "Test닉네임", day: 10, level: "LEVEL_ONE", attendances: ["11/1","11/2","11/3"])
XCTAssertEqual(result.babyNickname, expectation.babyNickname)
XCTAssertEqual(result.day, expectation.day)
XCTAssertEqual(result.attendances, expectation.attendances)
}

func test_챌린지API_호출했을때_서버에러가발생한경우() async throws {
//given
let urlRequest = try self.setChallengeAPITest(fileName: "ChallengeFailure_Server")

//when
var willOccureError: NetworkError?
do {
let _: ChallengeDataResponse? = try await self.apiService.request(urlRequest)
XCTFail("성공할수없는 case입니다")
} catch {
let error = error as? NetworkError
willOccureError = error
}

//then
let expectation = NetworkError.serverError
XCTAssertEqual(willOccureError, expectation)
}

func test_챌린지API_호출했을때_존재하지않는_챌린지인경우() async throws {
//given
let urlRequest = try self.setChallengeAPITest(fileName: "ChallengeFailure_Client")

//when
var willOccureError: NetworkError?
do {
let _: ChallengeDataResponse? = try await self.apiService.request(urlRequest)
XCTFail("성공할수없는 case입니다")
} catch {
let error = error as? NetworkError
willOccureError = error
}

//then
let expectation = NetworkError.clientError(code: "N004", message: "클라이언트에러")
XCTAssertEqual(willOccureError, expectation)
}
}

private extension ChallengeServiceTests {
func setChallengeAPITest(fileName: String) throws -> URLRequest {
self.url = jsonLoader.load(fileName: fileName)
let data = try Data(contentsOf: self.url)
let urlRequest = URLRequest(url: self.url)
self.urlSession = URLSessionStub(data: data)
self.apiService = APIService(session: urlSession)
return urlRequest
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//
// ChallengeManagerStub.swift
// LionHeart-iOSTests
//
// Created by uiskim on 2023/12/01.
//

import Foundation
@testable import LionHeart_iOS

final class ChallengeManagerStub: ChallengeManager {
var returnValue: ChallengeDataResponse?

func inquireChallengeInfo() async throws -> LionHeart_iOS.ChallengeData {
guard let returnValue else { throw NetworkError.badCasting }
return returnValue.toAppData()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// ChallengeNavigationStub.swift
// LionHeart-iOSTests
//
// Created by uiskim on 2023/12/01.
//

import Foundation
@testable import LionHeart_iOS

final class ChallengeNavigationDummy: ChallengeNavigation {

func navigationRightButtonTapped() {
print("왼쪽버튼눌림")
}

func navigationLeftButtonTapped() {
print("오른쪽버튼눌림")
}

func checkTokenIsExpired() {
print("앱강제종료")
}
}
Loading

0 comments on commit cf035e2

Please sign in to comment.