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

Add SingleUseSendReport model

parent a4046b1b
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!18Update Bindings
import Foundation
public struct SingleUseSendReport: Equatable {
public init(
rounds: [Int],
ephId: EphId
) {
self.rounds = rounds
self.ephId = ephId
}
public var rounds: [Int]
public var ephId: EphId
}
extension SingleUseSendReport {
public struct EphId: Equatable {
public init(
ephId: [Int],
source: Data
) {
self.ephId = ephId
self.source = source
}
public var ephId: [Int]
public var source: Data
}
}
extension SingleUseSendReport: Codable {
enum CodingKeys: String, CodingKey {
case rounds = "Rounds"
case ephId = "EphID"
}
public static func decode(_ data: Data) throws -> Self {
try JSONDecoder().decode(Self.self, from: data)
}
public func encode() throws -> Data {
try JSONEncoder().encode(self)
}
}
extension SingleUseSendReport.EphId: Codable {
enum CodingKeys: String, CodingKey {
case ephId = "EphId"
case source = "Source"
}
}
import CustomDump
import XCTest
@testable import ElixxirDAppsSDK
final class SingleUseSendReportTests: XCTestCase {
func testCoding() throws {
let rounds: [Int] = [1, 5, 9]
let ephId: [Int] = [0, 0, 0, 0, 0, 0, 3, 89]
let ephIdSourceB64 = "emV6aW1hAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD"
let jsonString = """
{
"Rounds": [\(rounds.map { "\($0)" }.joined(separator: ", "))],
"EphID": {
"EphId": [\(ephId.map { "\($0)" }.joined(separator: ", "))],
"Source": "\(ephIdSourceB64)"
}
}
"""
let jsonData = jsonString.data(using: .utf8)!
let report = try SingleUseSendReport.decode(jsonData)
XCTAssertNoDifference(report, SingleUseSendReport(
rounds: rounds,
ephId: .init(
ephId: ephId,
source: Data(base64Encoded: ephIdSourceB64)!
)
))
let encodedReport = try report.encode()
let decodedReport = try SingleUseSendReport.decode(encodedReport)
XCTAssertNoDifference(decodedReport, report)
}
}
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