diff --git a/Sources/ElixxirDAppsSDK/Models/Progress.swift b/Sources/ElixxirDAppsSDK/Models/Progress.swift index 1376957be7b247acd1c84d0668246078c7b9163f..ba2e199db7fb504d790ef6ef514c1e25f9c794eb 100644 --- a/Sources/ElixxirDAppsSDK/Models/Progress.swift +++ b/Sources/ElixxirDAppsSDK/Models/Progress.swift @@ -4,18 +4,19 @@ public struct Progress: Equatable { public init( completed: Bool, transmitted: Int, - total: Int + total: Int, + error: String? ) { self.completed = completed self.transmitted = transmitted self.total = total + self.error = error } public var completed: Bool public var transmitted: Int public var total: Int - // TODO: add error - // public var error: ??? + public var error: String? } extension Progress: Codable { @@ -23,8 +24,7 @@ extension Progress: Codable { case completed = "Completed" case transmitted = "Transmitted" case total = "Total" - // TODO: add error - // case error = "Err" + case error = "Err" } public static func decode(_ data: Data) throws -> Self { diff --git a/Tests/ElixxirDAppsSDKTests/Models/ProgressTests.swift b/Tests/ElixxirDAppsSDKTests/Models/ProgressTests.swift index 86f8d0f57a46554fc427ec1976ecb65fe0bac52b..451ea593aef7bd145265617c178c4dce32788ad5 100644 --- a/Tests/ElixxirDAppsSDKTests/Models/ProgressTests.swift +++ b/Tests/ElixxirDAppsSDKTests/Models/ProgressTests.swift @@ -21,7 +21,8 @@ final class ProgressTests: XCTestCase { XCTAssertNoDifference(progress, Progress( completed: completed, transmitted: transmitted, - total: total + total: total, + error: nil )) let encodedProgress = try progress.encode() @@ -29,4 +30,28 @@ final class ProgressTests: XCTestCase { XCTAssertNoDifference(decodedProgress, progress) } + + func testDecodingProgressWithError() throws { + let completed = false + let transmitted: Int = 128 + let total: Int = 2048 + let error = "something went wrong" + let jsonString = """ + { + "Completed": \(completed), + "Transmitted": \(transmitted), + "Total": \(total), + "Err": "\(error)" + } + """ + let jsonData = jsonString.data(using: .utf8)! + let progress = try Progress.decode(jsonData) + + XCTAssertNoDifference(progress, Progress( + completed: completed, + transmitted: transmitted, + total: total, + error: error + )) + } }