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

Add MessengerGetNotificationReport

parent 84105b1b
No related branches found
No related tags found
2 merge requests!138Notifications,!102Release 1.0.0
import Foundation
public struct NotificationReport: Equatable {
public enum ReportType: String, Equatable {
public enum ReportType: String, Equatable, CaseIterable {
case `default`
case request
case reset
......
import XXClient
import XCTestDynamicOverlay
public struct MessengerGetNotificationReport {
public enum Error: Swift.Error, Equatable {
case notConnected
case serviceListMissing
}
public var run: (String) throws -> NotificationReport
public func callAsFunction(notificationCSV: String) throws -> NotificationReport {
try run(notificationCSV)
}
}
extension MessengerGetNotificationReport {
public static func live(_ env: MessengerEnvironment) -> MessengerGetNotificationReport {
MessengerGetNotificationReport { notificationCSV in
guard let e2e = env.e2e() else {
throw Error.notConnected
}
guard let serviceList = env.serviceList() else {
throw Error.serviceListMissing
}
return try env.getNotificationsReport(
e2eId: e2e.getId(),
notificationCSV: notificationCSV,
services: serviceList
)
}
}
}
extension MessengerGetNotificationReport {
public static let unimplemented = MessengerGetNotificationReport(
run: XCTUnimplemented("\(Self.self)")
)
}
......@@ -16,6 +16,7 @@ public struct MessengerEnvironment {
public var getE2EFileTransferParams: GetE2EFileTransferParams
public var getE2EParams: GetE2EParams
public var getFileTransferParams: GetFileTransferParams
public var getNotificationsReport: GetNotificationsReport
public var getSingleUseParams: GetSingleUseParams
public var initFileTransfer: InitFileTransfer
public var initializeBackup: InitializeBackup
......@@ -68,6 +69,7 @@ extension MessengerEnvironment {
getE2EFileTransferParams: .liveDefault,
getE2EParams: .liveDefault,
getFileTransferParams: .liveDefault,
getNotificationsReport: .live,
getSingleUseParams: .liveDefault,
initFileTransfer: .live,
initializeBackup: .live,
......@@ -115,6 +117,7 @@ extension MessengerEnvironment {
getE2EFileTransferParams: .unimplemented,
getE2EParams: .unimplemented,
getFileTransferParams: .unimplemented,
getNotificationsReport: .unimplemented,
getSingleUseParams: .unimplemented,
initFileTransfer: .unimplemented,
initializeBackup: .unimplemented,
......
import CustomDump
import XCTest
import XCTestDynamicOverlay
import XXClient
@testable import XXMessengerClient
final class MessengerGetNotificationReportTests: XCTestCase {
func testGetReport() throws {
let e2eId = 123
let serviceList = MessageServiceList.stub()
let notificationCSV = "notification-csv"
let notificationReport = NotificationReport.stub()
struct GetNotificationsReportParams: Equatable {
var e2eId: Int
var notificationCSV: String
var serviceList: MessageServiceList
}
var didGetNotificationsReport: [GetNotificationsReportParams] = []
var env: MessengerEnvironment = .unimplemented
env.e2e.get = {
var e2e: E2E = .unimplemented
e2e.getId.run = { e2eId }
return e2e
}
env.serviceList.get = {
serviceList
}
env.getNotificationsReport.run = { e2eId, notificationCSV, serviceList in
didGetNotificationsReport.append(.init(
e2eId: e2eId,
notificationCSV: notificationCSV,
serviceList: serviceList
))
return notificationReport
}
let getReport: MessengerGetNotificationReport = .live(env)
let report = try getReport(notificationCSV: notificationCSV)
XCTAssertNoDifference(didGetNotificationsReport, [
.init(
e2eId: e2eId,
notificationCSV: notificationCSV,
serviceList: serviceList
)
])
XCTAssertNoDifference(report, notificationReport)
}
func testGetReportWhenNotConnected() {
var env: MessengerEnvironment = .unimplemented
env.e2e.get = { nil }
let getReport: MessengerGetNotificationReport = .live(env)
XCTAssertThrowsError(try getReport(notificationCSV: "")) { error in
XCTAssertNoDifference(
error as? MessengerGetNotificationReport.Error,
.notConnected
)
}
}
func testGetReportWhenServiceListMissing() {
var env: MessengerEnvironment = .unimplemented
env.e2e.get = { .unimplemented }
env.serviceList.get = { nil }
let getReport: MessengerGetNotificationReport = .live(env)
XCTAssertThrowsError(try getReport(notificationCSV: "")) { error in
XCTAssertNoDifference(
error as? MessengerGetNotificationReport.Error,
.serviceListMissing
)
}
}
}
extension NotificationReport {
static func stub() -> NotificationReport {
NotificationReport(
forMe: .random(),
type: ReportType.allCases.randomElement()!,
source: "source-\(Int.random(in: 100...999))".data(using: .utf8)!
)
}
}
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