Download this file
| 1 | #if DEBUG |
| 2 | import Foundation |
| 3 | |
| 4 | /// Simulator-only hosts opt into this origin with a disposable keychain account. |
| 5 | /// No real origin or bearer can enter this transport, and Release omits it. |
| 6 | public struct ShareFixtureTransport: ShareTransport { |
| 7 | public init() {} |
| 8 | public func send(_ request: URLRequest, file: URL?, progress: @escaping @Sendable (Double) -> Void) async throws -> ShareResponse { |
| 9 | guard request.url?.host == "share-fixture.invalid", request.value(forHTTPHeaderField: "Authorization") == "Bearer fixture-share" else { throw ShareFailure.signedOut } |
| 10 | if request.url?.path == "/api/v1/projects" { return .init(status: 200, data: Data(#"{"items":[{"id":"home","name":"Home"}],"allowed":["home"]}"#.utf8)) } |
| 11 | if request.url?.path == "/api/v1/attachments", let file { |
| 12 | guard (try file.resourceValues(forKeys: [.fileSizeKey]).fileSize ?? .max) <= AttachmentLimits.maxBytes else { throw ShareFailure.tooLarge } |
| 13 | progress(1) |
| 14 | return .init(status: 201, data: Data(#"{"id":"fixture-attachment"}"#.utf8)) |
| 15 | } |
| 16 | if request.url?.path == "/api/v1/messages" { return .init(status: 201, data: Data(#"{"message":{"id":"fixture-message"}}"#.utf8)) } |
| 17 | throw ShareFailure.invalidInput |
| 18 | } |
| 19 | } |
| 20 | public enum ShareFixtureFiles { public static func save(_ data: Data, to url: URL) throws { try data.write(to: url, options: .atomic) } } |
| 21 | #endif |
| 22 | |