FSTIntegrationTestCase.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. // NOTE: For Swift compatibility, please keep this header Objective-C only.
  17. // Swift cannot interact with any C++ definitions.
  18. #import <Foundation/Foundation.h>
  19. #import <XCTest/XCTest.h>
  20. #import "Firestore/Example/Tests/Util/XCTestCase+Await.h"
  21. #import "FIRFirestoreSource.h"
  22. @class FIRApp;
  23. @class FIRAggregateQuery;
  24. @class FIRAggregateQuerySnapshot;
  25. @class FIRCollectionReference;
  26. @class FIRDocumentSnapshot;
  27. @class FIRDocumentReference;
  28. @class FIRQuerySnapshot;
  29. @class FIRFirestore;
  30. @class FIRFirestoreSettings;
  31. @class FIRQuery;
  32. @class FIRWriteBatch;
  33. @class FSTEventAccumulator;
  34. @class FIRTransaction;
  35. NS_ASSUME_NONNULL_BEGIN
  36. #if __cplusplus
  37. extern "C" {
  38. #endif
  39. @interface FSTIntegrationTestCase : XCTestCase
  40. /** Returns the default Firestore project ID for testing. */
  41. + (NSString *)projectID;
  42. /** Returns the default Firestore database ID for testing. */
  43. + (NSString *)databaseID;
  44. + (bool)isRunningAgainstEmulator;
  45. /** Returns a FirestoreSettings configured to use either hexa or the emulator. */
  46. + (FIRFirestoreSettings *)settings;
  47. /** Returns a new Firestore connected to the "test-db" project. */
  48. - (FIRFirestore *)firestore;
  49. /** Returns a new Firestore connected to the project with the given projectID. */
  50. - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID;
  51. /** Triggers a user change with given user id. */
  52. - (void)triggerUserChangeWithUid:(NSString *)uid;
  53. /**
  54. * Returns a new Firestore connected to the project with the given app.
  55. */
  56. - (FIRFirestore *)firestoreWithApp:(FIRApp *)app;
  57. /** Synchronously terminates the given firestore. */
  58. - (void)terminateFirestore:(FIRFirestore *)firestore;
  59. /** Synchronously deletes the given FIRapp. */
  60. - (void)deleteApp:(FIRApp *)app;
  61. - (NSString *)documentPath;
  62. - (FIRDocumentReference *)documentRef;
  63. - (FIRCollectionReference *)collectionRef;
  64. - (FIRCollectionReference *)collectionRefWithDocuments:
  65. (NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents;
  66. - (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
  67. toCollection:(FIRCollectionReference *)collection;
  68. - (void)readerAndWriterOnDocumentRef:(void (^)(FIRDocumentReference *readerRef,
  69. FIRDocumentReference *writerRef))action;
  70. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref;
  71. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
  72. source:(FIRFirestoreSource)source;
  73. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query;
  74. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRFirestoreSource)source;
  75. - (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)query
  76. requireOnline:(BOOL)online;
  77. - (FIRAggregateQuerySnapshot *)readSnapshotForAggregate:(FIRAggregateQuery *)query;
  78. - (void)writeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  79. - (void)updateDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  80. - (void)deleteDocumentRef:(FIRDocumentReference *)ref;
  81. - (FIRDocumentReference *)addDocumentRef:(FIRCollectionReference *)ref
  82. data:(NSDictionary<NSString *, id> *)data;
  83. - (void)runTransaction:(FIRFirestore *)db
  84. block:(id _Nullable (^)(FIRTransaction *, NSError **error))block
  85. completion:(nullable void (^)(id _Nullable result, NSError *_Nullable error))completion;
  86. - (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  87. - (void)mergeDocumentRef:(FIRDocumentReference *)ref
  88. data:(NSDictionary<NSString *, id> *)data
  89. fields:(NSArray<id> *)fields;
  90. - (void)commitWriteBatch:(FIRWriteBatch *)batch;
  91. - (void)disableNetwork;
  92. - (void)enableNetwork;
  93. - (void)checkOnlineAndOfflineQuery:(FIRQuery *)query matchesResult:(NSArray *)expectedDocs;
  94. /**
  95. * "Blocks" the current thread/run loop until the block returns YES.
  96. * Should only be called on the main thread.
  97. * The block is invoked frequently and in a loop (every couple of milliseconds) to ensure fast
  98. * test progress and make sure actions to be run on main thread are not blocked by this method.
  99. */
  100. - (void)waitUntil:(BOOL (^)())predicate;
  101. @property(nonatomic, strong) FIRFirestore *db;
  102. @property(nonatomic, strong) FSTEventAccumulator *eventAccumulator;
  103. @property(nonatomic, strong) NSMutableArray<FIRFirestore *> *firestores;
  104. @end
  105. /** Converts the FIRQuerySnapshot to an NSArray containing the data of the documents in order. */
  106. NSArray<NSDictionary<NSString *, id> *> *FIRQuerySnapshotGetData(FIRQuerySnapshot *docs);
  107. /** Converts the FIRQuerySnapshot to an NSArray containing the document IDs in order. */
  108. NSArray<NSString *> *FIRQuerySnapshotGetIDs(FIRQuerySnapshot *docs);
  109. /** Converts the FIRQuerySnapshot to an NSArray containing an NSArray containing the doc change data
  110. * in order of { type, doc title, doc data }. */
  111. NSArray<NSArray<id> *> *FIRQuerySnapshotGetDocChangesData(FIRQuerySnapshot *docs);
  112. /** Gets the FIRDocumentReference objects from a FIRQuerySnapshot and returns them. */
  113. NSArray<FIRDocumentReference *> *FIRDocumentReferenceArrayFromQuerySnapshot(FIRQuerySnapshot *);
  114. #if __cplusplus
  115. } // extern "C"
  116. #endif
  117. NS_ASSUME_NONNULL_END