From 450ca4880a2c5d85dbc35f4834f9f2af862e23d8 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Sat, 12 Nov 2022 11:29:07 +0100
Subject: [PATCH 1/4] Add NotificationReport array coding helpers

---
 .../XXClient/Models/NotificationReport.swift  | 10 +++++
 .../Models/NotificationReportTests.swift      | 39 +++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/Sources/XXClient/Models/NotificationReport.swift b/Sources/XXClient/Models/NotificationReport.swift
index 06eb1d89..3a0192cc 100644
--- a/Sources/XXClient/Models/NotificationReport.swift
+++ b/Sources/XXClient/Models/NotificationReport.swift
@@ -45,3 +45,13 @@ extension NotificationReport: Codable {
     try JSONEncoder().encode(self)
   }
 }
+
+extension Array where Element == NotificationReport {
+  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/XXClientTests/Models/NotificationReportTests.swift b/Tests/XXClientTests/Models/NotificationReportTests.swift
index 9e99d825..4b8372fc 100644
--- a/Tests/XXClientTests/Models/NotificationReportTests.swift
+++ b/Tests/XXClientTests/Models/NotificationReportTests.swift
@@ -28,4 +28,43 @@ final class NotificationReportTests: XCTestCase {
 
     XCTAssertNoDifference(decodedModel, model)
   }
+
+  func testCodingArray() throws {
+    let source1B64 = "dGVzdGVyMTIzAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
+    let source2B64 = "ciI1cpyUUY/UPaVeMy1zBFWbZRgiZSXhY+cVoM+fCxwD"
+    let jsonString = """
+    [
+      {
+        "ForMe": true,
+        "Type": "\(NotificationReport.ReportType.default.rawValue)",
+        "Source": "\(source1B64)"
+      },
+      {
+        "ForMe": false,
+        "Type": "\(NotificationReport.ReportType.request.rawValue)",
+        "Source": "\(source2B64)"
+      },
+    ]
+    """
+    let jsonData = jsonString.data(using: .utf8)!
+    let models = try [NotificationReport].decode(jsonData)
+
+    XCTAssertNoDifference(models, [
+      NotificationReport(
+        forMe: true,
+        type: .default,
+        source: Data(base64Encoded: source1B64)!
+      ),
+      NotificationReport(
+        forMe: false,
+        type: .request,
+        source: Data(base64Encoded: source2B64)!
+      )
+    ])
+
+    let encodedModels = try models.encode()
+    let decodedModels = try [NotificationReport].decode(encodedModels)
+
+    XCTAssertNoDifference(decodedModels, models)
+  }
 }
-- 
GitLab


From 86e5199c9382527ced469ef99cbcc40a3c078199 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Sat, 12 Nov 2022 11:33:43 +0100
Subject: [PATCH 2/4] Fix GetNotificationsReport so it returns array

---
 Sources/XXClient/Functions/GetNotificationsReport.swift | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/Sources/XXClient/Functions/GetNotificationsReport.swift b/Sources/XXClient/Functions/GetNotificationsReport.swift
index 81d54a59..9b123572 100644
--- a/Sources/XXClient/Functions/GetNotificationsReport.swift
+++ b/Sources/XXClient/Functions/GetNotificationsReport.swift
@@ -2,12 +2,12 @@ import Bindings
 import XCTestDynamicOverlay
 
 public struct GetNotificationsReport {
-  public var run: (String, MessageServiceList) throws -> NotificationReport
+  public var run: (String, MessageServiceList) throws -> [NotificationReport]
 
   public func callAsFunction(
     notificationCSV: String,
     services: MessageServiceList
-  ) throws -> NotificationReport {
+  ) throws -> [NotificationReport] {
     try run(notificationCSV, services)
   }
 }
@@ -26,7 +26,7 @@ extension GetNotificationsReport {
     guard let result = result else {
       fatalError("BindingsGetNotificationsReport returned nil without providing error")
     }
-    return try NotificationReport.decode(result)
+    return try [NotificationReport].decode(result)
   }
 }
 
-- 
GitLab


From 065dbc91122b204af3c0276315c0743fe5e12119 Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Sat, 12 Nov 2022 11:34:01 +0100
Subject: [PATCH 3/4] Update MessengerGetNotificationReport

