Skip to content
Snippets Groups Projects
Commit d98e0fa0 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Add GroupReport model

parent d83acfea
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!24Update Bindings
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)
}
}
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)
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment