Skip to content

Commit f80e467

Browse files
committed
Review updates
1 parent ac4df1f commit f80e467

File tree

3 files changed

+70
-29
lines changed

3 files changed

+70
-29
lines changed

FirebaseFunctions/Tests/SwiftIntegration/IntegrationTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import FirebaseFunctions
1818
import FirebaseFunctionsTestingSupport
1919
import XCTest
2020

21-
/// This file was intitialized as a direct port of the Objective C
21+
/// This file was initialized as a direct port of the Objective C
2222
/// FirebaseFunctions/Tests/Integration/FIRIntegrationTests.m
2323
///
2424
/// The tests require the emulator to be running with `FirebaseFunctions/Backend/start.sh synchronous`

FirebaseFunctionsSwift/Sources/Codable/Callable+Codable.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public struct Callable<Request: Encodable, Response: Decodable> {
7373
///
7474
/// - Parameter data: Parameters to pass to the trigger.
7575
/// - Parameter completion: The block to call when the HTTPS request has completed.
76-
public func call(_ data: Request,
76+
public func call(_ data: Request? = nil,
7777
completion: @escaping (Result<Response, Error>)
7878
-> Void) {
7979
do {
@@ -119,7 +119,7 @@ public struct Callable<Request: Encodable, Response: Decodable> {
119119
/// - Parameters:
120120
/// - data: Parameters to pass to the trigger.
121121
/// - completion: The block to call when the HTTPS request has completed.
122-
public func callAsFunction(_ data: Request,
122+
public func callAsFunction(_ data: Request? = nil,
123123
completion: @escaping (Result<Response, Error>)
124124
-> Void) {
125125
call(data, completion: completion)
@@ -146,7 +146,7 @@ public struct Callable<Request: Encodable, Response: Decodable> {
146146
///
147147
/// - Returns: The decoded `Response` value
148148
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
149-
public func call(_ data: Request,
149+
public func call(_ data: Request? = nil,
150150
encoder: FirebaseDataEncoder = FirebaseDataEncoder(),
151151
decoder: FirebaseDataDecoder =
152152
FirebaseDataDecoder()) async throws -> Response {
@@ -175,7 +175,7 @@ public struct Callable<Request: Encodable, Response: Decodable> {
175175
/// - data: Parameters to pass to the trigger.
176176
/// - Returns: The decoded `Response` value
177177
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
178-
public func callAsFunction(_ data: Request) async throws -> Response {
178+
public func callAsFunction(_ data: Request? = nil) async throws -> Response {
179179
return try await call(data)
180180
}
181181
#endif

FirebaseFunctionsSwift/Tests/IntegrationTests.swift

Lines changed: 65 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import FirebaseFunctionsSwift
1919
import FirebaseFunctionsTestingSupport
2020
import XCTest
2121

22-
/// This file was intitialized as a direct port of the Objective C
23-
/// FirebaseFunctions/Tests/Integration/FIRIntegrationTests.m
22+
/// This file was intitialized as a direct port of `FirebaseFunctionsSwift/Tests/IntegrationTests.swift`
23+
/// which itself was ported from the Objective C `FirebaseFunctions/Tests/Integration/FIRIntegrationTests.m`
2424
///
2525
/// The tests require the emulator to be running with `FirebaseFunctions/Backend/start.sh synchronous`
2626
/// The Firebase Functions called in the tests are implemented in `FirebaseFunctions/Backend/index.js`.
@@ -75,7 +75,7 @@ class IntegrationTests: XCTestCase {
7575
functions.useLocalhost()
7676
}
7777

78-
func testData() throws {
78+
func testData() {
7979
let expectation = expectation(description: #function)
8080
let data = DataTestRequest(
8181
bool: true,
@@ -97,10 +97,10 @@ class IntegrationTests: XCTestCase {
9797
code: 42
9898
)
9999
XCTAssertEqual(response, expected)
100-
expectation.fulfill()
101100
} catch {
102101
XCTAssert(false, "Failed to unwrap the function result: \(error)")
103102
}
103+
expectation.fulfill()
104104
}
105105
waitForExpectations(timeout: 5)
106106
}
@@ -131,7 +131,7 @@ class IntegrationTests: XCTestCase {
131131
}
132132
#endif
133133

134-
func testScalar() throws {
134+
func testScalar() {
135135
let expectation = expectation(description: #function)
136136
let function = functions.httpsCallable(
137137
"scalarTest",
@@ -142,10 +142,10 @@ class IntegrationTests: XCTestCase {
142142
do {
143143
let response = try result.get()
144144
XCTAssertEqual(response, 76)
145-
expectation.fulfill()
146145
} catch {
147146
XCTAssert(false, "Failed to unwrap the function result: \(error)")
148147
}
148+
expectation.fulfill()
149149
}
150150
waitForExpectations(timeout: 5)
151151
}
@@ -172,7 +172,7 @@ class IntegrationTests: XCTestCase {
172172

173173
#endif
174174

175-
func testToken() throws {
175+
func testToken() {
176176
// Recreate functions with a token.
177177
let functions = FunctionsFake(
178178
projectID: "functions-integration-test",
@@ -193,10 +193,10 @@ class IntegrationTests: XCTestCase {
193193
do {
194194
let data = try result.get()
195195
XCTAssertEqual(data, [:])
196-
expectation.fulfill()
197196
} catch {
198197
XCTAssert(false, "Failed to unwrap the function result: \(error)")
199198
}
199+
expectation.fulfill()
200200
}
201201
waitForExpectations(timeout: 5)
202202
}
@@ -224,7 +224,7 @@ class IntegrationTests: XCTestCase {
224224
}
225225
#endif
226226

227-
func testFCMToken() throws {
227+
func testFCMToken() {
228228
let expectation = expectation(description: #function)
229229
let function = functions.httpsCallable(
230230
"FCMTokenTest",
@@ -235,10 +235,10 @@ class IntegrationTests: XCTestCase {
235235
do {
236236
let data = try result.get()
237237
XCTAssertEqual(data, [:])
238-
expectation.fulfill()
239238
} catch {
240239
XCTAssert(false, "Failed to unwrap the function result: \(error)")
241240
}
241+
expectation.fulfill()
242242
}
243243
waitForExpectations(timeout: 5)
244244
}
@@ -257,7 +257,7 @@ class IntegrationTests: XCTestCase {
257257
}
258258
#endif
259259

260-
func testNull() throws {
260+
func testNull() {
261261
let expectation = expectation(description: #function)
262262
let function = functions.httpsCallable(
263263
"nullTest",
@@ -268,10 +268,10 @@ class IntegrationTests: XCTestCase {
268268
do {
269269
let data = try result.get()
270270
XCTAssertEqual(data, nil)
271-
expectation.fulfill()
272271
} catch {
273272
XCTAssert(false, "Failed to unwrap the function result: \(error)")
274273
}
274+
expectation.fulfill()
275275
}
276276
waitForExpectations(timeout: 5)
277277
}
@@ -294,11 +294,40 @@ class IntegrationTests: XCTestCase {
294294
// If no parameters are required, then the non-typed API
295295
// is more appropriate since it specifically avoids defining
296296
// type.
297-
// func testParameterless() {
298-
// }
299-
//
300-
//
301-
func testMissingResult() throws {
297+
func testParameterless() {
298+
let expectation = expectation(description: #function)
299+
let function = functions.httpsCallable(
300+
"nullTest",
301+
requestAs: Int?.self,
302+
responseAs: Int?.self
303+
)
304+
function.call { result in
305+
do {
306+
let data = try result.get()
307+
XCTAssertEqual(data, nil)
308+
} catch {
309+
XCTAssert(false, "Failed to unwrap the function result: \(error)")
310+
}
311+
expectation.fulfill()
312+
}
313+
waitForExpectations(timeout: 5)
314+
}
315+
316+
#if compiler(>=5.5) && canImport(_Concurrency)
317+
@available(iOS 15, tvOS 15, macOS 12, watchOS 8, *)
318+
func testParameterlessAsync() async throws {
319+
let function = functions.httpsCallable(
320+
"nullTest",
321+
requestAs: Int?.self,
322+
responseAs: Int?.self
323+
)
324+
325+
let data = try await function.call()
326+
XCTAssertEqual(data, nil)
327+
}
328+
#endif
329+
330+
func testMissingResult() {
302331
let expectation = expectation(description: #function)
303332
let function = functions.httpsCallable(
304333
"missingResultTest",
@@ -313,7 +342,9 @@ class IntegrationTests: XCTestCase {
313342
XCTAssertEqual(FunctionsErrorCode.internal.rawValue, error.code)
314343
XCTAssertEqual("Response is missing data field.", error.localizedDescription)
315344
expectation.fulfill()
345+
return
316346
}
347+
XCTFail("Failed to throw error for missing result")
317348
}
318349
waitForExpectations(timeout: 5)
319350
}
@@ -337,7 +368,7 @@ class IntegrationTests: XCTestCase {
337368
}
338369
#endif
339370

340-
func testUnhandledError() throws {
371+
func testUnhandledError() {
341372
let expectation = expectation(description: #function)
342373
let function = functions.httpsCallable(
343374
"unhandledErrorTest",
@@ -352,7 +383,9 @@ class IntegrationTests: XCTestCase {
352383
XCTAssertEqual(FunctionsErrorCode.internal.rawValue, error.code)
353384
XCTAssertEqual("INTERNAL", error.localizedDescription)
354385
expectation.fulfill()
386+
return
355387
}
388+
XCTFail("Failed to throw error for missing result")
356389
}
357390
XCTAssert(true)
358391
waitForExpectations(timeout: 5)
@@ -377,7 +410,7 @@ class IntegrationTests: XCTestCase {
377410
}
378411
#endif
379412

380-
func testUnknownError() throws {
413+
func testUnknownError() {
381414
let expectation = expectation(description: #function)
382415
let function = functions.httpsCallable(
383416
"unknownErrorTest",
@@ -392,7 +425,9 @@ class IntegrationTests: XCTestCase {
392425
XCTAssertEqual(FunctionsErrorCode.internal.rawValue, error.code)
393426
XCTAssertEqual("INTERNAL", error.localizedDescription)
394427
expectation.fulfill()
428+
return
395429
}
430+
XCTFail("Failed to throw error for missing result")
396431
}
397432
waitForExpectations(timeout: 5)
398433
}
@@ -416,7 +451,7 @@ class IntegrationTests: XCTestCase {
416451
}
417452
#endif
418453

419-
func testExplicitError() throws {
454+
func testExplicitError() {
420455
let expectation = expectation(description: #function)
421456
let function = functions.httpsCallable(
422457
"explicitErrorTest",
@@ -433,7 +468,9 @@ class IntegrationTests: XCTestCase {
433468
XCTAssertEqual(["start": 10 as Int32, "end": 20 as Int32, "long": 30],
434469
error.userInfo[FunctionsErrorDetailsKey] as! [String: Int32])
435470
expectation.fulfill()
471+
return
436472
}
473+
XCTFail("Failed to throw error for missing result")
437474
}
438475
waitForExpectations(timeout: 5)
439476
}
@@ -459,7 +496,7 @@ class IntegrationTests: XCTestCase {
459496
}
460497
#endif
461498

462-
func testHttpError() throws {
499+
func testHttpError() {
463500
let expectation = expectation(description: #function)
464501
let function = functions.httpsCallable(
465502
"httpErrorTest",
@@ -474,7 +511,9 @@ class IntegrationTests: XCTestCase {
474511
let error = error as NSError
475512
XCTAssertEqual(FunctionsErrorCode.invalidArgument.rawValue, error.code)
476513
expectation.fulfill()
514+
return
477515
}
516+
XCTFail("Failed to throw error for missing result")
478517
}
479518
waitForExpectations(timeout: 5)
480519
}
@@ -497,7 +536,7 @@ class IntegrationTests: XCTestCase {
497536
}
498537
#endif
499538

500-
func testTimeout() throws {
539+
func testTimeout() {
501540
let expectation = expectation(description: #function)
502541
var function = functions.httpsCallable(
503542
"timeoutTest",
@@ -514,7 +553,9 @@ class IntegrationTests: XCTestCase {
514553
XCTAssertEqual("DEADLINE EXCEEDED", error.localizedDescription)
515554
XCTAssertNil(error.userInfo[FunctionsErrorDetailsKey])
516555
expectation.fulfill()
556+
return
517557
}
558+
XCTFail("Failed to throw error for missing result")
518559
}
519560
waitForExpectations(timeout: 5)
520561
}
@@ -540,7 +581,7 @@ class IntegrationTests: XCTestCase {
540581
}
541582
#endif
542583

543-
func testCallAsFunction() throws {
584+
func testCallAsFunction() {
544585
let expectation = expectation(description: #function)
545586
let data = DataTestRequest(
546587
bool: true,
@@ -596,7 +637,7 @@ class IntegrationTests: XCTestCase {
596637
}
597638
#endif
598639

599-
func testInferredTypes() throws {
640+
func testInferredTypes() {
600641
let expectation = expectation(description: #function)
601642
let data = DataTestRequest(
602643
bool: true,

0 commit comments

Comments
 (0)