FSTIntegrationTestCase.mm 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  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 "Firestore/Example/Tests/Util/FSTIntegrationTestCase.h"
  17. #import <FirebaseFirestore/FIRCollectionReference.h>
  18. #import <FirebaseFirestore/FIRDocumentChange.h>
  19. #import <FirebaseFirestore/FIRDocumentReference.h>
  20. #import <FirebaseFirestore/FIRDocumentSnapshot.h>
  21. #import <FirebaseFirestore/FIRFirestore.h>
  22. #import <FirebaseFirestore/FIRFirestoreSettings.h>
  23. #import <FirebaseFirestore/FIRQuerySnapshot.h>
  24. #import <FirebaseFirestore/FIRSnapshotMetadata.h>
  25. #import <FirebaseFirestore/FIRTransaction.h>
  26. #include <memory>
  27. #include <string>
  28. #include <utility>
  29. #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  30. #import "Firestore/Example/Tests/Util/FIRFirestore+Testing.h"
  31. #import "Firestore/Example/Tests/Util/FSTEventAccumulator.h"
  32. #import "Firestore/Source/API/FIRFirestore+Internal.h"
  33. #include "Firestore/core/src/auth/credentials_provider.h"
  34. #include "Firestore/core/src/auth/empty_credentials_provider.h"
  35. #include "Firestore/core/src/auth/user.h"
  36. #include "Firestore/core/src/local/leveldb_opener.h"
  37. #include "Firestore/core/src/model/database_id.h"
  38. #include "Firestore/core/src/remote/grpc_connection.h"
  39. #include "Firestore/core/src/util/async_queue.h"
  40. #include "Firestore/core/src/util/autoid.h"
  41. #include "Firestore/core/src/util/filesystem.h"
  42. #include "Firestore/core/src/util/path.h"
  43. #include "Firestore/core/src/util/string_apple.h"
  44. #include "Firestore/core/test/unit/testutil/app_testing.h"
  45. #include "Firestore/core/test/unit/testutil/async_testing.h"
  46. #include "Firestore/core/test/unit/testutil/status_testing.h"
  47. #include "absl/memory/memory.h"
  48. namespace testutil = firebase::firestore::testutil;
  49. namespace util = firebase::firestore::util;
  50. using firebase::firestore::auth::CredentialChangeListener;
  51. using firebase::firestore::auth::CredentialsProvider;
  52. using firebase::firestore::auth::EmptyCredentialsProvider;
  53. using firebase::firestore::auth::User;
  54. using firebase::firestore::core::DatabaseInfo;
  55. using firebase::firestore::local::LevelDbOpener;
  56. using firebase::firestore::model::DatabaseId;
  57. using firebase::firestore::testutil::AppForUnitTesting;
  58. using firebase::firestore::testutil::AsyncQueueForTesting;
  59. using firebase::firestore::remote::GrpcConnection;
  60. using firebase::firestore::util::AsyncQueue;
  61. using firebase::firestore::util::CreateAutoId;
  62. using firebase::firestore::util::Filesystem;
  63. using firebase::firestore::util::Path;
  64. using firebase::firestore::util::Status;
  65. using firebase::firestore::util::StatusOr;
  66. NS_ASSUME_NONNULL_BEGIN
  67. /**
  68. * Firestore databases can be subject to a ~30s "cold start" delay if they have not been used
  69. * recently, so before any tests run we "prime" the backend.
  70. */
  71. static const double kPrimingTimeout = 45.0;
  72. static NSString *defaultProjectId;
  73. static FIRFirestoreSettings *defaultSettings;
  74. static bool runningAgainstEmulator = false;
  75. // Behaves the same as `EmptyCredentialsProvider` except it can also trigger a user
  76. // change.
  77. class FakeCredentialsProvider : public EmptyCredentialsProvider {
  78. public:
  79. void SetCredentialChangeListener(CredentialChangeListener changeListener) override {
  80. if (changeListener) {
  81. listener_ = std::move(changeListener);
  82. listener_(User::Unauthenticated());
  83. }
  84. }
  85. void ChangeUser(NSString *new_id) {
  86. if (listener_) {
  87. listener_(firebase::firestore::auth::User::FromUid(new_id));
  88. }
  89. }
  90. private:
  91. CredentialChangeListener listener_;
  92. };
  93. @implementation FSTIntegrationTestCase {
  94. NSMutableArray<FIRFirestore *> *_firestores;
  95. std::shared_ptr<FakeCredentialsProvider> _fakeCredentialsProvider;
  96. }
  97. - (void)setUp {
  98. [super setUp];
  99. LoadXCTestCaseAwait();
  100. _fakeCredentialsProvider = std::make_shared<FakeCredentialsProvider>();
  101. [self clearPersistenceOnce];
  102. [self primeBackend];
  103. _firestores = [NSMutableArray array];
  104. self.db = [self firestore];
  105. self.eventAccumulator = [FSTEventAccumulator accumulatorForTest:self];
  106. }
  107. - (void)tearDown {
  108. @try {
  109. for (FIRFirestore *firestore in _firestores) {
  110. [self terminateFirestore:firestore];
  111. }
  112. } @finally {
  113. _firestores = nil;
  114. [super tearDown];
  115. }
  116. }
  117. /**
  118. * Clears persistence, but only the first time. This ensures that each test
  119. * run is isolated from the last test run, but doesn't allow tests to interfere
  120. * with each other.
  121. */
  122. - (void)clearPersistenceOnce {
  123. auto *fs = Filesystem::Default();
  124. static bool clearedPersistence = false;
  125. @synchronized([FSTIntegrationTestCase class]) {
  126. if (clearedPersistence) return;
  127. DatabaseInfo dbInfo;
  128. LevelDbOpener opener(dbInfo);
  129. StatusOr<Path> maybeLevelDBDir = opener.FirestoreAppDataDir();
  130. ASSERT_OK(maybeLevelDBDir.status());
  131. Path levelDBDir = std::move(maybeLevelDBDir).ValueOrDie();
  132. Status status = fs->RecursivelyRemove(levelDBDir);
  133. ASSERT_OK(status);
  134. clearedPersistence = true;
  135. }
  136. }
  137. - (FIRFirestore *)firestore {
  138. return [self firestoreWithProjectID:[FSTIntegrationTestCase projectID]];
  139. }
  140. /**
  141. * Figures out what kind of testing environment we're using, and sets up testing defaults to make
  142. * that work.
  143. *
  144. * Several configurations are supported:
  145. * * Mobile Harness, running periocally against prod and nightly, using live SSL certs
  146. * * Hexa built from google3, running on a companion gLinux machine, using self-signed test SSL
  147. * certs
  148. * * Firestore emulator, running on localhost, with SSL disabled
  149. *
  150. * See Firestore/README.md for detailed setup instructions or comments below for which specific
  151. * values trigger which configurations.
  152. */
  153. + (void)setUpDefaults {
  154. if (defaultSettings) return;
  155. defaultSettings = [[FIRFirestoreSettings alloc] init];
  156. defaultSettings.persistenceEnabled = YES;
  157. // Check for a MobileHarness configuration, running against nightly or prod, which have live
  158. // SSL certs.
  159. NSString *project = [[NSProcessInfo processInfo] environment][@"PROJECT_ID"];
  160. NSString *host = [[NSProcessInfo processInfo] environment][@"DATASTORE_HOST"];
  161. if (project && host) {
  162. defaultProjectId = project;
  163. defaultSettings.host = host;
  164. return;
  165. }
  166. // Check for configuration of a prod project via GoogleServices-Info.plist.
  167. FIROptions *options = [FIROptions defaultOptions];
  168. if (options && ![options.projectID isEqualToString:@"abc-xyz-123"]) {
  169. defaultProjectId = options.projectID;
  170. if (host) {
  171. // Allow access to nightly or other hosts via this mechanism too.
  172. defaultSettings.host = host;
  173. }
  174. return;
  175. }
  176. // Otherwise fall back on assuming the emulator or Hexa on localhost.
  177. defaultProjectId = @"test-db";
  178. // Hexa uses a self-signed cert: the first bundle location is used by bazel builds. The second is
  179. // used for github clones.
  180. NSString *certsPath =
  181. [[NSBundle mainBundle] pathForResource:@"PlugIns/IntegrationTests.xctest/CAcert"
  182. ofType:@"pem"];
  183. if (certsPath == nil) {
  184. certsPath = [[NSBundle bundleForClass:[self class]] pathForResource:@"CAcert" ofType:@"pem"];
  185. }
  186. unsigned long long fileSize =
  187. [[[NSFileManager defaultManager] attributesOfItemAtPath:certsPath error:nil] fileSize];
  188. if (fileSize != 0) {
  189. defaultSettings.host = @"localhost:8081";
  190. GrpcConnection::UseTestCertificate(util::MakeString(defaultSettings.host),
  191. Path::FromNSString(certsPath), "test_cert_2");
  192. } else {
  193. // If no cert is set up, configure for the Firestore emulator.
  194. defaultSettings.host = @"localhost:8080";
  195. defaultSettings.sslEnabled = false;
  196. runningAgainstEmulator = true;
  197. // Also issue a warning because the Firestore emulator doesn't completely work yet.
  198. NSLog(@"Please set up a GoogleServices-Info.plist for Firestore in Firestore/Example/App using "
  199. "instructions at <https://github.com/firebase/firebase-ios-sdk#running-sample-apps>. "
  200. "Alternatively, if you're a Googler with a Hexa preproduction environment, run "
  201. "setup_integration_tests.py to properly configure testing SSL certificates.");
  202. }
  203. }
  204. + (NSString *)projectID {
  205. if (!defaultProjectId) {
  206. [self setUpDefaults];
  207. }
  208. return defaultProjectId;
  209. }
  210. + (bool)isRunningAgainstEmulator {
  211. // The only way to determine whether or not we're running against the emulator is to figure out
  212. // which testing environment we're using. Essentially `setUpDefaults` determines
  213. // `runningAgainstEmulator` as a side effect.
  214. if (!defaultProjectId) {
  215. [self setUpDefaults];
  216. }
  217. return runningAgainstEmulator;
  218. }
  219. + (FIRFirestoreSettings *)settings {
  220. [self setUpDefaults];
  221. return defaultSettings;
  222. }
  223. - (FIRFirestore *)firestoreWithProjectID:(NSString *)projectID {
  224. FIRApp *app = AppForUnitTesting(util::MakeString(projectID));
  225. return [self firestoreWithApp:app];
  226. }
  227. - (FIRFirestore *)firestoreWithApp:(FIRApp *)app {
  228. NSString *persistenceKey = [NSString stringWithFormat:@"db%lu", (unsigned long)_firestores.count];
  229. FIRSetLoggerLevel(FIRLoggerLevelDebug);
  230. std::string projectID = util::MakeString(app.options.projectID);
  231. FIRFirestore *firestore =
  232. [[FIRFirestore alloc] initWithDatabaseID:DatabaseId(projectID)
  233. persistenceKey:util::MakeString(persistenceKey)
  234. credentialsProvider:_fakeCredentialsProvider
  235. workerQueue:AsyncQueueForTesting()
  236. firebaseApp:app
  237. instanceRegistry:nil];
  238. firestore.settings = [FSTIntegrationTestCase settings];
  239. [_firestores addObject:firestore];
  240. return firestore;
  241. }
  242. - (void)triggerUserChangeWithUid:(NSString *)uid {
  243. _fakeCredentialsProvider->ChangeUser(uid);
  244. }
  245. - (void)primeBackend {
  246. static dispatch_once_t onceToken;
  247. dispatch_once(&onceToken, ^{
  248. [FSTIntegrationTestCase setUpDefaults];
  249. if (runningAgainstEmulator) {
  250. // Priming not required against the emulator.
  251. return;
  252. }
  253. FIRFirestore *db = [self firestore];
  254. XCTestExpectation *watchInitialized =
  255. [self expectationWithDescription:@"Prime backend: Watch initialized"];
  256. __block XCTestExpectation *watchUpdateReceived;
  257. FIRDocumentReference *docRef = [db documentWithPath:[self documentPath]];
  258. id<FIRListenerRegistration> listenerRegistration =
  259. [docRef addSnapshotListener:^(FIRDocumentSnapshot *snapshot, NSError *) {
  260. if ([snapshot[@"value"] isEqual:@"done"]) {
  261. [watchUpdateReceived fulfill];
  262. } else {
  263. [watchInitialized fulfill];
  264. }
  265. }];
  266. // Wait for watch to initialize and deliver first event.
  267. [self awaitExpectation:watchInitialized];
  268. watchUpdateReceived = [self expectationWithDescription:@"Prime backend: Watch update received"];
  269. // Use a transaction to perform a write without triggering any local events.
  270. [docRef.firestore
  271. runTransactionWithBlock:^id(FIRTransaction *transaction, NSError **) {
  272. [transaction setData:@{@"value" : @"done"} forDocument:docRef];
  273. return nil;
  274. }
  275. completion:^(id, NSError *){
  276. }];
  277. // Wait to see the write on the watch stream.
  278. [self waitForExpectationsWithTimeout:kPrimingTimeout
  279. handler:^(NSError *_Nullable expectationError) {
  280. if (expectationError) {
  281. XCTFail(@"Error waiting for prime backend: %@",
  282. expectationError);
  283. }
  284. }];
  285. [listenerRegistration remove];
  286. [self terminateFirestore:db];
  287. });
  288. }
  289. - (void)terminateFirestore:(FIRFirestore *)firestore {
  290. XCTestExpectation *expectation = [self expectationWithDescription:@"shutdown"];
  291. [firestore terminateWithCompletion:[self completionForExpectation:expectation]];
  292. [self awaitExpectation:expectation];
  293. }
  294. - (void)deleteApp:(FIRApp *)app {
  295. XCTestExpectation *expectation = [self expectationWithDescription:@"deleteApp"];
  296. [app deleteApp:^(BOOL completion) {
  297. XCTAssertTrue(completion);
  298. [expectation fulfill];
  299. }];
  300. [self awaitExpectation:expectation];
  301. }
  302. - (NSString *)documentPath {
  303. std::string autoId = CreateAutoId();
  304. return [NSString stringWithFormat:@"test-collection/%s", autoId.c_str()];
  305. }
  306. - (FIRDocumentReference *)documentRef {
  307. return [self.db documentWithPath:[self documentPath]];
  308. }
  309. - (FIRCollectionReference *)collectionRef {
  310. std::string autoId = CreateAutoId();
  311. NSString *collectionName = [NSString stringWithFormat:@"test-collection-%s", autoId.c_str()];
  312. return [self.db collectionWithPath:collectionName];
  313. }
  314. - (FIRCollectionReference *)collectionRefWithDocuments:
  315. (NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents {
  316. FIRCollectionReference *collection = [self collectionRef];
  317. // Use a different instance to write the documents
  318. [self writeAllDocuments:documents
  319. toCollection:[[self firestore] collectionWithPath:collection.path]];
  320. return collection;
  321. }
  322. - (void)writeAllDocuments:(NSDictionary<NSString *, NSDictionary<NSString *, id> *> *)documents
  323. toCollection:(FIRCollectionReference *)collection {
  324. [documents enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSDictionary<NSString *, id> *value,
  325. BOOL *) {
  326. FIRDocumentReference *ref = [collection documentWithPath:key];
  327. [self writeDocumentRef:ref data:value];
  328. }];
  329. }
  330. - (void)readerAndWriterOnDocumentRef:(void (^)(FIRDocumentReference *readerRef,
  331. FIRDocumentReference *writerRef))action {
  332. FIRFirestore *reader = self.db; // for clarity
  333. FIRFirestore *writer = [self firestore];
  334. NSString *path = [self documentPath];
  335. FIRDocumentReference *readerRef = [reader documentWithPath:path];
  336. FIRDocumentReference *writerRef = [writer documentWithPath:path];
  337. action(readerRef, writerRef);
  338. }
  339. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref {
  340. return [self readDocumentForRef:ref source:FIRFirestoreSourceDefault];
  341. }
  342. - (FIRDocumentSnapshot *)readDocumentForRef:(FIRDocumentReference *)ref
  343. source:(FIRFirestoreSource)source {
  344. __block FIRDocumentSnapshot *result;
  345. XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
  346. [ref getDocumentWithSource:source
  347. completion:^(FIRDocumentSnapshot *doc, NSError *_Nullable error) {
  348. XCTAssertNil(error);
  349. result = doc;
  350. [expectation fulfill];
  351. }];
  352. [self awaitExpectation:expectation];
  353. return result;
  354. }
  355. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query {
  356. return [self readDocumentSetForRef:query source:FIRFirestoreSourceDefault];
  357. }
  358. - (FIRQuerySnapshot *)readDocumentSetForRef:(FIRQuery *)query source:(FIRFirestoreSource)source {
  359. __block FIRQuerySnapshot *result;
  360. XCTestExpectation *expectation = [self expectationWithDescription:@"getData"];
  361. [query getDocumentsWithSource:source
  362. completion:^(FIRQuerySnapshot *documentSet, NSError *error) {
  363. XCTAssertNil(error);
  364. result = documentSet;
  365. [expectation fulfill];
  366. }];
  367. [self awaitExpectation:expectation];
  368. return result;
  369. }
  370. - (FIRDocumentSnapshot *)readSnapshotForRef:(FIRDocumentReference *)ref
  371. requireOnline:(BOOL)requireOnline {
  372. __block FIRDocumentSnapshot *result;
  373. XCTestExpectation *expectation = [self expectationWithDescription:@"listener"];
  374. id<FIRListenerRegistration> listener = [ref
  375. addSnapshotListenerWithIncludeMetadataChanges:YES
  376. listener:^(FIRDocumentSnapshot *snapshot,
  377. NSError *error) {
  378. XCTAssertNil(error);
  379. if (!requireOnline || !snapshot.metadata.fromCache) {
  380. result = snapshot;
  381. [expectation fulfill];
  382. }
  383. }];
  384. [self awaitExpectation:expectation];
  385. [listener remove];
  386. return result;
  387. }
  388. - (void)writeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
  389. XCTestExpectation *expectation = [self expectationWithDescription:@"setData"];
  390. [ref setData:data completion:[self completionForExpectation:expectation]];
  391. [self awaitExpectation:expectation];
  392. }
  393. - (void)updateDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<id, id> *)data {
  394. XCTestExpectation *expectation = [self expectationWithDescription:@"updateData"];
  395. [ref updateData:data completion:[self completionForExpectation:expectation]];
  396. [self awaitExpectation:expectation];
  397. }
  398. - (void)deleteDocumentRef:(FIRDocumentReference *)ref {
  399. XCTestExpectation *expectation = [self expectationWithDescription:@"deleteDocument"];
  400. [ref deleteDocumentWithCompletion:[self completionForExpectation:expectation]];
  401. [self awaitExpectation:expectation];
  402. }
  403. - (FIRDocumentReference *)addDocumentRef:(FIRCollectionReference *)ref
  404. data:(NSDictionary<NSString *, id> *)data {
  405. XCTestExpectation *expectation = [self expectationWithDescription:@"addDocument"];
  406. FIRDocumentReference *doc = [ref addDocumentWithData:data
  407. completion:[self completionForExpectation:expectation]];
  408. [self awaitExpectation:expectation];
  409. return doc;
  410. }
  411. - (void)mergeDocumentRef:(FIRDocumentReference *)ref data:(NSDictionary<NSString *, id> *)data {
  412. XCTestExpectation *expectation = [self expectationWithDescription:@"setDataWithMerge"];
  413. [ref setData:data merge:YES completion:[self completionForExpectation:expectation]];
  414. [self awaitExpectation:expectation];
  415. }
  416. - (void)mergeDocumentRef:(FIRDocumentReference *)ref
  417. data:(NSDictionary<NSString *, id> *)data
  418. fields:(NSArray<id> *)fields {
  419. XCTestExpectation *expectation = [self expectationWithDescription:@"setDataWithMerge"];
  420. [ref setData:data mergeFields:fields completion:[self completionForExpectation:expectation]];
  421. [self awaitExpectation:expectation];
  422. }
  423. - (void)disableNetwork {
  424. XCTestExpectation *expectation = [self expectationWithDescription:@"disableNetwork"];
  425. [self.db disableNetworkWithCompletion:[self completionForExpectation:expectation]];
  426. [self awaitExpectation:expectation];
  427. }
  428. - (void)enableNetwork {
  429. XCTestExpectation *expectation = [self expectationWithDescription:@"enableNetwork"];
  430. [self.db enableNetworkWithCompletion:[self completionForExpectation:expectation]];
  431. [self awaitExpectation:expectation];
  432. }
  433. - (const std::shared_ptr<util::AsyncQueue> &)queueForFirestore:(FIRFirestore *)firestore {
  434. return [firestore workerQueue];
  435. }
  436. - (void)waitUntil:(BOOL (^)())predicate {
  437. NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate];
  438. double waitSeconds = [self defaultExpectationWaitSeconds];
  439. while (!predicate() && ([NSDate timeIntervalSinceReferenceDate] - start < waitSeconds)) {
  440. // This waits for the next event or until the 100ms timeout is reached
  441. [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
  442. beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
  443. }
  444. if (!predicate()) {
  445. XCTFail(@"Timeout");
  446. }
  447. }
  448. extern "C" NSArray<NSDictionary<NSString *, id> *> *FIRQuerySnapshotGetData(
  449. FIRQuerySnapshot *docs) {
  450. NSMutableArray<NSDictionary<NSString *, id> *> *result = [NSMutableArray array];
  451. for (FIRDocumentSnapshot *doc in docs.documents) {
  452. [result addObject:doc.data];
  453. }
  454. return result;
  455. }
  456. extern "C" NSArray<NSString *> *FIRQuerySnapshotGetIDs(FIRQuerySnapshot *docs) {
  457. NSMutableArray<NSString *> *result = [NSMutableArray array];
  458. for (FIRDocumentSnapshot *doc in docs.documents) {
  459. [result addObject:doc.documentID];
  460. }
  461. return result;
  462. }
  463. extern "C" NSArray<NSArray<id> *> *FIRQuerySnapshotGetDocChangesData(FIRQuerySnapshot *docs) {
  464. NSMutableArray<NSMutableArray<id> *> *result = [NSMutableArray array];
  465. for (FIRDocumentChange *docChange in docs.documentChanges) {
  466. NSMutableArray<id> *docChangeData = [NSMutableArray array];
  467. [docChangeData addObject:@(docChange.type)];
  468. [docChangeData addObject:docChange.document.documentID];
  469. [docChangeData addObject:docChange.document.data];
  470. [result addObject:docChangeData];
  471. }
  472. return result;
  473. }
  474. @end
  475. NS_ASSUME_NONNULL_END