Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: URLProtocol을 이용한 테스트 세팅 #97

Merged
merged 9 commits into from
Nov 26, 2023
Merged

Conversation

anyukyung
Copy link
Member

🧑‍🚀 PR 요약

해당 pr에서 작업한 내역을 적어주세요.

    static func initMockSession(configuration: URLSessionConfiguration = .ephemeral) -> URLSession {
        let configuration = URLSessionConfiguration.default
        configuration.protocolClasses = [MockURLProtocol.self]
        let urlSession = URLSession.init(configuration: configuration)
        return urlSession
    }

  • json MockData를 이용해 SignUpScene에서 중복확인 플로우 구현
  • 아래와 같은 형식으로 사용하면 목데이터로 response를 받을 수 있음
        guard let fileLocation = Bundle.main.url(forResource: "CheckUserName",
                                                 withExtension: "json") else { throw NetworkError.unknown }
        let data = try? Data(contentsOf: fileLocation)

        MockURLProtocol.requestHandler = { request in
            let response = HTTPURLResponse(url: request.url!,
                                           statusCode: 200,
                                           httpVersion: nil,
                                           headerFields: nil)
            return (response, data, nil)
        }

📌 변경 사항

변경사항 및 주의 사항 (모듈 설치 등)을 적어주세요.

N/A

📸 ScreenShot

작동, 구현화면

{
  "customCode": "SUCCESS",
  "message": "요청이 성공적으로 처리되었습니다.",
  "statusCode": 200,
  "data": {
      "exist": false
  }
}

Linked Issue

close #75

@anyukyung anyukyung self-assigned this Nov 25, 2023
@anyukyung anyukyung changed the title test: UIProtocol을 이용한 테스트 세팅 test: URLProtocol을 이용한 테스트 세팅 Nov 25, 2023
Copy link
Collaborator

@loinsir loinsir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오...Dev Log 포스팅 까지 좋은데요👍
사용 예시인 MockUserWorker 까지 작성해주셔서 잘 사용할 수 있겠어요.
찬찬히 공부해서 저도 적용해보겠습니다.
딱히 건드릴 부분이 없어보여서...이 PR은 LGTM 할게요

Copy link
Collaborator

@chopmozzi chopmozzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다~~ Dev Log 꼭 읽어보겠습니다~~

iOS/Layover/Layover/Network/Mock/MockURLProtocol.swift Outdated Show resolved Hide resolved
func modifyNickname(to nickname: String) async throws -> String {
guard let fileLocation = Bundle.main.url(forResource: "PatchUserName",
withExtension: "json") else { throw NetworkError.unknown }
let data = try? Data(contentsOf: fileLocation)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

애 물음표 떼도 괜찮지 않나요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 상관없을 것 같네요 !! 수정하겠습니다

bodyParameters: NicknameDTO(userName: nickname),
headers: headers)
let response = try await provider.request(with: endPoint)
guard let data = response.data else { throw NetworkError.emptyData }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

얘는 위에 데이터랑 다른 친군가요?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • 윗 부분은 URLRequest가 오면 mockdata json을 읽어서 HTTPURLResponse 안에 담아주는 데이터입니다!
  • 밑에는 Provider를 통해 URLRequest를 보내고 받은 Reponse의 data입니다 !
  • 내부적으로는 동일한 데이터이긴 하지만, 흐름이 아예 다릅니다 !!
  • 그런데 저도 보다보니까 네이밍이 살짝 헷갈리네요 이건 좀 고민해보고 수정해볼게요 ㅎㅎ

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

위에 있는 data를 그냥 mockData라고 해줘도 괜찮을 것 같네요 ㅎㅎ

@anyukyung anyukyung merged commit 637f0ae into iOS/dev Nov 26, 2023
1 check passed
@anyukyung anyukyung deleted the iOS/feat#75 branch January 10, 2024 13:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants