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

Update BroadcastReport model

parent 804fa0eb
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!78Update Bindings
...@@ -2,21 +2,25 @@ import Foundation ...@@ -2,21 +2,25 @@ import Foundation
public struct BroadcastReport: Equatable { public struct BroadcastReport: Equatable {
public init( public init(
roundId: Int, rounds: [Int],
ephId: [Int] ephId: [Int],
roundURL: String
) { ) {
self.roundId = roundId self.rounds = rounds
self.ephId = ephId self.ephId = ephId
self.roundURL = roundURL
} }
public var roundId: Int public var rounds: [Int]
public var ephId: [Int] public var ephId: [Int]
public var roundURL: String
} }
extension BroadcastReport: Codable { extension BroadcastReport: Codable {
enum CodingKeys: String, CodingKey { enum CodingKeys: String, CodingKey {
case roundId = "RoundID" case rounds = "Rounds"
case ephId = "EphID" case ephId = "EphID"
case roundURL = "RoundURL"
} }
public static func decode(_ data: Data) throws -> Self { public static func decode(_ data: Data) throws -> Self {
......
...@@ -4,20 +4,23 @@ import XCTest ...@@ -4,20 +4,23 @@ import XCTest
final class BroadcastReportTests: XCTestCase { final class BroadcastReportTests: XCTestCase {
func testCoding() throws { func testCoding() throws {
let roundId: Int = 42 let rounds: [Int] = [25, 26, 29]
let ephId: [Int] = [0, 0, 0, 0, 0, 0, 24, 61] let ephId: [Int] = [0, 0, 0, 0, 0, 0, 24, 61]
let roundURL = "https://dashboard.xx.network/rounds/25?xxmessenger=true"
let jsonString = """ let jsonString = """
{ {
"RoundID": \(roundId), "Rounds": [\(rounds.map { "\($0)" }.joined(separator: ", "))],
"EphID": [\(ephId.map { "\($0)" }.joined(separator: ", "))] "EphID": [\(ephId.map { "\($0)" }.joined(separator: ", "))],
"RoundURL": "\(roundURL)"
} }
""" """
let jsonData = jsonString.data(using: .utf8)! let jsonData = jsonString.data(using: .utf8)!
let model = try BroadcastReport.decode(jsonData) let model = try BroadcastReport.decode(jsonData)
XCTAssertNoDifference(model, BroadcastReport( XCTAssertNoDifference(model, BroadcastReport(
roundId: roundId, rounds: rounds,
ephId: ephId ephId: ephId,
roundURL: roundURL
)) ))
let encodedModel = try model.encode() let encodedModel = try model.encode()
......
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