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

Add ContactFact codable model

parent 00ad3639
No related branches found
No related tags found
1 merge request!3Bindings models wrapper
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"
}
}
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)
}
}
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