FSTIntegrationTestCase.h 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #import <Foundation/Foundation.h>
  17. #import <XCTest/XCTest.h>
  18. #import "Firestore/Example/Tests/Util/XCTestCase+Await.h"
  19. #import "Firestore/Source/Core/FSTTypes.h"
  20. #import "FIRFirestoreSource.h"
  21. @class FIRCollectionReference;
  22. @class FIRDocumentSnapshot;
  23. @class FIRDocumentReference;
  24. @class FIRQuerySnapshot;
  25. @class FIRFirestore;
  26. @class FIRFirestoreSettings;
  27. @class FIRQuery;
  28. @class FSTEventAccumulator;
  29. @class FSTDispatchQueue;
  30. NS_ASSUME_NONNULL_BEGIN
  31. #if __cplusplus
  32. extern "C" {
  33. #endif
  34. @interface FSTIntegrationTestCase : XCTestCase
  35. /** Returns the default Firestore project ID for testing. */
  36. + (NSString *)projectID;
  37. /** Returns a FirestoreSettings configured to use either hexa or the emulator. */
  38. + (FIRFirestoreSettings *)settings;
  39. /** Returns a new Firestore connected to the "test-db" project. */
  40. - (FIRFirestore *)firestore;
  41. /** Returns a new Firestore connected to the project with the given projectID. */
  42. - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID;
  43. /** Synchronously shuts down the given firestore. */
  44. - (void)shutdownFirestore:(FIRFirestore *)firestore;
  45. - (NSString *)documentPath;
  46. - (FIRDocumentReference *)documentRef;
  47. - (FIRCollectionReference *)collectionRef;
  48. - (FIRCollectionReference *)collectionRefWithDocuments:
  49. (NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents;
  50. - (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
  51. toCollection:(FIRCollectionReference *)collection;
  52. - (void)readerAndWriterOnDocumentRef:(void (^)(NSString *path,
  53. FIRDocumentReference *readerRef,
  54. FIRDocumentReference *writerRef))action;
  55. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref;
  56. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
  57. source:(FIRFirestoreSource)source;
  58. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query;
  59. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRFirestoreSource)source;
  60. - (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)query
  61. requireOnline:(BOOL)online;
  62. - (void)writeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  63. - (void)updateDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  64. - (void)deleteDocumentRef:(FIRDocumentReference *)ref;
  65. - (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data;
  66. - (void)disableNetwork;
  67. - (void)enableNetwork;
  68. - (FSTDispatchQueue *)queueForFirestore:(FIRFirestore *)firestore;
  69. /**
  70. * "Blocks" the current thread/run loop until the block returns YES.
  71. * Should only be called on the main thread.
  72. * The block is invoked frequently and in a loop (every couple of milliseconds) to ensure fast
  73. * test progress and make sure actions to be run on main thread are not blocked by this method.
  74. */
  75. - (void)waitUntil:(BOOL (^)())predicate;
  76. @property(nonatomic, strong) FIRFirestore *db;
  77. @property(nonatomic, strong) FSTEventAccumulator *eventAccumulator;
  78. @end
  79. /** Converts the FIRQuerySnapshot to an NSArray containing the data of the documents in order. */
  80. NSArray<NSDictionary<NSString *, id> *> *FIRQuerySnapshotGetData(FIRQuerySnapshot *docs);
  81. /** Converts the FIRQuerySnapshot to an NSArray containing the document IDs in order. */
  82. NSArray<NSString *> *FIRQuerySnapshotGetIDs(FIRQuerySnapshot *docs);
  83. /** Converts the FIRQuerySnapshot to an NSArray containing an NSArray containing the doc change data
  84. * in order of { type, doc title, doc data }. */
  85. NSArray<NSArray<id> *> *FIRQuerySnapshotGetDocChangesData(FIRQuerySnapshot *docs);
  86. #if __cplusplus
  87. } // extern "C"
  88. #endif
  89. NS_ASSUME_NONNULL_END