oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1#if os(macOS)
2import AppKit
3import Foundation
4import Testing
5import EquipoShareCore
6import EquipoKit
7@testable import EquipoMac
8
9@Test(arguments: ["url", "earlier", "too_many", "too_large"]) @MainActor func serviceReceivesInputAndReportsPreparationFailure(_ kind: String) async throws {
10 _ = NSApplication.shared
11 let store = MemorySecretStore(), directory = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
12 defer { try? FileManager.default.removeItem(at: directory) }
13 let selection = ShareSelection(origin: URL(string: "https://share-fixture.invalid")!, person: "p", team: "T")
14 try store.write(JSONEncoder().encode(selection), account: ShareSelection.key)
15 // Device-account JSON is the shared boundary, using Foundation's date encoding.
16 let account: [String: Any] = ["origin": selection.origin.absoluteString, "address": "p", "credential": ["token": "fixture-share", "expiresAt": Date().addingTimeInterval(300).timeIntervalSinceReferenceDate]]
17 try store.write(JSONSerialization.data(withJSONObject: account), account: selection.origin.absoluteString)
18 let journal = ShareJournal(directory: directory)
19 let earlier = try ShareMessage(text: "Earlier message", project: nil, attachments: []).pending()
20 if kind == "earlier" { try journal.save(earlier, selection: selection) }
21 let sender = ShareSender(auth: ShareAuthentication(store: store), transport: ShareFixtureTransport(), journal: journal)
22 let service = ShareService(makeSender: { sender })
23 defer { service.close() }
24 let pasteboard = NSPasteboard.withUniqueName(); defer { pasteboard.releaseGlobally() }
25 if kind == "too_many" {
26 pasteboard.writeObjects((0..<6).map { directory.appendingPathComponent("file-\($0).txt") as NSURL })
27 } else if kind == "too_large" { pasteboard.setString(String(repeating: "x", count: 16 * 1024 + 1), forType: .string) }
28 else { pasteboard.setString("https://example.net/bug", forType: .URL) }
29 var error: NSString?
30 service.sendToEquipo(pasteboard, userData: nil, error: &error)
31 await service.waitForPreparation()
32 #expect(error == nil)
33 if kind == "url" || kind == "earlier" {
34 #expect(sender.text == "https://example.net/bug")
35 if kind == "earlier" {
36 #expect(sender.earlierPending == [earlier])
37 #expect(try journal.loadAll(selection: selection) == [earlier])
38 }
39 }
40 else {
41 #expect(service.preparationNotice == EquipoStrings.text(kind == "too_many" ? "api.attachment_limit" : "api.attachment_too_large"))
42 }
43 #expect(sender.files.isEmpty)
44 #expect(!sender.busy && !sender.finished && sender.pending == nil)
45}
46#endif
47