FSTIntegrationTestCase.h 3.6 KB

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