Repository: nbc-team01/team-card-app
Pull request #10: Feature/#9 data setup
Author: login: QuaRang1225
Labels: name: enhancement
description: New feature or request
Created: 2025-03-04T04:37:50Z | Merged: 2025-03-04T08:39:14Z

구현 내용입니다.
### DTO 모델화
- 실제 데이터를 인코딩/디코딩할 DTO로 모델화

### 커스텀 데이터 제작
- 생성한 Model로 PreView나 여러 테스트 환경에서 사용할 수 있도록 커스텀 데이터 제작

### 테스트 코드 제작
- 커스텀 데이터 테스크 코드 작성


Diff:
diff --git a/project-team-card-app/CustomData/CustomData.swift b/project-team-card-app/CustomData/CustomData.swift
new file mode 100644
index 0000000..68932fb
--- /dev/null
+++ b/project-team-card-app/CustomData/CustomData.swift
@@ -0,0 +1,94 @@
+//
+//  CustomData.swift
+//  project-team-card-app
+//
+//  Created by 유영웅 on 3/4/25.
+//
+
+import Foundation
+
+//singleton
+class CustomData{
+    static let shared = CustomData()
+    private init(){}
+    
+    //user data
+    var user:User{
+        let user = """
+        {
+          "userId": "UUID",
+          "name": "John Doe",
+          "MBTI": "INTJ",
+          "nickname": "johnny",
+          "age": 25,
+          "gitHub_path_URL": "https://github.com/johndoe",
+          "blog_path_URL": "https://youtube.com/johndoe",
+          "introduce": "iOS Developer",
+          "contents": [
+            { "title": "Project A", "content": "Description of Project A" },
+            { "title": "Project B", "content": "Description of Project B" }
+          ],
+          "password": "hashed_password",
+          "image_path_URL": "https://example.com/profile.jpg"
+        }
+        """
+        return try! JSONDecoder().decode(User.self, from: user.data(using: .utf8)!)
+    }
+    
+    //user data list
+    var userList:[User]{
+        let user = """
+        [
+            {
+              "userId": "UUID",
+              "name": "John Doe",
+              "MBTI": "INTJ",
+              "nickname": "johnny",
+              "age": 25,
+              "gitHub_path_URL": "https://github.com/johndoe",
+              "blog_path_URL": "https://youtube.com/johndoe",
+              "introduce": "iOS Developer",
+              "contents": [
+                { "title": "Project A", "content": "Description of Project A" },
+                { "title": "Project B", "content": "Description of Project B" }
+              ],
+              "password": "hashed_password",
+              "image_path_URL": "https://example.com/profile.jpg"
+            },
+            {
+              "userId": "UUID1",
+              "name": "John Doe",
+              "MBTI": "INTJ",
+              "nickname": "johnny",
+              "age": 25,
+              "gitHub_path_URL": "https://github.com/johndoe",
+              "blog_path_URL": "https://youtube.com/johndoe",
+              "introduce": "iOS Developer",
+              "contents": [
+                { "title": "Project A", "content": "Description of Project A" },
+                { "title": "Project B", "content": "Description of Project B" }
+              ],
+              "password": "hashed_password",
+              "image_path_URL": "https://example.com/profile.jpg"
+            },
+            {
+              "userId": "UUID2",
+              "name": "John Doe",
+              "MBTI": "INTJ",
+              "nickname": "johnny",
+              "age": 25,
+              "gitHub_path_URL": "https://github.com/johndoe",
+              "blog_path_URL": "https://youtube.com/johndoe",
+              "introduce": "iOS Developer",
+              "contents": [
+                { "title": "Project A", "content": "Description of Project A" },
+                { "title": "Project B", "content": "Description of Project B" }
+              ],
+              "password": "hashed_password",
+              "image_path_URL": "https://example.com/profile.jpg"
+            }
+        ]
+        """
+        return try! JSONDecoder().decode([User].self, from: user.data(using: .utf8)!)
+    }
+}
diff --git a/project-team-card-app/Model/Content.swift b/project-team-card-app/Model/Content.swift
new file mode 100644
index 0000000..6c8b516
--- /dev/null
+++ b/project-team-card-app/Model/Content.swift
@@ -0,0 +1,15 @@
+//
+//  Content.swift
+//  project-team-card-app
+//
+//  Created by 유영웅 on 3/4/25.
+//
+
+import Foundation
+
+//Content of User Data
+//Key - title, Value - content
+//ex - Goals, Merit, TMI
+struct Content: Codable {
+    let title, content: String
+}
diff --git a/project-team-card-app/Model/User.swift b/project-team-card-app/Model/User.swift
new file mode 100644
index 0000000..3d0ed82
--- /dev/null
+++ b/project-team-card-app/Model/User.swift
@@ -0,0 +1,31 @@
+//
+//  User.swift
+//  project-team-card-app
+//
+//  Created by 유영웅 on 3/4/25.
+//
+
+import Foundation
+
+//User Data
+struct User: Codable {
+    let userID, name, mbti, nickname: String
+    let age: Int
+    let gitHubPathURL, blogPathURL: String
+    let introduce: String
+    let contents: [Content]
+    let password: String
+    let imagePathURL: String
+
+    enum CodingKeys: String, CodingKey {
+        case userID = "userId"
+        case name
+        case mbti = "MBTI"
+        case nickname, age
+        case gitHubPathURL = "gitHub_path_URL"
+        case blogPathURL = "blog_path_URL"
+        case introduce, contents, password
+        case imagePathURL = "image_path_URL"
+    }
+}
+
diff --git a/project-team-card-appTests/project_team_card_appTests.swift b/project-team-card-appTests/project_team_card_appTests.swift
index 86959a9..dd1157b 100644
--- a/project-team-card-appTests/project_team_card_appTests.swift
+++ b/project-team-card-appTests/project_team_card_appTests.swift
@@ -13,5 +13,16 @@ struct project_team_card_appTests {
     @Test func example() async throws {
         // Write your test here and use APIs like `#expect(...)` to check expected conditions.
     }
-
+    //user custom data test code..
+    @Test func getUserData() async throws{
+        let user = CustomData.shared.user
+        print("user : \(user)")
+        #expect(user.userID == "UUID")
+    }
+    //user list custom data test code..
+    @Test func getUserListData() async throws{
+        let list = CustomData.shared.userList
+        print("user : \(list[1])")
+        #expect(list[1].userID == "UUID1")
+    }
 }


