Skip to content

Commit

Permalink
[Feat] #466 - ChangeSocialEntity 구현 및 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
meltsplit committed Dec 27, 2024
1 parent 8cbe844 commit c0d5d46
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//
// SocialAPI.swift
// Networks
//
// Created by 장석우 on 12/28/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import Foundation
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// ChangeSocialAccountEntity.swift
// Networks
//
// Created by 장석우 on 12/28/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import Foundation

struct ChangeSocialAccountEntity: Encodable {
let phone: String
let authPlatform: SocialAccountType
let code: String


enum CodingKeys: CodingKey {
case phone
case authPlatform
case code
}

func encode(to encoder: any Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(self.phone, forKey: .phone)
try container.encode(self.authPlatform.rawValue, forKey: .authPlatform)
try container.encode(self.code, forKey: .code)
}

}

enum SocialAccountType: String, Encodable {
case google = "GOOGLE"
case apple = "APPLE"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// SocialEntityTests.swift
// NetworksTests
//
// Created by 장석우 on 12/28/24.
// Copyright © 2024 SOPT-iOS. All rights reserved.
//

import XCTest
@testable import Networks

final class SocialEntityTests: XCTestCase {

override func setUp() {
}

override func tearDown() {
}

func test_changeSocialEntity의_authPlatform가_enum의_RAW값으로_encode되는가() throws {

// given
let encoder = JSONEncoder()
let entity = ChangeSocialAccountEntity(phone: "", authPlatform: .apple, code: "")

// when
let data = try encoder.encode(entity)
let jsonString = String(data: data, encoding: .utf8)

//then
XCTAssertTrue(jsonString!.contains("\"authPlatform\":\"APPLE\""), "authPlatform 값이 올바르게 인코딩되지 않았습니다.")

}


}

0 comments on commit c0d5d46

Please sign in to comment.