Skip to content

Commit

Permalink
✨[feat]: DTO 모델 변환 중 #14
Browse files Browse the repository at this point in the history
* question 질문  관련 쪽  작업  중
  • Loading branch information
Roy-wonji committed Nov 11, 2024
1 parent 04fa939 commit b8d6a72
Show file tree
Hide file tree
Showing 46 changed files with 1,748 additions and 1,623 deletions.
84 changes: 41 additions & 43 deletions OPeace/Projects/App/OpeaceTests/Sources/ProfileTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,51 +18,49 @@ import Utills

@MainActor
struct ProfileTest {
let store = TestStore(initialState: Profile.State()) {
Profile()
} withDependencies: {
let repository = AuthRepository()
$0.authUseCase = AuthUseCase(repository: repository)
let store = TestStore(initialState: Profile.State()) {
Profile()
} withDependencies: {
let repository = AuthRepository()
$0.authUseCase = AuthUseCase(repository: repository)
}

@Test("유저 정보 조회")
func testUserInfo_유저정보_조회() async throws {
var mockUpdateUserInfo = UpdateUserInfoDTOModel.mockModel

await store.send(.async(.fetchUserProfileResponse(.success(mockUpdateUserInfo)))) { state in
state.profileUserModel = mockUpdateUserInfo
}

@Test("유저 정보 조회")
func testUserInfo_유저정보_조회() async throws {
var mockUpdateUserInfo = UpdateUserInfoModel.mockModel

await store.send(.async(.fetchUserProfileResponse(.success(mockUpdateUserInfo)))) { state in
state.profileUserModel = mockUpdateUserInfo
}

await store.send(.async(.fetchUser))

store.assert { state in
state.profileUserModel = mockUpdateUserInfo
}

let mockError = CustomError.unknownError("Failed to fetch user info")


await store.send(.async(.fetchUserProfileResponse(.failure(mockError)))) {
XCTAssertNil($0.profileUserModel)
}



await store.finish()
store.exhaustivity = .off

await store.send(.async(.fetchUser))

store.assert { state in
state.profileUserModel = mockUpdateUserInfo
}

@Test("유저 정보 업데이트")
func testUserInfo_유저정보_업데이트() async throws {
let testEditStore = TestStore(initialState: EditProfile.State()) {
EditProfile()
} withDependencies: {
let repository = AuthRepository()
$0.authUseCase = AuthUseCase(repository: repository)
let signupRepository = SingUpRepository()
$0.signUpUseCase = SignUpUseCase(repository: signupRepository)
}

await testEditStore.send(.async(.updateUserInfo(nickName: "로이", year: 1998, job: "개발", generation: "Z 세대")))
let mockError = CustomError.unknownError("Failed to fetch user info")


await store.send(.async(.fetchUserProfileResponse(.failure(mockError)))) {
XCTAssertNil($0.profileUserModel)
}

await store.finish()
store.exhaustivity = .off
}

@Test("유저 정보 업데이트")
func testUserInfo_유저정보_업데이트() async throws {
let testEditStore = TestStore(initialState: EditProfile.State()) {
EditProfile()
} withDependencies: {
let repository = AuthRepository()
$0.authUseCase = AuthUseCase(repository: repository)
let signupRepository = SingUpRepository()
$0.signUpUseCase = SignUpUseCase(repository: signupRepository)
}

await testEditStore.send(.async(.updateUserInfo(nickName: "로이", year: 1998, job: "개발", generation: "Z 세대")))
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// FlagQuestionDTOModel.swift
// Model
//
// Created by Wonji Suh on 11/11/24.
//

import Foundation

public struct FlagQuestionDTOModel: Codable, Equatable {
public let data: FlagQuestionResponseDTOModel

public init(data: FlagQuestionResponseDTOModel) {
self.data = data
}
}

public struct FlagQuestionResponseDTOModel: Codable, Equatable {
public let id, question: Int
public let userID, reason, createAt: String
public let status: Bool
public let message: String

public init(
id: Int = .zero,
question: Int = .zero,
userID: String = "",
reason: String = "",
createAt: String = "",
status: Bool = false,
message: String = ""
) {
self.id = id
self.question = question
self.userID = userID
self.reason = reason
self.createAt = createAt
self.status = status
self.message = message
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Extension+DeleteQuestionModel.swift
// Model
//
// Created by Wonji Suh on 11/11/24.
//

public extension DeleteQuestionModel {
func toFlagQuestionDTOToModel() -> FlagQuestionDTOModel {
let data: FlagQuestionResponseDTOModel = .init(
status: self.data?.status ?? false,
message: self.data?.message ?? ""
)

return FlagQuestionDTOModel(data: data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Extension+ReportQuestionModel.swift
// Model
//
// Created by Wonji Suh on 11/11/24.
//

import Foundation

public extension ReportQuestionModel {
func toFlagQuestionDTOToModel() -> FlagQuestionDTOModel {
let data: FlagQuestionResponseDTOModel = .init(
id: self.data?.id ?? .zero,
question: self.data?.question ?? .zero,
userID: self.data?.userID ?? "",
reason: self.data?.reason ?? "",
createAt: self.data?.createAt ?? ""
)

return FlagQuestionDTOModel(data: data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// Extension+VoteQuestionLikeModel.swift
// Model
//
// Created by Wonji Suh on 11/11/24.
//

import Foundation

public extension VoteQuestionLikeModel {
func toFlagQuestionDTOToModel() -> FlagQuestionDTOModel {
let data: FlagQuestionResponseDTOModel = .init(
question: self.data?.question ?? .zero,
userID: self.data?.userID ?? "",
createAt: self.data?.createAt ?? ""
)

return FlagQuestionDTOModel(data: data)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// DeleteQuestionModel.swift
// Model
//
// Created by 서원지 on 8/26/24.
//

import Foundation

public struct DeleteQuestionModel: Decodable {
let data: DeleteQuestionResponseModel?

}

// MARK: - DataClass
struct DeleteQuestionResponseModel: Decodable {
let status: Bool?
let message: String?

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
//
// ReportQuestion.swift
// Model
//
// Created by 서원지 on 8/26/24.
//

import Foundation
// MARK: - Welcome
public struct ReportQuestionModel: Decodable {
let data: ReportQuestionResponseModel?

}

// MARK: - DataClass
struct ReportQuestionResponseModel: Decodable {
let id, question: Int?
let userID, reason, createAt: String?

enum CodingKeys: String, CodingKey {
case id, question
case userID = "user_id"
case reason
case createAt = "create_at"
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by 서원지 on 8/25/24.
//

import Foundation

public struct VoteQuestionLikeModel: Codable, Equatable {
public let data: VoteQuestionLikeResponse?

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Extension+UpdateUserInfoDTOModel.swift
// Model
//
// Created by Wonji Suh on 11/11/24.
//

public extension UpdateUserInfoModel {
func toUpdateUserInfoDTOToModel() -> UpdateUserInfoDTOModel {
let data: UpdateUserInfoResponseDTOModel = .init(
socialID: self.data?.socialID ?? "",
socialType: self.data?.socialType ?? "",
email: self.data?.email ?? "",
createdAt: self.data?.createdAt ?? "",
nickname: self.data?.nickname,
year: self.data?.year ,
job: self.data?.job,
generation: self.data?.generation ?? "",
isFirstLogin: self.data?.isFirstLogin ?? false
)

return UpdateUserInfoDTOModel(data: data)
}
}

public extension UpdateUserInfoDTOModel {
static var mockModel: UpdateUserInfoDTOModel = UpdateUserInfoDTOModel(
data: UpdateUserInfoResponseDTOModel(
socialID: "apple_001096.cf7680b2761f4de694a1d1c21ea507a6.1112",
socialType: "apple",
email: "[email protected]",
createdAt: "2024-08-29 01:39:57",
nickname: "오피스",
year: 1998,
job: "개발",
generation: "Z 세대",
isFirstLogin: true
)
)
}
Loading

0 comments on commit b8d6a72

Please sign in to comment.