@@ -32,93 +32,91 @@ let emptyBundle = """
3232}
3333"""
3434
35- #if swift(>=5.5.2)
36- @available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
37- class AsyncAwaitIntegrationTests : FSTIntegrationTestCase {
38- func testAddData( ) async throws {
39- let collection = collectionRef ( )
40- let document = try await collection. addDocument ( data: [ : ] )
41- let snapshot = try await document. getDocument ( )
42- XCTAssertTrue ( snapshot. exists)
43- }
44-
45- func testLoadBundleFromData( ) async throws {
46- let bundle = " \( emptyBundle. count) \( emptyBundle) "
47- let bundleProgress = try await db. loadBundle ( Data ( bundle. utf8) )
48- XCTAssertEqual ( LoadBundleTaskState . success, bundleProgress. state)
49- }
35+ @available ( iOS 13 , tvOS 13 , macOS 10 . 15 , macCatalyst 13 , watchOS 7 , * )
36+ class AsyncAwaitIntegrationTests : FSTIntegrationTestCase {
37+ func testAddData( ) async throws {
38+ let collection = collectionRef ( )
39+ let document = try await collection. addDocument ( data: [ : ] )
40+ let snapshot = try await document. getDocument ( )
41+ XCTAssertTrue ( snapshot. exists)
42+ }
5043
51- func testLoadBundleFromEmptyDataFails( ) async throws {
52- do {
53- _ = try await db. loadBundle ( Data ( ) )
54- XCTFail ( " Bundle loading should have failed " )
55- } catch {
56- XCTAssertEqual ( ( error as NSError ) . domain, FirestoreErrorDomain)
57- XCTAssertEqual ( ( error as NSError ) . code, FirestoreErrorCode . unknown. rawValue)
58- }
59- }
44+ func testLoadBundleFromData( ) async throws {
45+ let bundle = " \( emptyBundle. count) \( emptyBundle) "
46+ let bundleProgress = try await db. loadBundle ( Data ( bundle. utf8) )
47+ XCTAssertEqual ( LoadBundleTaskState . success, bundleProgress. state)
48+ }
6049
61- func testLoadBundleFromStream( ) async throws {
62- let bundle = " \( emptyBundle. count) \( emptyBundle) "
63- let bundleProgress = try await db
64- . loadBundle ( InputStream ( data: bundle. data ( using: String . Encoding. utf8) !) )
65- XCTAssertEqual ( LoadBundleTaskState . success, bundleProgress. state)
50+ func testLoadBundleFromEmptyDataFails( ) async throws {
51+ do {
52+ _ = try await db. loadBundle ( Data ( ) )
53+ XCTFail ( " Bundle loading should have failed " )
54+ } catch {
55+ XCTAssertEqual ( ( error as NSError ) . domain, FirestoreErrorDomain)
56+ XCTAssertEqual ( ( error as NSError ) . code, FirestoreErrorCode . unknown. rawValue)
6657 }
58+ }
6759
68- func testRunTransactionDoesNotCrashOnNilSuccess( ) async throws {
69- let value = try await db. runTransaction { transact, error in
70- nil // should not crash
71- }
60+ func testLoadBundleFromStream( ) async throws {
61+ let bundle = " \( emptyBundle. count) \( emptyBundle) "
62+ let bundleProgress = try await db
63+ . loadBundle ( InputStream ( data: bundle. data ( using: String . Encoding. utf8) !) )
64+ XCTAssertEqual ( LoadBundleTaskState . success, bundleProgress. state)
65+ }
7266
73- XCTAssertNil ( value, " value should be nil on success " )
67+ func testRunTransactionDoesNotCrashOnNilSuccess( ) async throws {
68+ let value = try await db. runTransaction { transact, error in
69+ nil // should not crash
7470 }
7571
76- func testQuery( ) async throws {
77- let collRef = collectionRef (
78- withDocuments: [ " doc1 " : [ " a " : 1 , " b " : 0 ] ,
79- " doc2 " : [ " a " : 2 , " b " : 1 ] ,
80- " doc3 " : [ " a " : 3 , " b " : 2 ] ,
81- " doc4 " : [ " a " : 1 , " b " : 3 ] ,
82- " doc5 " : [ " a " : 1 , " b " : 1 ] ]
83- )
72+ XCTAssertNil ( value, " value should be nil on success " )
73+ }
74+
75+ func testQuery( ) async throws {
76+ let collRef = collectionRef (
77+ withDocuments: [ " doc1 " : [ " a " : 1 , " b " : 0 ] ,
78+ " doc2 " : [ " a " : 2 , " b " : 1 ] ,
79+ " doc3 " : [ " a " : 3 , " b " : 2 ] ,
80+ " doc4 " : [ " a " : 1 , " b " : 3 ] ,
81+ " doc5 " : [ " a " : 1 , " b " : 1 ] ]
82+ )
8483
85- // Two equalities: a==1 || b==1.
86- let filter = Filter . orFilter (
87- [ Filter . whereField ( " a " , isEqualTo: 1 ) ,
88- Filter . whereField ( " b " , isEqualTo: 1 ) ]
89- )
90- let query = collRef. whereFilter ( filter)
91- let snapshot = try await query. getDocuments ( source: FirestoreSource . server)
92- XCTAssertEqual ( FIRQuerySnapshotGetIDs ( snapshot) ,
93- [ " doc1 " , " doc2 " , " doc4 " , " doc5 " ] )
94- }
84+ // Two equalities: a==1 || b==1.
85+ let filter = Filter . orFilter (
86+ [ Filter . whereField ( " a " , isEqualTo: 1 ) ,
87+ Filter . whereField ( " b " , isEqualTo: 1 ) ]
88+ )
89+ let query = collRef. whereFilter ( filter)
90+ let snapshot = try await query. getDocuments ( source: FirestoreSource . server)
91+ XCTAssertEqual ( FIRQuerySnapshotGetIDs ( snapshot) ,
92+ [ " doc1 " , " doc2 " , " doc4 " , " doc5 " ] )
93+ }
9594
96- func testAutoIndexCreationAfterFailsTermination( ) async throws {
97- try await db. terminate ( )
95+ func testAutoIndexCreationAfterFailsTermination( ) async throws {
96+ try await db. terminate ( )
9897
99- let enableIndexAutoCreation = {
100- try FSTExceptionCatcher . catchException {
101- self . db. persistentCacheIndexManager? . enableIndexAutoCreation ( )
102- }
98+ let enableIndexAutoCreation = {
99+ try FSTExceptionCatcher . catchException {
100+ self . db. persistentCacheIndexManager? . enableIndexAutoCreation ( )
103101 }
104- XCTAssertThrowsError ( try enableIndexAutoCreation ( ) , " The client has already been terminated. " )
102+ }
103+ XCTAssertThrowsError ( try enableIndexAutoCreation ( ) , " The client has already been terminated. " )
105104
106- let disableIndexAutoCreation = {
107- try FSTExceptionCatcher . catchException {
108- self . db. persistentCacheIndexManager? . disableIndexAutoCreation ( )
109- }
105+ let disableIndexAutoCreation = {
106+ try FSTExceptionCatcher . catchException {
107+ self . db. persistentCacheIndexManager? . disableIndexAutoCreation ( )
110108 }
111- XCTAssertThrowsError (
112- try disableIndexAutoCreation ( ) ,
113- " The client has already been terminated. "
114- )
109+ }
110+ XCTAssertThrowsError (
111+ try disableIndexAutoCreation ( ) ,
112+ " The client has already been terminated. "
113+ )
115114
116- let deleteAllIndexes = {
117- try FSTExceptionCatcher . catchException {
118- self . db. persistentCacheIndexManager? . deleteAllIndexes ( )
119- }
115+ let deleteAllIndexes = {
116+ try FSTExceptionCatcher . catchException {
117+ self . db. persistentCacheIndexManager? . deleteAllIndexes ( )
120118 }
121- XCTAssertThrowsError ( try deleteAllIndexes ( ) , " The client has already been terminated. " )
122119 }
120+ XCTAssertThrowsError ( try deleteAllIndexes ( ) , " The client has already been terminated. " )
123121 }
124- #endif
122+ }
0 commit comments