diff --git a/Sources/ElixxirDAppsSDK/Models/GroupSendReport.swift b/Sources/ElixxirDAppsSDK/Models/GroupSendReport.swift new file mode 100644 index 0000000000000000000000000000000000000000..c7b3b01d5da48cc518773572c95bdd76213544ab --- /dev/null +++ b/Sources/ElixxirDAppsSDK/Models/GroupSendReport.swift @@ -0,0 +1,33 @@ +import Foundation + +public struct GroupSendReport: Equatable { + public init( + roundId: UInt64, + timestamp: Int64, + messageId: Data + ) { + self.roundId = roundId + self.timestamp = timestamp + self.messageId = messageId + } + + public var roundId: UInt64 + public var timestamp: Int64 + public var messageId: Data +} + +extension GroupSendReport: Codable { + enum CodingKeys: String, CodingKey { + case roundId = "RoundID" + case timestamp = "Timestamp" + case messageId = "MessageID" + } + + 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/GroupSendReportTests.swift b/Tests/ElixxirDAppsSDKTests/Models/GroupSendReportTests.swift new file mode 100644 index 0000000000000000000000000000000000000000..8d99647c9432d5ff88ddc57738ebab00d48db9d3 --- /dev/null +++ b/Tests/ElixxirDAppsSDKTests/Models/GroupSendReportTests.swift @@ -0,0 +1,31 @@ +import CustomDump +import XCTest +@testable import ElixxirDAppsSDK + +final class GroupSendReportTests: XCTestCase { + func testCoding() throws { + let roundId: UInt64 = 123 + let timestamp: Int64 = 321 + let messageIdB64 = "EB/70R5HYEw5htZ4Hg9ondrn3+cAc/lH2G0mjQMja3w=" + let jsonString = """ + { + "RoundID": \(roundId), + "Timestamp": \(timestamp), + "MessageID": "\(messageIdB64)" + } + """ + let jsonData = jsonString.data(using: .utf8)! + let model = try GroupSendReport.decode(jsonData) + + XCTAssertNoDifference(model, GroupSendReport( + roundId: roundId, + timestamp: timestamp, + messageId: Data(base64Encoded: messageIdB64)! + )) + + let encodedModel = try model.encode() + let decodedModel = try GroupSendReport.decode(encodedModel) + + XCTAssertNoDifference(decodedModel, model) + } +}