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)) } }