---
 .../MessengerGetNotificationReport.swift         |  4 ++--
 .../MessengerGetNotificationReportTests.swift    | 16 +++++++++++-----
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReport.swift b/Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReport.swift
index a7f04ff9..0b7de4fa 100644
--- a/Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReport.swift
+++ b/Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReport.swift
@@ -6,9 +6,9 @@ public struct MessengerGetNotificationReport {
     case serviceListMissing
   }
 
-  public var run: (String) throws -> NotificationReport
+  public var run: (String) throws -> [NotificationReport]
 
-  public func callAsFunction(notificationCSV: String) throws -> NotificationReport {
+  public func callAsFunction(notificationCSV: String) throws -> [NotificationReport] {
     try run(notificationCSV)
   }
 }
diff --git a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportTests.swift b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportTests.swift
index eed49be1..7d778c0d 100644
--- a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportTests.swift
+++ b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportTests.swift
@@ -8,7 +8,7 @@ final class MessengerGetNotificationReportTests: XCTestCase {
   func testGetReport() throws {
     let serviceList = MessageServiceList.stub()
     let notificationCSV = "notification-csv"
-    let notificationReport = NotificationReport.stub()
+    let notificationReports = [NotificationReport].stub()
 
     struct GetNotificationsReportParams: Equatable {
       var notificationCSV: String
@@ -25,11 +25,11 @@ final class MessengerGetNotificationReportTests: XCTestCase {
         notificationCSV: notificationCSV,
         serviceList: serviceList
       ))
-      return notificationReport
+      return notificationReports
     }
     let getReport: MessengerGetNotificationReport = .live(env)
 
-    let report = try getReport(notificationCSV: notificationCSV)
+    let reports = try getReport(notificationCSV: notificationCSV)
 
     XCTAssertNoDifference(didGetNotificationsReport, [
       .init(
@@ -37,7 +37,7 @@ final class MessengerGetNotificationReportTests: XCTestCase {
         serviceList: serviceList
       )
     ])
-    XCTAssertNoDifference(report, notificationReport)
+    XCTAssertNoDifference(reports, notificationReports)
   }
 
   func testGetReportWhenServiceListMissing() {
@@ -55,7 +55,13 @@ final class MessengerGetNotificationReportTests: XCTestCase {
   }
 }
 
-extension NotificationReport {
+private extension Array where Element == NotificationReport {
+  static func stub() -> [NotificationReport] {
+    [.stub(), .stub(), .stub()]
+  }
+}
+
+private extension NotificationReport {
   static func stub() -> NotificationReport {
     NotificationReport(
       forMe: .random(),
-- 
GitLab


From 20f419171a5ead6f2cfaa412784bb6bf53e3ec1d Mon Sep 17 00:00:00 2001
From: Dariusz Rybicki <dariusz@elixxir.io>
Date: Sat, 12 Nov 2022 11:37:15 +0100
Subject: [PATCH 4/4] Refactor

Rename MessengerGetNotificationReport to MessengerGetNotificationReports
---
 ...t.swift => MessengerGetNotificationReports.swift} | 12 ++++++------
 Sources/XXMessengerClient/Messenger/Messenger.swift  |  6 +++---
 ...ft => MessengerGetNotificationReportsTests.swift} | 12 ++++++------
 3 files changed, 15 insertions(+), 15 deletions(-)
 rename Sources/XXMessengerClient/Messenger/Functions/{MessengerGetNotificationReport.swift => MessengerGetNotificationReports.swift} (76%)
 rename Tests/XXMessengerClientTests/Messenger/Functions/{MessengerGetNotificationReportTests.swift => MessengerGetNotificationReportsTests.swift} (81%)

diff --git a/Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReport.swift b/Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReports.swift
similarity index 76%
rename from Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReport.swift
rename to Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReports.swift
index 0b7de4fa..b2496c22 100644
--- a/Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReport.swift
+++ b/Sources/XXMessengerClient/Messenger/Functions/MessengerGetNotificationReports.swift
@@ -1,7 +1,7 @@
 import XXClient
 import XCTestDynamicOverlay
 
-public struct MessengerGetNotificationReport {
+public struct MessengerGetNotificationReports {
   public enum Error: Swift.Error, Equatable {
     case serviceListMissing
   }
@@ -13,9 +13,9 @@ public struct MessengerGetNotificationReport {
   }
 }
 
-extension MessengerGetNotificationReport {
-  public static func live(_ env: MessengerEnvironment) -> MessengerGetNotificationReport {
-    MessengerGetNotificationReport { notificationCSV in
+extension MessengerGetNotificationReports {
+  public static func live(_ env: MessengerEnvironment) -> MessengerGetNotificationReports {
+    MessengerGetNotificationReports { notificationCSV in
       guard let serviceList = env.serviceList() else {
         throw Error.serviceListMissing
       }
@@ -27,8 +27,8 @@ extension MessengerGetNotificationReport {
   }
 }
 
-extension MessengerGetNotificationReport {
-  public static let unimplemented = MessengerGetNotificationReport(
+extension MessengerGetNotificationReports {
+  public static let unimplemented = MessengerGetNotificationReports(
     run: XCTUnimplemented("\(Self.self)")
   )
 }
diff --git a/Sources/XXMessengerClient/Messenger/Messenger.swift b/Sources/XXMessengerClient/Messenger/Messenger.swift
index d0bf6e46..9261d264 100644
--- a/Sources/XXMessengerClient/Messenger/Messenger.swift
+++ b/Sources/XXMessengerClient/Messenger/Messenger.swift
@@ -47,7 +47,7 @@ public struct Messenger {
   public var sendFile: MessengerSendFile
   public var receiveFile: MessengerReceiveFile
   public var trackServices: MessengerTrackServices
-  public var getNotificationReport: MessengerGetNotificationReport
+  public var getNotificationReports: MessengerGetNotificationReports
 }
 
 extension Messenger {
@@ -99,7 +99,7 @@ extension Messenger {
       sendFile: .live(env),
       receiveFile: .live(env),
       trackServices: .live(env),
-      getNotificationReport: .live(env)
+      getNotificationReports: .live(env)
     )
   }
 }
@@ -152,6 +152,6 @@ extension Messenger {
     sendFile: .unimplemented,
     receiveFile: .unimplemented,
     trackServices: .unimplemented,
-    getNotificationReport: .unimplemented
+    getNotificationReports: .unimplemented
   )
 }
diff --git a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportTests.swift b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportsTests.swift
similarity index 81%
rename from Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportTests.swift
rename to Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportsTests.swift
index 7d778c0d..98e1adce 100644
--- a/Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportTests.swift
+++ b/Tests/XXMessengerClientTests/Messenger/Functions/MessengerGetNotificationReportsTests.swift
@@ -4,7 +4,7 @@ import XCTestDynamicOverlay
 import XXClient
 @testable import XXMessengerClient
 
-final class MessengerGetNotificationReportTests: XCTestCase {
+final class MessengerGetNotificationReportsTests: XCTestCase {
   func testGetReport() throws {
     let serviceList = MessageServiceList.stub()
     let notificationCSV = "notification-csv"
@@ -27,9 +27,9 @@ final class MessengerGetNotificationReportTests: XCTestCase {
       ))
       return notificationReports
     }
-    let getReport: MessengerGetNotificationReport = .live(env)
+    let getReports: MessengerGetNotificationReports = .live(env)
 
-    let reports = try getReport(notificationCSV: notificationCSV)
+    let reports = try getReports(notificationCSV: notificationCSV)
 
     XCTAssertNoDifference(didGetNotificationsReport, [
       .init(
@@ -44,11 +44,11 @@ final class MessengerGetNotificationReportTests: XCTestCase {
     var env: MessengerEnvironment = .unimplemented
     env.e2e.get = { .unimplemented }
     env.serviceList.get = { nil }
-    let getReport: MessengerGetNotificationReport = .live(env)
+    let getReports: MessengerGetNotificationReports = .live(env)
 
-    XCTAssertThrowsError(try getReport(notificationCSV: "")) { error in
+    XCTAssertThrowsError(try getReports(notificationCSV: "")) { error in
       XCTAssertNoDifference(
-        error as? MessengerGetNotificationReport.Error,
+        error as? MessengerGetNotificationReports.Error,
         .serviceListMissing
       )
     }
-- 
GitLab