Skip to content

Commit 694059f

Browse files
inlinedryanwilson
andauthored
Remove url label. add Codable test (#9667)
* Remove url label. ad Codable test * Fix compilation failures Co-authored-by: Ryan Wilson <[email protected]>
1 parent 8a9e385 commit 694059f

File tree

3 files changed

+43
-34
lines changed

3 files changed

+43
-34
lines changed

FirebaseFunctions/Sources/Functions.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ internal enum FunctionsConstants {
104104
return HTTPSCallable(functions: self, name: name)
105105
}
106106

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

@@ -135,15 +135,15 @@ internal enum FunctionsConstants {
135135
/// - Parameter encoder: The encoder instance to use to run the encoding.
136136
/// - Parameter decoder: The decoder instance to use to run the decoding.
137137
open func httpsCallable<Request: Encodable,
138-
Response: Decodable>(url: URL,
138+
Response: Decodable>(_ url: URL,
139139
requestAs: Request.Type = Request.self,
140140
responseAs: Response.Type = Response.self,
141141
encoder: FirebaseDataEncoder = FirebaseDataEncoder(
142142
),
143143
decoder: FirebaseDataDecoder = FirebaseDataDecoder(
144144
))
145145
-> Callable<Request, Response> {
146-
return Callable(callable: httpsCallable(url: url), encoder: encoder, decoder: decoder)
146+
return Callable(callable: httpsCallable(url), encoder: encoder, decoder: decoder)
147147
}
148148

149149
/**

FirebaseFunctions/Tests/Integration/IntegrationTests.swift

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class IntegrationTests: XCTestCase {
9090
let byName = functions.httpsCallable("dataTest",
9191
requestAs: DataTestRequest.self,
9292
responseAs: DataTestResponse.self)
93-
let byURL = functions.httpsCallable(url: emulatorURL("dataTest"),
93+
let byURL = functions.httpsCallable(emulatorURL("dataTest"),
9494
requestAs: DataTestRequest.self,
9595
responseAs: DataTestResponse.self)
9696

@@ -129,7 +129,7 @@ class IntegrationTests: XCTestCase {
129129
let byName = functions.httpsCallable("dataTest",
130130
requestAs: DataTestRequest.self,
131131
responseAs: DataTestResponse.self)
132-
let byUrl = functions.httpsCallable(url: emulatorURL("dataTest"),
132+
let byUrl = functions.httpsCallable(emulatorURL("dataTest"),
133133
requestAs: DataTestRequest.self,
134134
responseAs: DataTestResponse.self)
135135

@@ -152,7 +152,7 @@ class IntegrationTests: XCTestCase {
152152
responseAs: Int.self
153153
)
154154
let byURL = functions.httpsCallable(
155-
url: emulatorURL("scalarTest"),
155+
emulatorURL("scalarTest"),
156156
requestAs: Int16.self,
157157
responseAs: Int.self
158158
)
@@ -180,7 +180,7 @@ class IntegrationTests: XCTestCase {
180180
responseAs: Int.self
181181
)
182182
let byURL = functions.httpsCallable(
183-
url: emulatorURL("scalarTest"),
183+
emulatorURL("scalarTest"),
184184
requestAs: Int16.self,
185185
responseAs: Int.self
186186
)
@@ -194,7 +194,7 @@ class IntegrationTests: XCTestCase {
194194
@available(iOS 13, tvOS 13, macOS 10.15, macCatalyst 13, watchOS 7, *)
195195
func testScalarAsyncAlternateSignature() async throws {
196196
let byName: Callable<Int16, Int> = functions.httpsCallable("scalarTest")
197-
let byURL: Callable<Int16, Int> = functions.httpsCallable(url: emulatorURL("scalarTest"))
197+
let byURL: Callable<Int16, Int> = functions.httpsCallable(emulatorURL("scalarTest"))
198198
for function in [byName, byURL] {
199199
let result = try await function.call(17)
200200
XCTAssertEqual(result, 76)
@@ -221,7 +221,7 @@ class IntegrationTests: XCTestCase {
221221
responseAs: [String: Int].self
222222
)
223223
let byURL = functions.httpsCallable(
224-
url: emulatorURL("tokenTest"),
224+
emulatorURL("tokenTest"),
225225
requestAs: [String: Int].self,
226226
responseAs: [String: Int].self
227227
)
@@ -261,7 +261,7 @@ class IntegrationTests: XCTestCase {
261261
responseAs: [String: Int].self
262262
)
263263
let byURL = functions.httpsCallable(
264-
url: emulatorURL("tokenTest"),
264+
emulatorURL("tokenTest"),
265265
requestAs: [String: Int].self,
266266
responseAs: [String: Int].self
267267
)
@@ -280,7 +280,7 @@ class IntegrationTests: XCTestCase {
280280
responseAs: [String: Int].self
281281
)
282282
let byURL = functions.httpsCallable(
283-
url: emulatorURL("FCMTokenTest"),
283+
emulatorURL("FCMTokenTest"),
284284
requestAs: [String: Int].self,
285285
responseAs: [String: Int].self
286286
)
@@ -308,7 +308,7 @@ class IntegrationTests: XCTestCase {
308308
responseAs: [String: Int].self
309309
)
310310
let byURL = functions.httpsCallable(
311-
url: emulatorURL("FCMTokenTest"),
311+
emulatorURL("FCMTokenTest"),
312312
requestAs: [String: Int].self,
313313
responseAs: [String: Int].self
314314
)
@@ -327,7 +327,7 @@ class IntegrationTests: XCTestCase {
327327
responseAs: Int?.self
328328
)
329329
let byURL = functions.httpsCallable(
330-
url: emulatorURL("nullTest"),
330+
emulatorURL("nullTest"),
331331
requestAs: Int?.self,
332332
responseAs: Int?.self
333333
)
@@ -355,7 +355,7 @@ class IntegrationTests: XCTestCase {
355355
responseAs: Int?.self
356356
)
357357
let byURL = functions.httpsCallable(
358-
url: emulatorURL("nullTest"),
358+
emulatorURL("nullTest"),
359359
requestAs: Int?.self,
360360
responseAs: Int?.self
361361
)
@@ -374,7 +374,7 @@ class IntegrationTests: XCTestCase {
374374
responseAs: Int?.self
375375
)
376376
let byURL = functions.httpsCallable(
377-
url: emulatorURL("missingResultTest"),
377+
emulatorURL("missingResultTest"),
378378
requestAs: Int?.self,
379379
responseAs: Int?.self
380380
)
@@ -406,7 +406,7 @@ class IntegrationTests: XCTestCase {
406406
responseAs: Int?.self
407407
)
408408
let byURL = functions.httpsCallable(
409-
url: emulatorURL("missingResultTest"),
409+
emulatorURL("missingResultTest"),
410410
requestAs: Int?.self,
411411
responseAs: Int?.self
412412
)
@@ -430,7 +430,7 @@ class IntegrationTests: XCTestCase {
430430
responseAs: Int.self
431431
)
432432
let byURL = functions.httpsCallable(
433-
url: emulatorURL("unhandledErrorTest"),
433+
emulatorURL("unhandledErrorTest"),
434434
requestAs: [Int].self,
435435
responseAs: Int.self
436436
)
@@ -486,7 +486,7 @@ class IntegrationTests: XCTestCase {
486486
responseAs: Int.self
487487
)
488488
let byURL = functions.httpsCallable(
489-
url: emulatorURL("unknownErrorTest"),
489+
emulatorURL("unknownErrorTest"),
490490
requestAs: [Int].self,
491491
responseAs: Int.self
492492
)
@@ -517,7 +517,7 @@ class IntegrationTests: XCTestCase {
517517
responseAs: Int.self
518518
)
519519
let byURL = functions.httpsCallable(
520-
url: emulatorURL("unknownErrorTest"),
520+
emulatorURL("unknownErrorTest"),
521521
requestAs: [Int].self,
522522
responseAs: Int.self
523523
)
@@ -574,7 +574,7 @@ class IntegrationTests: XCTestCase {
574574
responseAs: Int.self
575575
)
576576
let byURL = functions.httpsCallable(
577-
url: emulatorURL("explicitErrorTest"),
577+
emulatorURL("explicitErrorTest"),
578578
requestAs: [Int].self,
579579
responseAs: Int.self
580580
)
@@ -600,7 +600,7 @@ class IntegrationTests: XCTestCase {
600600
responseAs: Int.self
601601
)
602602
let byURL = functions.httpsCallable(
603-
url: emulatorURL("httpErrorTest"),
603+
emulatorURL("httpErrorTest"),
604604
requestAs: [Int].self,
605605
responseAs: Int.self
606606
)
@@ -631,7 +631,7 @@ class IntegrationTests: XCTestCase {
631631
responseAs: Int.self
632632
)
633633
let byURL = functions.httpsCallable(
634-
url: emulatorURL("httpErrorTest"),
634+
emulatorURL("httpErrorTest"),
635635
requestAs: [Int].self,
636636
responseAs: Int.self
637637
)
@@ -654,7 +654,7 @@ class IntegrationTests: XCTestCase {
654654
responseAs: Int.self
655655
)
656656
let byURL = functions.httpsCallable(
657-
url: emulatorURL("timeoutTest"),
657+
emulatorURL("timeoutTest"),
658658
requestAs: [Int].self,
659659
responseAs: Int.self
660660
)
@@ -688,7 +688,7 @@ class IntegrationTests: XCTestCase {
688688
)
689689
byName.timeoutInterval = 0.05
690690
var byURL = functions.httpsCallable(
691-
url: emulatorURL("timeoutTest"),
691+
emulatorURL("timeoutTest"),
692692
requestAs: [Int].self,
693693
responseAs: Int.self
694694
)
@@ -719,7 +719,7 @@ class IntegrationTests: XCTestCase {
719719
let byName = functions.httpsCallable("dataTest",
720720
requestAs: DataTestRequest.self,
721721
responseAs: DataTestResponse.self)
722-
let byURL = functions.httpsCallable(url: emulatorURL("dataTest"),
722+
let byURL = functions.httpsCallable(emulatorURL("dataTest"),
723723
requestAs: DataTestRequest.self,
724724
responseAs: DataTestResponse.self)
725725
for function in [byName, byURL] {
@@ -758,7 +758,7 @@ class IntegrationTests: XCTestCase {
758758
requestAs: DataTestRequest.self,
759759
responseAs: DataTestResponse.self)
760760

761-
let byURL = functions.httpsCallable(url: emulatorURL("dataTest"),
761+
let byURL = functions.httpsCallable(emulatorURL("dataTest"),
762762
requestAs: DataTestRequest.self,
763763
responseAs: DataTestResponse.self)
764764

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

790790
for function in [byName, byURL] {
791791
let expectation = expectation(description: #function)
@@ -822,7 +822,7 @@ class IntegrationTests: XCTestCase {
822822
let byName: Callable<DataTestRequest, DataTestResponse> = functions
823823
.httpsCallable("dataTest")
824824
let byURL: Callable<DataTestRequest, DataTestResponse> = functions
825-
.httpsCallable(url: emulatorURL("dataTest"))
825+
.httpsCallable(emulatorURL("dataTest"))
826826

827827
for function in [byName, byURL] {
828828
let response = try await function(data)

FirebaseFunctions/Tests/Unit/FunctionsAPITests.swift

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,19 +51,28 @@ final class FunctionsAPITests: XCTestCase {
5151
let callableRef = Functions.functions().httpsCallable("setCourseForAlderaan")
5252
callableRef.timeoutInterval = 60
5353
let url = URL(string: "https://localhost:8080/setCourseForAlderaan")!
54-
let callableRefByURL = Functions.functions().httpsCallable(url: url)
54+
let callableRefByURL = Functions.functions().httpsCallable(url)
5555

5656
struct Message: Codable {
5757
let hello: String
5858
let world: String
5959
}
6060

61+
struct Response: Codable {
62+
let response: String
63+
}
64+
65+
let callableCodable = Functions.functions()
66+
.httpsCallable("codable", requestAs: Message.self, responseAs: Response.self)
67+
let callableCodable2 = Functions.functions()
68+
.httpsCallable(url, requestAs: Message.self, responseAs: Response.self)
6169
let message = Message(hello: "hello", world: "world")
62-
callableRef.call(message) { result, error in
63-
if let result = result {
64-
_ = result.data
65-
} else if let _ /* error */ = error {
66-
// ...
70+
callableCodable.call(message) { result in
71+
switch result {
72+
case let .success(response):
73+
let _: Response = response
74+
case let .failure(error):
75+
()
6776
}
6877
}
6978

0 commit comments

Comments
 (0)