FSTIntegrationTestCase.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 FIRCollectionReference;
  24. @class FIRDocumentSnapshot;
  25. @class FIRDocumentReference;
  26. @class FIRQuerySnapshot;
  27. @class FIRFirestore;
  28. @class FIRFirestoreSettings;
  29. @class FIRQuery;
  30. @class FSTEventAccumulator;
  31. NS_ASSUME_NONNULL_BEGIN
  32. #if __cplusplus
  33. extern "C" {
  34. #endif
  35. @interface FSTIntegrationTestCase : XCTestCase
  36. /** Returns the default Firestore project ID for testing. */
  37. + (NSString *)projectID;
  38. + (bool)isRunningAgainstEmulator;
  39. /** Returns a FirestoreSettings configured to use either hexa or the emulator. */
  40. + (FIRFirestoreSettings *)settings;
  41. /** Returns a new Firestore connected to the "test-db" project. */
  42. - (FIRFirestore *)firestore;
  43. /** Returns a new Firestore connected to the project with the given projectID. */
  44. - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID;
  45. /** Triggers a user change with given user id. */
  46. - (void)triggerUserChangeWithUid:(NSString *)uid;
  47. /**
  48. * Returns a new Firestore connected to the project with the given app.
  49. */
  50. - (FIRFirestore *)firestoreWithApp:(FIRApp *)app;
  51. /** Synchronously terminates the given firestore. */
  52. - (void)terminateFirestore:(FIRFirestore *)firestore;
  53. /** Synchronously deletes the given FIRapp. */
  54. - (void)deleteApp:(FIRApp *)app;
  55. - (NSString *)documentPath;
  56. - (FIRDocumentReference *)documentRef;
  57. - (FIRCollectionReference *)collectionRef;
  58. - (FIRCollectionReference *)collectionRefWithDocuments:
  59. (NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents;
  60. - (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
  61. toCollection:(FIRCollectionReference *)collection;
  62. - (void)readerAndWriterOnDocumentRef:(void (^)(NSString *path,
  63. FIRDocumentReference *readerRef,
  64. FIRDocumentReference *writerRef))action;
  65. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref;
  66. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
  67. source:(FIRFirestoreSource)source;
  68. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query;
  69. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRFirestoreSource)source;
  70. - (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)query
  71. requireOnline:(BOOL)online;
  72. - (void)writeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  73. - (void)updateDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  74. - (void)deleteDocumentRef:(FIRDocumentReference *)ref;
  75. - (FIRDocumentReference *)addDocumentRef:(FIRCollectionReference *)ref
  76. data:(NSDictionary<NSString *, id> *)data;
  77. - (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  78. - (void)mergeDocumentRef:(FIRDocumentReference *)ref
  79. data:(NSDictionary<NSString *, id> *)data
  80. fields:(NSArray<id> *)fields;
  81. - (void)disableNetwork;
  82. - (void)enableNetwork;
  83. /**
  84. * "Blocks" the current thread/run loop until the block returns YES.
  85. * Should only be called on the main thread.
  86. * The block is invoked frequently and in a loop (every couple of milliseconds) to ensure fast
  87. * test progress and make sure actions to be run on main thread are not blocked by this method.
  88. */
  89. - (void)waitUntil:(BOOL (^)())predicate;
  90. @property(nonatomic, strong) FIRFirestore *db;
  91. @property(nonatomic, strong) FSTEventAccumulator *eventAccumulator;
  92. @property(nonatomic, strong) NSMutableArray<FIRFirestore *> *firestores;
  93. @end
  94. /** Converts the FIRQuerySnapshot to an NSArray containing the data of the documents in order. */
  95. NSArray<NSDictionary<NSString *, id> *> *FIRQuerySnapshotGetData(FIRQuerySnapshot *docs);
  96. /** Converts the FIRQuerySnapshot to an NSArray containing the document IDs in order. */
  97. NSArray<NSString *> *FIRQuerySnapshotGetIDs(FIRQuerySnapshot *docs);
  98. /** Converts the FIRQuerySnapshot to an NSArray containing an NSArray containing the doc change data
  99. * in order of { type, doc title, doc data }. */
  100. NSArray<NSArray<id> *> *FIRQuerySnapshotGetDocChangesData(FIRQuerySnapshot *docs);
  101. #if __cplusplus
  102. } // extern "C"
  103. #endif
  104. NS_ASSUME_NONNULL_END