oficina / equipo Public

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

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2import Testing
3import EquipoShareCore
4@testable import EquipoKit
5
6@MainActor @Test func shareSelectionTracksTheActiveHostLifetime() throws {
7 let store = MemorySecretStore(), accounts = DeviceAccounts(store: MemorySecretStore())
8 // Use one store for the actual boundary; the separate instance above has
9 // a foreign lifetime and must never authorize a write.
10 let host = DeviceAccounts(store: store)
11 var account = DeviceAccount.new(origin: URL(string: "https://team.example")!, label: "Phone")
12 account.address = "a@example.net"; account.teamName = "Team"
13 account.credential = DeviceCredential(id: "d", token: "fixture", audience: "a", instanceId: "i", expiresAt: Date().addingTimeInterval(300))
14 try host.commit(.save(account), lifetime: host.lifetimes.current)
15 #expect(throws: CancellationError.self) { try host.commit(.selectForSharing(account), lifetime: accounts.lifetimes.current) }
16 #expect(store.read(ShareSelection.key) == nil)
17 try host.commit(.selectForSharing(account), lifetime: host.lifetimes.current)
18 let selection = try JSONDecoder().decode(ShareSelection.self, from: #require(store.read(ShareSelection.key)))
19 #expect(selection.person == account.address)
20 #expect(selection.origin == account.origin)
21 try host.commit(.clearShareSelection(account), lifetime: host.lifetimes.current)
22 #expect(store.read(ShareSelection.key) == nil)
23 try host.commit(.selectForSharing(account), lifetime: host.lifetimes.current)
24 try host.commit(.remove(account), lifetime: host.lifetimes.current)
25 #expect(store.read(ShareSelection.key) == nil)
26}
27