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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import Foundation
import UIKit
import XCTest
@testable import OldFella
extension SecureSessionUploadFixture {
func timeline(_ request: URLRequest) throws -> (Int, Data) {
XCTAssertEqual(request.url?.host, "pds.example.test")
XCTAssertEqual(request.value(forHTTPHeaderField: "Authorization"), "Bearer \(token)")
XCTAssertEqual(request.value(forHTTPHeaderField: "atproto-proxy"), "did:web:api.bsky.app#bsky_appview")
return (200, try JSONSerialization.data(withJSONObject: SecureSessionTimelineFixture.body))
}
func updateSeen(_ request: URLRequest) throws -> (Int, Data) {
let count = StubURLProtocol.recordedRequests.filter { $0.url?.path == request.url?.path }.count
if count == 1 { return (200, Data()) }
return (503, Data(#"{"error":"Unavailable","message":"Try again later"}"#.utf8))
}
func notifications(_ request: URLRequest) throws -> (Int, Data) {
XCTAssertEqual(request.url?.host, "pds.example.test")
XCTAssertEqual(request.value(forHTTPHeaderField: "Authorization"), "Bearer \(token)")
XCTAssertEqual(request.value(forHTTPHeaderField: "atproto-proxy"), "did:web:api.bsky.app#bsky_appview")
let query = request.url.flatMap { URLComponents(url: $0, resolvingAgainstBaseURL: false)?.queryItems }
if query?.first(where: { $0.name == "cursor" })?.value == "notifications-next" {
return (200, Data(#"{"notifications":[],"cursor":null}"#.utf8))
}
let json = [
#"{"notifications":[{"uri":"at://did:plc:reader/app.bsky.notification/notice-1","#,
#""cid":"notice-1-cid","reason":"like","indexedAt":"2025-01-02T03:04:05.000Z","#,
#""isRead":false,"record":{"$type":"app.bsky.feed.like","#,
#""subject":{"uri":"at://did:plc:reader/app.bsky.feed.post/selected","#,
#""cid":"selected-cid"},"createdAt":"2025-01-02T03:04:05.000Z"},"#,
#""reasonSubject":"at://did:plc:reader/app.bsky.feed.post/selected","#,
#""author":{"did":"did:plc:actor","handle":"actor.example","displayName":"Actor","#,
#""avatar":"https://cdn.bsky.app/img/avatar/actor.jpeg","description":"I post about books."}},"#,
#"{"uri":"at://did:plc:reader/app.bsky.feed.post/reply-1","cid":"reply-cid","#,
#""reason":"reply","#,
#""reasonSubject":"at://did:plc:reader/app.bsky.feed.post/selected","#,
#""indexedAt":"2025-01-02T03:05:05.000Z","isRead":false,"#,
#""record":{"text":"Here is the actual reply.","#,
#""reply":{"parent":{"uri":"at://did:plc:reader/app.bsky.feed.post/parent","#,
#""cid":"parent-cid"},"#,
#""root":{"uri":"at://did:plc:reader/app.bsky.feed.post/parent","#,
#""cid":"parent-cid"}}},"author":{"did":"did:plc:actor","handle":"actor.example","#,
#""displayName":"Actor","avatar":"https://cdn.bsky.app/img/avatar/actor.jpeg"}}],"#,
#""cursor":"notifications-next"}"#
].joined()
return (
200,
Data(json.utf8)
)
}
func posts(_ request: URLRequest) throws -> (Int, Data) {
XCTAssertEqual(request.url?.host, "pds.example.test")
XCTAssertEqual(request.value(forHTTPHeaderField: "Authorization"), "Bearer \(token)")
XCTAssertEqual(request.value(forHTTPHeaderField: "atproto-proxy"), "did:web:api.bsky.app#bsky_appview")
let json = [
#"{"posts":[{"uri":"at://did:plc:reader/app.bsky.feed.post/reply-1","#,
#""cid":"reply-cid","author":{"did":"did:plc:actor","handle":"actor.example","#,
#""displayName":"Actor"},"record":{"text":"Here is the actual reply."},"#,
#""indexedAt":"2025-01-02T03:05:05.000Z"},"#,
#"{"uri":"at://did:plc:reader/app.bsky.feed.post/selected","cid":"selected-cid","#,
#""author":{"did":"did:plc:reader","handle":"reader.bsky.social","#,
#""displayName":"Reader","avatar":"https://cdn.bsky.app/img/avatar/reader.jpeg"},"#,
#""record":{"text":"The post that was liked."},"#,
#""indexedAt":"2025-01-02T03:04:05.000Z"},"#,
#"{"uri":"at://did:plc:reader/app.bsky.feed.post/parent","cid":"parent-cid","#,
#""author":{"did":"did:plc:reader","handle":"reader.bsky.social","#,
#""displayName":"Reader"},"record":{"text":"My original post."},"#,
#""indexedAt":"2025-01-02T03:04:05.000Z"}]}"#
].joined()
return (
200,
Data(json.utf8)
)
}
func thread(_ request: URLRequest) throws -> (Int, Data) {
return (200, Data(Self.threadJSON.utf8))
}
}