import Foundation import XCTest @testable import OldFella extension NotificationBatchFixture { func posts(_ request: URLRequest) throws -> (Int, Data) { let queryItems = request.url.flatMap { URLComponents(url: $0, resolvingAgainstBaseURL: false)?.queryItems } ?? [] let uris = queryItems.filter { $0.name == "uris" }.compactMap(\.value) batchSizesLock.withLock { recordedBatchSizes.append(uris.count) } guard uris.count <= 25 else { return (400, Data("{\"error\":\"TooManyURIs\"}".utf8)) } if let failPostURI, uris.contains(failPostURI) { return (500, Data("{\"error\":\"Unavailable\"}".utf8)) } let posts: [[String: Any]] = uris.filter { $0 != omitPostURI || (omitOnlyFromBatch && uris.count == 1) } .enumerated().map { index, uri in var post: [String: Any] = [ "uri": uri, "cid": "post-cid-\(index)", "author": [ "did": "did:plc:reader", "handle": "reader.example", "displayName": "Reader", "viewer": ["muted": uri == mutedPostURI] ], "record": ["text": "Hydrated post \(uri)"], "indexedAt": "2025-01-02T03:04:05.000Z" ] if uri == malformedPostURI { post.removeValue(forKey: "record") } return post } let response = try JSONSerialization.data(withJSONObject: ["posts": posts]) return (200, response) } static func notificationURI(_ index: Int) -> String { "at://did:plc:actor/app.bsky.feed.like/notice-\(String(format: "%03d", index))" } static func postURI(_ index: Int) -> String { "at://did:plc:reader/app.bsky.feed.post/post-\(String(format: "%03d", index))" } static let notifications: [[String: Any]] = (0..<60).map { index in [ "uri": notificationURI(index), "cid": "notice-cid-\(index)", "reason": "like", "record": [ "subject": ["uri": postURI(index), "cid": "subject-cid"], "createdAt": "2025-01-02T03:04:05.000Z" ], "indexedAt": "2025-01-02T03:04:05.000Z", "isRead": true, "reasonSubject": postURI(index), "author": ["did": "did:plc:actor", "handle": "actor.example"] ] } }