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

Add error property to Progress model

parent 4a04d14d
No related branches found
No related tags found
Loading
......@@ -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 {
......
......@@ -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
))
}
}
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