RadrootsExternalActionsTestingTests.swift (1424B)
1 import Foundation 2 import RadrootsKit 3 import RadrootsKitTesting 4 import Testing 5 6 @Test func fakeExternalActionsRecordsCapabilityAndOpenRequests() async throws { 7 let web = try RadrootsExternalActionDestination.web("https://radroots.org") 8 let nostr = try RadrootsExternalActionDestination.nostr("nostr:npub1qqqqqq") 9 let actions = RadrootsFakeExternalActions( 10 capabilityOverrides: [nostr: false], 11 defaultCanOpen: true 12 ) 13 14 #expect(await actions.canOpen(web).canOpen) 15 #expect(await !(actions.canOpen(nostr).canOpen)) 16 try await actions.open(RadrootsExternalActionRequest(destination: web)) 17 18 #expect(await actions.capabilityRequestCount == 2) 19 #expect(await actions.openRequestCount == 1) 20 #expect(await actions.lastCapabilityDestination == nostr) 21 #expect(await actions.lastOpenedDestination == web) 22 #expect(await actions.openedDestinations == [web]) 23 } 24 25 @Test func fakeExternalActionsReturnsConfiguredFailures() async throws { 26 let destination = RadrootsExternalActionDestination.appSettings 27 let actions = RadrootsFakeExternalActions( 28 openOutcome: .failure(.unavailable) 29 ) 30 31 await #expect(throws: RadrootsExternalActionError.unavailable) { 32 try await actions.open(RadrootsExternalActionRequest(destination: destination)) 33 } 34 35 #expect(await actions.openRequestCount == 1) 36 #expect(await actions.lastOpenedDestination == destination) 37 }