FSTIntegrationTestCase.h 4.5 KB

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