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

Add NotificationReport model

parent a0cd9910
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!56Update Bindings
import Foundation
public struct NotificationReport: Equatable {
public enum ReportType: String, Equatable {
case `default`
case request
case reset
case confirm
case silent
case e2e
case group
case endFT
case groupRQ
}
public init(
forMe: Bool,
type: NotificationReport.ReportType,
source: Data
) {
self.forMe = forMe
self.type = type
self.source = source
}
public var forMe: Bool
public var type: ReportType
public var source: Data
}
extension NotificationReport.ReportType: Codable {}
extension NotificationReport: Codable {
enum CodingKeys: String, CodingKey {
case forMe = "ForMe"
case type = "Type"
case source = "Source"
}
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 XXClient
final class NotificationReportTests: XCTestCase {
func testCoding() throws {
let forMe = true
let type = NotificationReport.ReportType.default
let sourceB64 = "dGVzdGVyMTIzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
let jsonString = """
{
"ForMe": true,
"Type": "\(type.rawValue)",
"Source": "\(sourceB64)"
}
"""
let jsonData = jsonString.data(using: .utf8)!
let model = try NotificationReport.decode(jsonData)
XCTAssertNoDifference(model, NotificationReport(
forMe: forMe,
type: type,
source: Data(base64Encoded: sourceB64)!
))
let encodedModel = try model.encode()
let decodedModel = try NotificationReport.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