You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
session-ios/SessionMessagingKitTests/_TestUtilities/CustomArgSummaryDescribable...

43 lines
1.7 KiB
Swift

// Copyright © 2024 Rangeproof Pty Ltd. All rights reserved.
import Foundation
import SessionMessagingKit
import SessionUtilitiesKit
extension Job: CustomArgSummaryDescribable {
var customArgSummaryDescribable: String? {
switch variant {
case .attachmentUpload:
guard
let detailsData: Data = details,
let details: AttachmentUploadJob.Details = try? JSONDecoder()
.decode(AttachmentUploadJob.Details.self, from: detailsData)
else { return nil }
let stringParts: [String] = String(reflecting: self).components(separatedBy: "details: Optional(")
guard stringParts.count > 1 else { return nil }
let stringSuffix: [String] = stringParts[1].components(separatedBy: " bytes)")
guard stringSuffix.count > 1 else { return nil }
return (stringParts[0] + String(reflecting: details) + stringSuffix[1])
default:
guard
let detailsData: Data = details,
let detailsString: String = String(data: detailsData, encoding: .utf8)
else { return nil }
let stringParts: [String] = String(reflecting: self).components(separatedBy: "details: Optional(")
guard stringParts.count > 1 else { return nil }
let stringSuffix: [String] = stringParts[1].components(separatedBy: " bytes)")
guard stringSuffix.count > 1 else { return nil }
return (stringParts[0] + detailsString + stringSuffix[1])
}
}
}