Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions FirebaseFunctions/Sources/Functions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ internal enum FunctionsConstants {
return HTTPSCallable(functions: self, name: name)
}

@objc(HTTPSCallableWithURL:) open func httpsCallable(url: URL) -> HTTPSCallable {
@objc(HTTPSCallableWithURL:) open func httpsCallable(_ url: URL) -> HTTPSCallable {
return HTTPSCallable(functions: self, url: url)
}

Expand Down Expand Up @@ -135,15 +135,15 @@ internal enum FunctionsConstants {
/// - Parameter encoder: The encoder instance to use to run the encoding.
/// - Parameter decoder: The decoder instance to use to run the decoding.
open func httpsCallable<Request: Encodable,
Response: Decodable>(url: URL,
Response: Decodable>(_ url: URL,
requestAs: Request.Type = Request.self,
responseAs: Response.Type = Response.self,
encoder: FirebaseDataEncoder = FirebaseDataEncoder(
),
decoder: FirebaseDataDecoder = FirebaseDataDecoder(
))
-> Callable<Request, Response> {
return Callable(callable: httpsCallable(url: url), encoder: encoder, decoder: decoder)
return Callable(callable: httpsCallable(url), encoder: encoder, decoder: decoder)
}

/**
Expand Down
50 changes: 25 additions & 25 deletions FirebaseFunctions/Tests/Integration/IntegrationTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class IntegrationTests: XCTestCase {
let byName = functions.httpsCallable("dataTest",
requestAs: DataTestRequest.self,
responseAs: DataTestResponse.self)
let byURL = functions.httpsCallable(url: emulatorURL("dataTest"),
let byURL = functions.httpsCallable(emulatorURL("dataTest"),
requestAs: DataTestRequest.self,
responseAs: DataTestResponse.self)

Expand Down Expand Up @@ -129,7 +129,7 @@ class IntegrationTests: XCTestCase {
let byName = functions.httpsCallable("dataTest",
requestAs: DataTestRequest.self,
responseAs: DataTestResponse.self)
let byUrl = functions.httpsCallable(url: emulatorURL("dataTest"),
let byUrl = functions.httpsCallable(emulatorURL("dataTest"),
requestAs: DataTestRequest.self,
responseAs: DataTestResponse.self)

Expand All @@ -152,7 +152,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("scalarTest"),
emulatorURL("scalarTest"),
requestAs: Int16.self,
responseAs: Int.self
)
Expand Down Expand Up @@ -180,7 +180,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("scalarTest"),
emulatorURL("scalarTest"),
requestAs: Int16.self,
responseAs: Int.self
)
Expand All @@ -194,7 +194,7 @@ class IntegrationTests: XCTestCase {
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
func testScalarAsyncAlternateSignature() async throws {
let byName: Callable<Int16, Int> = functions.httpsCallable("scalarTest")
let byURL: Callable<Int16, Int> = functions.httpsCallable(url: emulatorURL("scalarTest"))
let byURL: Callable<Int16, Int> = functions.httpsCallable(emulatorURL("scalarTest"))
for function in [byName, byURL] {
let result = try await function.call(17)
XCTAssertEqual(result, 76)
Expand All @@ -221,7 +221,7 @@ class IntegrationTests: XCTestCase {
responseAs: [String: Int].self
)
let byURL = functions.httpsCallable(
url: emulatorURL("tokenTest"),
emulatorURL("tokenTest"),
requestAs: [String: Int].self,
responseAs: [String: Int].self
)
Expand Down Expand Up @@ -261,7 +261,7 @@ class IntegrationTests: XCTestCase {
responseAs: [String: Int].self
)
let byURL = functions.httpsCallable(
url: emulatorURL("tokenTest"),
emulatorURL("tokenTest"),
requestAs: [String: Int].self,
responseAs: [String: Int].self
)
Expand All @@ -280,7 +280,7 @@ class IntegrationTests: XCTestCase {
responseAs: [String: Int].self
)
let byURL = functions.httpsCallable(
url: emulatorURL("FCMTokenTest"),
emulatorURL("FCMTokenTest"),
requestAs: [String: Int].self,
responseAs: [String: Int].self
)
Expand Down Expand Up @@ -308,7 +308,7 @@ class IntegrationTests: XCTestCase {
responseAs: [String: Int].self
)
let byURL = functions.httpsCallable(
url: emulatorURL("FCMTokenTest"),
emulatorURL("FCMTokenTest"),
requestAs: [String: Int].self,
responseAs: [String: Int].self
)
Expand All @@ -327,7 +327,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int?.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("nullTest"),
emulatorURL("nullTest"),
requestAs: Int?.self,
responseAs: Int?.self
)
Expand Down Expand Up @@ -355,7 +355,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int?.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("nullTest"),
emulatorURL("nullTest"),
requestAs: Int?.self,
responseAs: Int?.self
)
Expand All @@ -374,7 +374,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int?.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("missingResultTest"),
emulatorURL("missingResultTest"),
requestAs: Int?.self,
responseAs: Int?.self
)
Expand Down Expand Up @@ -406,7 +406,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int?.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("missingResultTest"),
emulatorURL("missingResultTest"),
requestAs: Int?.self,
responseAs: Int?.self
)
Expand All @@ -430,7 +430,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("unhandledErrorTest"),
emulatorURL("unhandledErrorTest"),
requestAs: [Int].self,
responseAs: Int.self
)
Expand Down Expand Up @@ -486,7 +486,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("unknownErrorTest"),
emulatorURL("unknownErrorTest"),
requestAs: [Int].self,
responseAs: Int.self
)
Expand Down Expand Up @@ -517,7 +517,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("unknownErrorTest"),
emulatorURL("unknownErrorTest"),
requestAs: [Int].self,
responseAs: Int.self
)
Expand Down Expand Up @@ -574,7 +574,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("explicitErrorTest"),
emulatorURL("explicitErrorTest"),
requestAs: [Int].self,
responseAs: Int.self
)
Expand All @@ -600,7 +600,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("httpErrorTest"),
emulatorURL("httpErrorTest"),
requestAs: [Int].self,
responseAs: Int.self
)
Expand Down Expand Up @@ -631,7 +631,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("httpErrorTest"),
emulatorURL("httpErrorTest"),
requestAs: [Int].self,
responseAs: Int.self
)
Expand All @@ -654,7 +654,7 @@ class IntegrationTests: XCTestCase {
responseAs: Int.self
)
let byURL = functions.httpsCallable(
url: emulatorURL("timeoutTest"),
emulatorURL("timeoutTest"),
requestAs: [Int].self,
responseAs: Int.self
)
Expand Down Expand Up @@ -688,7 +688,7 @@ class IntegrationTests: XCTestCase {
)
byName.timeoutInterval = 0.05
var byURL = functions.httpsCallable(
url: emulatorURL("timeoutTest"),
emulatorURL("timeoutTest"),
requestAs: [Int].self,
responseAs: Int.self
)
Expand Down Expand Up @@ -719,7 +719,7 @@ class IntegrationTests: XCTestCase {
let byName = functions.httpsCallable("dataTest",
requestAs: DataTestRequest.self,
responseAs: DataTestResponse.self)
let byURL = functions.httpsCallable(url: emulatorURL("dataTest"),
let byURL = functions.httpsCallable(emulatorURL("dataTest"),
requestAs: DataTestRequest.self,
responseAs: DataTestResponse.self)
for function in [byName, byURL] {
Expand Down Expand Up @@ -758,7 +758,7 @@ class IntegrationTests: XCTestCase {
requestAs: DataTestRequest.self,
responseAs: DataTestResponse.self)

let byURL = functions.httpsCallable(url: emulatorURL("dataTest"),
let byURL = functions.httpsCallable(emulatorURL("dataTest"),
requestAs: DataTestRequest.self,
responseAs: DataTestResponse.self)

Expand All @@ -785,7 +785,7 @@ class IntegrationTests: XCTestCase {
)
let byName: Callable<DataTestRequest, DataTestResponse> = functions.httpsCallable("dataTest")
let byURL: Callable<DataTestRequest, DataTestResponse> = functions
.httpsCallable(url: emulatorURL("dataTest"))
.httpsCallable(emulatorURL("dataTest"))

for function in [byName, byURL] {
let expectation = expectation(description: #function)
Expand Down Expand Up @@ -822,7 +822,7 @@ class IntegrationTests: XCTestCase {
let byName: Callable<DataTestRequest, DataTestResponse> = functions
.httpsCallable("dataTest")
let byURL: Callable<DataTestRequest, DataTestResponse> = functions
.httpsCallable(url: emulatorURL("dataTest"))
.httpsCallable(emulatorURL("dataTest"))

for function in [byName, byURL] {
let response = try await function(data)
Expand Down
21 changes: 15 additions & 6 deletions FirebaseFunctions/Tests/Unit/FunctionsAPITests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,28 @@ final class FunctionsAPITests: XCTestCase {
let callableRef = Functions.functions().httpsCallable("setCourseForAlderaan")
callableRef.timeoutInterval = 60
let url = URL(string: "https://localhost:8080/setCourseForAlderaan")!
let callableRefByURL = Functions.functions().httpsCallable(url: url)
let callableRefByURL = Functions.functions().httpsCallable(url)

struct Message: Codable {
let hello: String
let world: String
}

struct Response: Codable {
let response: String
}

let callableCodable = Functions.functions()
.httpsCallable("codable", requestAs: Message.self, responseAs: Response.self)
let callableCodable2 = Functions.functions()
.httpsCallable(url, requestAs: Message.self, responseAs: Response.self)
let message = Message(hello: "hello", world: "world")
callableRef.call(message) { result, error in
if let result = result {
_ = result.data
} else if let _ /* error */ = error {
// ...
callableCodable.call(message) { result in
switch result {
case let .success(response):
let _: Response = response
case let .failure(error):
()
}
}

Expand Down