Skip to content

Commit

Permalink
[Feat/#94] Challenge TestCode 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
HELLOHIDI committed Oct 31, 2024
1 parent 17e5cd6 commit 15882e2
Show file tree
Hide file tree
Showing 12 changed files with 296 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BASE_URL</key>
<string>$(BASE_URL)</string>
<key>CFBundleDevelopmentRegion</key>
<string>$(DEVELOPMENT_LANGUAGE)</string>
<key>CFBundleExecutable</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public struct AddAppRequest: Encodable {
}
}

struct AddAppResult: Decodable {
public struct AddAppResult: Decodable {
let apps: [AppInfoDTO]
}

public extension AddAppRequest {
static var stub: Self {
.init(apps: [.stub,.stub,.stub,.stub])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ public struct CreateChallengeRequest: Encodable {
self.goalTime = goalTime
}
}

public extension CreateChallengeRequest {
static var stub: Self {
.init(period: 1, goalTime: 1)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,9 @@ public struct DeleteAppRequest: Encodable {
self.appCode = appCode
}
}

public extension DeleteAppRequest {
static var stub: Self {
.init(appCode: "######")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import Foundation

enum ChallengeAPI {
public enum ChallengeAPI {
case getdailyChallenge
case getSuccesChallenge
case createChallenge(request: CreateChallengeRequest)
Expand All @@ -20,11 +20,11 @@ enum ChallengeAPI {
}

extension ChallengeAPI: BaseAPI {
var isWithInterceptor: Bool {
public var isWithInterceptor: Bool {
return true
}

var path: String? {
public var path: String? {
switch self {
case .getdailyChallenge:
return Paths.getChallenge
Expand All @@ -45,7 +45,7 @@ extension ChallengeAPI: BaseAPI {
}
}

var method: HTTPMethod {
public var method: HTTPMethod {
switch self {
case .getdailyChallenge:
return .get
Expand All @@ -66,7 +66,7 @@ extension ChallengeAPI: BaseAPI {
}
}

var task: Task {
public var task: Task {
switch self {
case .getdailyChallenge:
return .requestPlain
Expand All @@ -87,7 +87,7 @@ extension ChallengeAPI: BaseAPI {
}
}

var headers: [String : String]? {
public var headers: [String : String]? {
switch self {
case .getdailyChallenge:
return APIHeaders.hasTokenWithTimeZoneHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import Foundation
import Combine

typealias ChallengeService = BaseService<ChallengeAPI>
public typealias ChallengeService = BaseService<ChallengeAPI>

public protocol ChallengeServiceType {
func getdailyChallenge() -> AnyPublisher<GetChallengeResult, HMHNetworkError>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import Foundation

import Domain

enum UserAPI {
public enum UserAPI {
case logout
case deleteAccount
case getUserData
case getCurrentPoint
}

extension UserAPI: BaseAPI {
var isWithInterceptor: Bool {
public var isWithInterceptor: Bool {
return false
}

var path: String? {
public var path: String? {
switch self {
case .logout:
return Paths.logout
Expand All @@ -35,7 +35,7 @@ extension UserAPI: BaseAPI {
}
}

var method: HTTPMethod {
public var method: HTTPMethod {
switch self {
case .logout:
return .post
Expand All @@ -48,7 +48,7 @@ extension UserAPI: BaseAPI {
}
}

var task: Task {
public var task: Task {
switch self {
case .logout:
return .requestPlain
Expand All @@ -61,7 +61,7 @@ extension UserAPI: BaseAPI {
}
}

var headers: [String : String]? {
public var headers: [String : String]? {
return APIHeaders.hasTokenHeader
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import Combine

import Core

typealias UserService = BaseService<UserAPI>
public typealias UserService = BaseService<UserAPI>

public protocol UserServiceType {
func logout() -> AnyPublisher<Void, HMHNetworkError>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,6 @@
// Copyright © 2024 HMH-iOS. All rights reserved.
//

//
// PointServiceTests.swift
// NetworksTests
//
// Created by 류희재 on 10/30/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import XCTest
import Combine

Expand Down Expand Up @@ -61,7 +53,7 @@ final class AuthServiceTests: XCTestCase {

let expectation = XCTestExpectation()

sut.socialLogin(request: SocialLoginRequest(socialPlatform: "iOS"))
sut.socialLogin(request: SocialLoginRequest(socialPlatform: "APPLE"))
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
//
// ChallengeServiceTests.swift
// NetworksTests
//
// Created by 류희재 on 10/31/24.
// Copyright © 2024 HMH-iOS. All rights reserved.
//

import XCTest
import Combine

import Networks
import Core

final class ChallengeServiceTests: XCTestCase {

var sut: ChallengeServiceType!
var mockRequestHandler: RequestHandling!
var cancelBag: CancelBag!

override func setUp() {
cancelBag = CancelBag()
mockRequestHandler = RequestHandler()
sut = ChallengeService(requestHandler: mockRequestHandler)

UserManager.shared.accessToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNzMwMjcyMDkyLCJleHAiOjE3MzA0NDQ4OTJ9.FULSF-b-cu4iH25ld_EgL99g310XT1uTHcyyebBgxxpYERXXk19Mb-TyfaeDEWUMpkC6vjrjWz5yPc27fPbPTQ"
UserManager.shared.refreshToken = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNzMwMjcyMDkyLCJleHAiOjE3MzE0ODE2OTJ9.9SrHLvCCbFVt_p6GZvh0P91CgLSZfH3VgFDH2HZHiVHXdjC0O_4OUiv9wZI4Hmf3BwSer8awR8ilOTsKIODS6A"
}

override func tearDown() {
cancelBag = nil
mockRequestHandler = nil
sut = nil
}

func test_홈이용시간통계불러오기_서버통신이_정상적으로_진행되는가() {

let expectation = XCTestExpectation()

sut.getdailyChallenge()
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
expectation.fulfill()
}
.store(in: cancelBag)

wait(for: [expectation], timeout: 10.0)

}

func test_챌린지성공여부리스트전송_서버통신이_정상적으로_진행되는가() {

let expectation = XCTestExpectation()

sut.getSuccesChallenge()
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
expectation.fulfill()
}
.store(in: cancelBag)

wait(for: [expectation], timeout: 10.0)

}

func test_챌린지생성_서버통신이_정상적으로_진행되는가() {

let expectation = XCTestExpectation()

sut.createChallenge(request: .stub)
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
expectation.fulfill()
}
.store(in: cancelBag)

wait(for: [expectation], timeout: 10.0)

}

func test_당일잠금여부확인_서버통신이_정상적으로_진행되는가() {

let expectation = XCTestExpectation()

sut.getLockChallenge()
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
expectation.fulfill()
}
.store(in: cancelBag)

wait(for: [expectation], timeout: 10.0)

}

func test_당일잠금여부전송_서버통신이_정상적으로_진행되는가() {

let expectation = XCTestExpectation()

sut.postLockChallenge()
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
expectation.fulfill()
}
.store(in: cancelBag)

wait(for: [expectation], timeout: 10.0)

}

func test_스크린타임설정한앱삭제_서버통신이_정상적으로_진행되는가() {

let expectation = XCTestExpectation()

sut.deleteApp(request: .stub)
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
expectation.fulfill()
}
.store(in: cancelBag)

wait(for: [expectation], timeout: 10.0)

}

func test_달성현황정보불러오기_서버통신이_정상적으로_진행되는가() {

let expectation = XCTestExpectation()

sut.getChallenge()
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
expectation.fulfill()
}
.store(in: cancelBag)

wait(for: [expectation], timeout: 10.0)

}

func test_스크린타임설정할앱추가_서버통신이_정상적으로_진행되는가() {

let expectation = XCTestExpectation()

sut.addApp(request: .stub)
.sink { completion in
if case let .failure(err) = completion { XCTFail(err.localizedDescription)}
} receiveValue: { roomDetails in
expectation.fulfill()
}
.store(in: cancelBag)

wait(for: [expectation], timeout: 10.0)

}
}
Loading

0 comments on commit 15882e2

Please sign in to comment.