Newer
Older
import CustomDump
import XCTest
import XCTestDynamicOverlay
import XXClient
@testable import XXMessengerClient
func testGetReport() throws {
let serviceList = MessageServiceList.stub()
let notificationCSV = "notification-csv"
let notificationReports = [NotificationReport].stub()
struct GetNotificationsReportParams: Equatable {
var notificationCSV: String
var serviceList: MessageServiceList
}
var didGetNotificationsReport: [GetNotificationsReportParams] = []
var env: MessengerEnvironment = .unimplemented
env.serviceList.get = {
serviceList
}
env.getNotificationsReport.run = { notificationCSV, serviceList in
didGetNotificationsReport.append(.init(
notificationCSV: notificationCSV,
serviceList: serviceList
))
let reports = try getReports(notificationCSV: notificationCSV)
XCTAssertNoDifference(didGetNotificationsReport, [
.init(
notificationCSV: notificationCSV,
serviceList: serviceList
)
])
XCTAssertNoDifference(reports, notificationReports)
}
func testGetReportWhenServiceListMissing() {
var env: MessengerEnvironment = .unimplemented
env.e2e.get = { .unimplemented }
env.serviceList.get = { nil }
XCTAssertThrowsError(try getReports(notificationCSV: "")) { error in
.serviceListMissing
)
}
}
}
private extension Array where Element == NotificationReport {
static func stub() -> [NotificationReport] {
[.stub(), .stub(), .stub()]
}
}
private extension NotificationReport {
static func stub() -> NotificationReport {
NotificationReport(
forMe: .random(),
type: ReportType.allCases.randomElement()!,
source: "source-\(Int.random(in: 100...999))".data(using: .utf8)!
)
}
}