From c9c4efcd1477a5391c7ea35cbdb999cd507db0e9 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Fri, 29 Jul 2022 13:21:38 +0100
Subject: [PATCH] Add BackupReport model

---
 .../ElixxirDAppsSDK/Models/BackupReport.swift | 29 +++++++++++++++++++
 .../Models/BackupReportTests.swift            | 28 ++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 Sources/ElixxirDAppsSDK/Models/BackupReport.swift
 create mode 100644 Tests/ElixxirDAppsSDKTests/Models/BackupReportTests.swift

diff --git a/Sources/ElixxirDAppsSDK/Models/BackupReport.swift b/Sources/ElixxirDAppsSDK/Models/BackupReport.swift
new file mode 100644
index 00000000..3ee3dca9
--- /dev/null
+++ b/Sources/ElixxirDAppsSDK/Models/BackupReport.swift
@@ -0,0 +1,29 @@
+import Foundation
+
+public struct BackupReport: Equatable {
+  public init(
+    ids: Data,
+    params: Data
+  ) {
+    self.ids = ids
+    self.params = params
+  }
+
+  public var ids: Data
+  public var params: Data
+}
+
+extension BackupReport: Codable {
+  enum CodingKeys: String, CodingKey {
+    case ids = "BackupIdListJson"
+    case params = "BackupParams"
+  }
+
+  public static func decode(_ data: Data) throws -> Self {
+    try JSONDecoder().decode(Self.self, from: data)
+  }
+
+  public func encode() throws -> Data {
+    try JSONEncoder().encode(self)
+  }
+}
diff --git a/Tests/ElixxirDAppsSDKTests/Models/BackupReportTests.swift b/Tests/ElixxirDAppsSDKTests/Models/BackupReportTests.swift
new file mode 100644
index 00000000..93ef4f65
--- /dev/null
+++ b/Tests/ElixxirDAppsSDKTests/Models/BackupReportTests.swift
@@ -0,0 +1,28 @@
+import CustomDump
+import XCTest
+@testable import ElixxirDAppsSDK
+
+final class BackupReportTests: XCTestCase {
+  func testCoding() throws {
+    let idsB64 = "WyJPRHRRTTA4ZERpV3lXaE0wWUhjanRHWnZQcHRSa1JOZ1pHR2FkTG10dE9BRCJd"
+    let paramsB64 = "cGFyYW1z"
+    let jsonString = """
+    {
+      "BackupIdListJson": "\(idsB64)",
+      "BackupParams": "\(paramsB64)"
+    }
+    """
+    let jsonData = jsonString.data(using: .utf8)!
+    let model = try BackupReport.decode(jsonData)
+
+    XCTAssertNoDifference(model, BackupReport(
+      ids: Data(base64Encoded: idsB64)!,
+      params: Data(base64Encoded: paramsB64)!
+    ))
+
+    let encodedModel = try model.encode()
+    let decodedModel = try BackupReport.decode(encodedModel)
+
+    XCTAssertNoDifference(decodedModel, model)
+  }
+}
-- 
GitLab