FSTIntegrationTestCase.h 3.3 KB

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