Reviews:
user: login: seolbotdae
body: 테스팅 방식이 특이하네요
state: APPROVED
author_association: CONTRIBUTOR
submitted_at: 2025-03-04T05:03:23Z
user: login: LeeeeSuHyeon
state: APPROVED
author_association: MEMBER
submitted_at: 2025-03-04T05:06:11Z
user: login: QuaRang1225
state: COMMENTED
author_association: CONTRIBUTOR
submitted_at: 2025-03-04T05:07:51Z
user: login: Sheep1sik
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-03-04T05:38:38Z
user: login: amazingDove367
body: 오 저두 테스트 배워갑니다!!! 👍
state: APPROVED
author_association: COLLABORATOR
submitted_at: 2025-03-04T06:59:02Z

Review comments:
path: project-team-card-appTests/project_team_card_appTests.swift
user: login: LeeeeSuHyeon
body: 오 테스트까지 구현해주셨군요!
created_at: 2025-03-04T05:04:19Z
author_association: MEMBER
path: project-team-card-app/Model/User.swift
user: login: LeeeeSuHyeon
body: contents가 null로 오는 경우가 있을 수도 있을 것 같아서 옵셔널로 선언하는 건 어떨까요??
created_at: 2025-03-04T05:05:53Z
author_association: MEMBER
path: project-team-card-app/Model/User.swift
user: login: QuaRang1225
body: 오 생각해보니 그렇네요! 
혹시 다른 필드로 null로 들어올 경우가 있을까요?
created_at: 2025-03-04T05:07:51Z
author_association: CONTRIBUTOR
path: project-team-card-appTests/project_team_card_appTests.swift
user: login: Sheep1sik
body: 테스트 구현 배워갑니당 !
created_at: 2025-03-04T05:37:02Z
author_association: COLLABORATOR

PR comments:
user: login: QuaRang1225
created_at: 2025-03-04T05:05:19Z
body: > 테스팅 방식이 특이하네요

혹시 어떤 부분에서 그렇게 느끼셨나요??
author_association: CONTRIBUTOR
user: login: seolbotdae
created_at: 2025-03-04T05:08:46Z
body: > > 테스팅 방식이 특이하네요
> 
> 혹시 어떤 부분에서 그렇게 느끼셨나요??
평소에는 XCTest를 사용했었는데, 이게 Swift Testing.. 인가요?

author_association: CONTRIBUTOR
user: login: QuaRang1225
created_at: 2025-03-04T05:15:23Z
body: > > > 테스팅 방식이 특이하네요
> > 
> > 
> > 혹시 어떤 부분에서 그렇게 느끼셨나요??
> > 평소에는 XCTest를 사용했었는데, 이게 Swift Testing.. 인가요?

넵 wwdc 2024에서 새로 추가된 세션입니다.
저는 개인적으로기존 XCTest코드랑 비교해봤을 때 좀 더 깔끔하고, 조건서식 입력이 편하드라고요!
author_association: CONTRIBUTOR