From e9ca0dc8430b90c0ebf5d834660a4d1da719d827 Mon Sep 17 00:00:00 2001 From: Dariusz Rybicki <dariusz@elixxir.io> Date: Mon, 25 Jul 2022 18:51:21 +0100 Subject: [PATCH] Refactor --- Tests/ElixxirDAppsSDKTests/FactTests.swift | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/Tests/ElixxirDAppsSDKTests/FactTests.swift b/Tests/ElixxirDAppsSDKTests/FactTests.swift index 21820a78..0894b22a 100644 --- a/Tests/ElixxirDAppsSDKTests/FactTests.swift +++ b/Tests/ElixxirDAppsSDKTests/FactTests.swift @@ -4,26 +4,25 @@ import XCTest final class FactTests: XCTestCase { func testCoding() throws { + let factString = "Zezima" + let factType: Int = 0 let jsonString = """ { - "Fact": "Zezima", - "Type": 0 + "Fact": "\(factString)", + "Type": \(factType) } """ let jsonData = jsonString.data(using: .utf8)! - let decoder = JSONDecoder() - decoder.dataDecodingStrategy = .base64 - let fact = try decoder.decode(Fact.self, from: jsonData) + + let fact = try Fact.decode(jsonData) XCTAssertNoDifference(fact, Fact( - fact: "Zezima", - type: 0 + fact: factString, + type: factType )) - let encoder = JSONEncoder() - encoder.dataEncodingStrategy = .base64 - let encodedFact = try encoder.encode(fact) - let decodedFact = try decoder.decode(Fact.self, from: encodedFact) + let encodedFact = try fact.encode() + let decodedFact = try Fact.decode(encodedFact) XCTAssertNoDifference(decodedFact, fact) } -- GitLab