1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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"]
]
}
}