@@ -19,8 +19,8 @@ import FirebaseFunctionsSwift
19
19
import FirebaseFunctionsTestingSupport
20
20
import XCTest
21
21
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`
24
24
///
25
25
/// The tests require the emulator to be running with `FirebaseFunctions/Backend/start.sh synchronous`
26
26
/// The Firebase Functions called in the tests are implemented in `FirebaseFunctions/Backend/index.js`.
@@ -75,7 +75,7 @@ class IntegrationTests: XCTestCase {
75
75
functions. useLocalhost ( )
76
76
}
77
77
78
- func testData( ) throws {
78
+ func testData( ) {
79
79
let expectation = expectation ( description: #function)
80
80
let data = DataTestRequest (
81
81
bool: true ,
@@ -97,10 +97,10 @@ class IntegrationTests: XCTestCase {
97
97
code: 42
98
98
)
99
99
XCTAssertEqual ( response, expected)
100
- expectation. fulfill ( )
101
100
} catch {
102
101
XCTAssert ( false , " Failed to unwrap the function result: \( error) " )
103
102
}
103
+ expectation. fulfill ( )
104
104
}
105
105
waitForExpectations ( timeout: 5 )
106
106
}
@@ -131,7 +131,7 @@ class IntegrationTests: XCTestCase {
131
131
}
132
132
#endif
133
133
134
- func testScalar( ) throws {
134
+ func testScalar( ) {
135
135
let expectation = expectation ( description: #function)
136
136
let function = functions. httpsCallable (
137
137
" scalarTest " ,
@@ -142,10 +142,10 @@ class IntegrationTests: XCTestCase {
142
142
do {
143
143
let response = try result. get ( )
144
144
XCTAssertEqual ( response, 76 )
145
- expectation. fulfill ( )
146
145
} catch {
147
146
XCTAssert ( false , " Failed to unwrap the function result: \( error) " )
148
147
}
148
+ expectation. fulfill ( )
149
149
}
150
150
waitForExpectations ( timeout: 5 )
151
151
}
@@ -172,7 +172,7 @@ class IntegrationTests: XCTestCase {
172
172
173
173
#endif
174
174
175
- func testToken( ) throws {
175
+ func testToken( ) {
176
176
// Recreate functions with a token.
177
177
let functions = FunctionsFake (
178
178
projectID: " functions-integration-test " ,
@@ -193,10 +193,10 @@ class IntegrationTests: XCTestCase {
193
193
do {
194
194
let data = try result. get ( )
195
195
XCTAssertEqual ( data, [ : ] )
196
- expectation. fulfill ( )
197
196
} catch {
198
197
XCTAssert ( false , " Failed to unwrap the function result: \( error) " )
199
198
}
199
+ expectation. fulfill ( )
200
200
}
201
201
waitForExpectations ( timeout: 5 )
202
202
}
@@ -224,7 +224,7 @@ class IntegrationTests: XCTestCase {
224
224
}
225
225
#endif
226
226
227
- func testFCMToken( ) throws {
227
+ func testFCMToken( ) {
228
228
let expectation = expectation ( description: #function)
229
229
let function = functions. httpsCallable (
230
230
" FCMTokenTest " ,
@@ -235,10 +235,10 @@ class IntegrationTests: XCTestCase {
235
235
do {
236
236
let data = try result. get ( )
237
237
XCTAssertEqual ( data, [ : ] )
238
- expectation. fulfill ( )
239
238
} catch {
240
239
XCTAssert ( false , " Failed to unwrap the function result: \( error) " )
241
240
}
241
+ expectation. fulfill ( )
242
242
}
243
243
waitForExpectations ( timeout: 5 )
244
244
}
@@ -257,7 +257,7 @@ class IntegrationTests: XCTestCase {
257
257
}
258
258
#endif
259
259
260
- func testNull( ) throws {
260
+ func testNull( ) {
261
261
let expectation = expectation ( description: #function)
262
262
let function = functions. httpsCallable (
263
263
" nullTest " ,
@@ -268,10 +268,10 @@ class IntegrationTests: XCTestCase {
268
268
do {
269
269
let data = try result. get ( )
270
270
XCTAssertEqual ( data, nil )
271
- expectation. fulfill ( )
272
271
} catch {
273
272
XCTAssert ( false , " Failed to unwrap the function result: \( error) " )
274
273
}
274
+ expectation. fulfill ( )
275
275
}
276
276
waitForExpectations ( timeout: 5 )
277
277
}
@@ -294,11 +294,40 @@ class IntegrationTests: XCTestCase {
294
294
// If no parameters are required, then the non-typed API
295
295
// is more appropriate since it specifically avoids defining
296
296
// 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( ) {
302
331
let expectation = expectation ( description: #function)
303
332
let function = functions. httpsCallable (
304
333
" missingResultTest " ,
@@ -313,7 +342,9 @@ class IntegrationTests: XCTestCase {
313
342
XCTAssertEqual ( FunctionsErrorCode . internal. rawValue, error. code)
314
343
XCTAssertEqual ( " Response is missing data field. " , error. localizedDescription)
315
344
expectation. fulfill ( )
345
+ return
316
346
}
347
+ XCTFail ( " Failed to throw error for missing result " )
317
348
}
318
349
waitForExpectations ( timeout: 5 )
319
350
}
@@ -337,7 +368,7 @@ class IntegrationTests: XCTestCase {
337
368
}
338
369
#endif
339
370
340
- func testUnhandledError( ) throws {
371
+ func testUnhandledError( ) {
341
372
let expectation = expectation ( description: #function)
342
373
let function = functions. httpsCallable (
343
374
" unhandledErrorTest " ,
@@ -352,7 +383,9 @@ class IntegrationTests: XCTestCase {
352
383
XCTAssertEqual ( FunctionsErrorCode . internal. rawValue, error. code)
353
384
XCTAssertEqual ( " INTERNAL " , error. localizedDescription)
354
385
expectation. fulfill ( )
386
+ return
355
387
}
388
+ XCTFail ( " Failed to throw error for missing result " )
356
389
}
357
390
XCTAssert ( true )
358
391
waitForExpectations ( timeout: 5 )
@@ -377,7 +410,7 @@ class IntegrationTests: XCTestCase {
377
410
}
378
411
#endif
379
412
380
- func testUnknownError( ) throws {
413
+ func testUnknownError( ) {
381
414
let expectation = expectation ( description: #function)
382
415
let function = functions. httpsCallable (
383
416
" unknownErrorTest " ,
@@ -392,7 +425,9 @@ class IntegrationTests: XCTestCase {
392
425
XCTAssertEqual ( FunctionsErrorCode . internal. rawValue, error. code)
393
426
XCTAssertEqual ( " INTERNAL " , error. localizedDescription)
394
427
expectation. fulfill ( )
428
+ return
395
429
}
430
+ XCTFail ( " Failed to throw error for missing result " )
396
431
}
397
432
waitForExpectations ( timeout: 5 )
398
433
}
@@ -416,7 +451,7 @@ class IntegrationTests: XCTestCase {
416
451
}
417
452
#endif
418
453
419
- func testExplicitError( ) throws {
454
+ func testExplicitError( ) {
420
455
let expectation = expectation ( description: #function)
421
456
let function = functions. httpsCallable (
422
457
" explicitErrorTest " ,
@@ -433,7 +468,9 @@ class IntegrationTests: XCTestCase {
433
468
XCTAssertEqual ( [ " start " : 10 as Int32 , " end " : 20 as Int32 , " long " : 30 ] ,
434
469
error. userInfo [ FunctionsErrorDetailsKey] as! [ String : Int32 ] )
435
470
expectation. fulfill ( )
471
+ return
436
472
}
473
+ XCTFail ( " Failed to throw error for missing result " )
437
474
}
438
475
waitForExpectations ( timeout: 5 )
439
476
}
@@ -459,7 +496,7 @@ class IntegrationTests: XCTestCase {
459
496
}
460
497
#endif
461
498
462
- func testHttpError( ) throws {
499
+ func testHttpError( ) {
463
500
let expectation = expectation ( description: #function)
464
501
let function = functions. httpsCallable (
465
502
" httpErrorTest " ,
@@ -474,7 +511,9 @@ class IntegrationTests: XCTestCase {
474
511
let error = error as NSError
475
512
XCTAssertEqual ( FunctionsErrorCode . invalidArgument. rawValue, error. code)
476
513
expectation. fulfill ( )
514
+ return
477
515
}
516
+ XCTFail ( " Failed to throw error for missing result " )
478
517
}
479
518
waitForExpectations ( timeout: 5 )
480
519
}
@@ -497,7 +536,7 @@ class IntegrationTests: XCTestCase {
497
536
}
498
537
#endif
499
538
500
- func testTimeout( ) throws {
539
+ func testTimeout( ) {
501
540
let expectation = expectation ( description: #function)
502
541
var function = functions. httpsCallable (
503
542
" timeoutTest " ,
@@ -514,7 +553,9 @@ class IntegrationTests: XCTestCase {
514
553
XCTAssertEqual ( " DEADLINE EXCEEDED " , error. localizedDescription)
515
554
XCTAssertNil ( error. userInfo [ FunctionsErrorDetailsKey] )
516
555
expectation. fulfill ( )
556
+ return
517
557
}
558
+ XCTFail ( " Failed to throw error for missing result " )
518
559
}
519
560
waitForExpectations ( timeout: 5 )
520
561
}
@@ -540,7 +581,7 @@ class IntegrationTests: XCTestCase {
540
581
}
541
582
#endif
542
583
543
- func testCallAsFunction( ) throws {
584
+ func testCallAsFunction( ) {
544
585
let expectation = expectation ( description: #function)
545
586
let data = DataTestRequest (
546
587
bool: true ,
@@ -596,7 +637,7 @@ class IntegrationTests: XCTestCase {
596
637
}
597
638
#endif
598
639
599
- func testInferredTypes( ) throws {
640
+ func testInferredTypes( ) {
600
641
let expectation = expectation ( description: #function)
601
642
let data = DataTestRequest (
602
643
bool: true ,
0 commit comments