Skip to content

Commit

Permalink
feat: implement multiple services
Browse files Browse the repository at this point in the history
  • Loading branch information
sa-ma committed Jun 22, 2024
1 parent 8c77b47 commit 6aa9b2c
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
1 change: 1 addition & 0 deletions Sources/Example/Example.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ struct Example {
func testConnect() async {
let services: InputData = [
"uber": .service(Service(traits: ["rating"], activities: ["trip"])),
"netflix": .service(Service(activities: ["watch"])),
]
let input = ConnectInput(
publicKey: "0x02073d3b9daf439c19a267dcfc19bc1ac1aea5066d8c754554b046476099b6fa22",
Expand Down
4 changes: 2 additions & 2 deletions Sources/GandalfConnect/GandalfConnect.swift
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,9 @@ public class Connect {

let keys = input.keys.map { $0.lowercased() }

if keys.count > 2 || (keys.count == 2 && !keys.contains("gandalf")) {
if keys.count < 1 {
throw GandalfError(
message: "Only one non-Gandalf service is supported per Connect URL",
message: "At least one service is needed.",
code: .InvalidService
)
}
Expand Down
5 changes: 3 additions & 2 deletions Tests/GandalfConnectTests/GandalfConnectTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,9 @@ final class ConnectTests: XCTestCase {
let connect = Connect(input: input)

do {
_ = try await connect.generateURL()
XCTFail("Expected to throw, but did not throw")
let generatedURL = try await connect.generateURL()
XCTAssertTrue(generatedURL.contains(publicKey))
XCTAssertTrue(generatedURL.contains(redirectURL))
} catch let error as GandalfError {
XCTAssertEqual(error.code, .InvalidService)
} catch {
Expand Down

0 comments on commit 6aa9b2c

Please sign in to comment.