diff --git a/Sources/ElixxirDAppsSDK/Models/GroupReport.swift b/Sources/ElixxirDAppsSDK/Models/GroupReport.swift new file mode 100644 index 0000000000000000000000000000000000000000..0407507dfe034255822b07f78eaf9310dff3975b --- /dev/null +++ b/Sources/ElixxirDAppsSDK/Models/GroupReport.swift @@ -0,0 +1,33 @@ +import Foundation + +public struct GroupReport: Equatable { + public init( + id: Data, + rounds: [Int], + status: Int + ) { + self.id = id + self.rounds = rounds + self.status = status + } + + public var id: Data + public var rounds: [Int] + public var status: Int +} + +extension GroupReport: Codable { + enum CodingKeys: String, CodingKey { + case id = "Id" + case rounds = "Rounds" + case status = "Status" + } + + 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/ElixxirDAppsSDKTests/Models/GroupReportTests.swift b/Tests/ElixxirDAppsSDKTests/Models/GroupReportTests.swift new file mode 100644 index 0000000000000000000000000000000000000000..d89542e7fc7ed3e8b00d8f3c4a740b37d815aed0 --- /dev/null +++ b/Tests/ElixxirDAppsSDKTests/Models/GroupReportTests.swift @@ -0,0 +1,31 @@ +import CustomDump +import XCTest +@testable import ElixxirDAppsSDK + +final class GroupReportTests: XCTestCase { + func testCoding() throws { + let idB64 = "EB/70R5HYEw5htZ4Hg9ondrn3+cAc/lH2G0mjQMja3w=" + let rounds: [Int] = [1, 5, 9] + let status: Int = 123 + let jsonString = """ + { + "Id": "\(idB64)", + "Rounds": [\(rounds.map { "\($0)" }.joined(separator: ", "))], + "Status": \(status) + } + """ + let jsonData = jsonString.data(using: .utf8)! + let model = try GroupReport.decode(jsonData) + + XCTAssertNoDifference(model, GroupReport( + id: Data(base64Encoded: idB64)!, + rounds: rounds, + status: status + )) + + let encodedModel = try model.encode() + let decodedModel = try GroupReport.decode(encodedModel) + + XCTAssertNoDifference(decodedModel, model) + } +}