import Foundation import UIKit import XCTest @testable import OldFella extension SecureSessionUploadFixture { func resolveHandle(_ request: URLRequest) throws -> (Int, Data) { XCTAssertEqual(request.url?.host, "public.api.bsky.app") return (200, Data("{\"did\":\"did:plc:reader\"}".utf8)) } func resolveDID(_ request: URLRequest) throws -> (Int, Data) { return ( 200, Data( ("{\"id\":\"did:plc:reader\",\"service\":[{\"id\":\"#atproto_pds\"," + "\"type\":\"AtprotoPersonalDataServer\"," + "\"serviceEndpoint\":\"https://pds.example.test\"}]}") .utf8) ) } func createSession(_ request: URLRequest) throws -> (Int, Data) { XCTAssertEqual(request.url?.host, "pds.example.test") XCTAssertEqual(request.httpMethod, "POST") XCTAssertNil(request.value(forHTTPHeaderField: "Authorization")) let bodyData = request.url.flatMap { StubURLProtocol.recordedBody(for: $0) } let body = bodyData.flatMap { try? JSONSerialization.jsonObject(with: $0) as? [String: String] } XCTAssertEqual(body?["identifier"], "reader.bsky.social") XCTAssertEqual(body?["password"], "dedicated-app-password") return ( 200, Data( ("{\"handle\":\"reader.bsky.social\",\"did\":\"did:plc:reader\"," + "\"accessJwt\":\"\(token)\",\"refreshJwt\":\"refresh-token\"}") .utf8) ) } func profile(_ 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, Data( ("{\"did\":\"did:plc:reader\",\"handle\":\"reader.bsky.social\"," + "\"displayName\":\"Reader\"," + "\"viewer\":{\"following\":\"at://did:plc:reader/app.bsky.graph.follow/followee\"}}") .utf8) ) } }