diff --git a/Sources/XXClient/Models/IsReadyInfo.swift b/Sources/XXClient/Models/IsReadyInfo.swift new file mode 100644 index 0000000000000000000000000000000000000000..916f37df7efdc020cc04909324031915f672e8d9 --- /dev/null +++ b/Sources/XXClient/Models/IsReadyInfo.swift @@ -0,0 +1,26 @@ +import Foundation + +public struct IsReadyInfo: Equatable { + public init(isReady: Bool, howClose: Double) { + self.isReady = isReady + self.howClose = howClose + } + + public var isReady: Bool + public var howClose: Double +} + +extension IsReadyInfo: Codable { + enum CodingKeys: String, CodingKey { + case isReady = "IsReady" + case howClose = "HowClose" + } + + public static func decode(_ data: Data) throws -> Self { + try JSONDecoder().decode(Self.self, from: data) + } + + public func encode() throws -> Data { + try JSONEncoder().encode(self) + } +} diff --git a/Tests/XXClientTests/Models/IsReadyInfoTests.swift b/Tests/XXClientTests/Models/IsReadyInfoTests.swift new file mode 100644 index 0000000000000000000000000000000000000000..9db31131ddf11b895b1bac13424a956ff9c28571 --- /dev/null +++ b/Tests/XXClientTests/Models/IsReadyInfoTests.swift @@ -0,0 +1,26 @@ +import CustomDump +import XCTest +@testable import XXClient + +final class IsReadyInfoTests: XCTestCase { + func testCoding() throws { + let jsonString = """ + { + "IsReady": true, + "HowClose": 0.534 + } + """ + let jsonData = jsonString.data(using: .utf8)! + let model = try IsReadyInfo.decode(jsonData) + + XCTAssertNoDifference(model, IsReadyInfo( + isReady: true, + howClose: 0.534 + )) + + let encodedModel = try model.encode() + let decodedModel = try IsReadyInfo.decode(encodedModel) + + XCTAssertNoDifference(decodedModel, model) + } +}