diff --git a/Sources/ElixxirDAppsSDK/ContactFact.swift b/Sources/ElixxirDAppsSDK/ContactFact.swift new file mode 100644 index 0000000000000000000000000000000000000000..f4401028242281cf0bc36fdd521adbcbce4dced8 --- /dev/null +++ b/Sources/ElixxirDAppsSDK/ContactFact.swift @@ -0,0 +1,19 @@ +public struct ContactFact: Equatable { + public init( + fact: String, + type: Int + ) { + self.fact = fact + self.type = type + } + + public var fact: String + public var type: Int +} + +extension ContactFact: Codable { + enum CodingKeys: String, CodingKey { + case fact = "Fact" + case type = "Type" + } +} diff --git a/Tests/ElixxirDAppsSDKTests/ContactFactTests.swift b/Tests/ElixxirDAppsSDKTests/ContactFactTests.swift new file mode 100644 index 0000000000000000000000000000000000000000..a95b0b9e2887c0ec374b33324f64360e9ad43edb --- /dev/null +++ b/Tests/ElixxirDAppsSDKTests/ContactFactTests.swift @@ -0,0 +1,30 @@ +import CustomDump +import XCTest +@testable import ElixxirDAppsSDK + +final class ContactFactTests: XCTestCase { + func testCoding() throws { + let jsonString = """ + { + "Fact": "Zezima", + "Type": 0 + } + """ + let jsonData = jsonString.data(using: .utf8)! + let decoder = JSONDecoder() + decoder.dataDecodingStrategy = .base64 + let fact = try decoder.decode(ContactFact.self, from: jsonData) + + XCTAssertNoDifference(fact, ContactFact( + fact: "Zezima", + type: 0 + )) + + let encoder = JSONEncoder() + encoder.dataEncodingStrategy = .base64 + let encodedFact = try encoder.encode(fact) + let decodedFact = try decoder.decode(ContactFact.self, from: encodedFact) + + XCTAssertNoDifference(decodedFact, fact) + } +}