Skip to content

Commit df36792

Browse files
authored
Add an integration test for calling clearPersistence() on a newly-created Firestore instance. (#5515)
1 parent 416e8d7 commit df36792

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

Firestore/Example/Tests/Integration/API/FIRDatabaseTests.mm

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,7 @@ - (void)testCanClearPersistenceAfterRestarting {
13201320
[self terminateFirestore:firestore];
13211321
[self.firestores removeObject:firestore];
13221322
[firestore
1323-
clearPersistenceWithCompletion:[self completionForExpectationWithName:@"Enable network"]];
1323+
clearPersistenceWithCompletion:[self completionForExpectationWithName:@"ClearPersistence"]];
13241324
[self awaitExpectations];
13251325
[self deleteApp:app];
13261326

@@ -1342,6 +1342,42 @@ - (void)testCanClearPersistenceAfterRestarting {
13421342
[self awaitExpectations];
13431343
}
13441344

1345+
- (void)testCanClearPersistenceOnANewFirestoreInstance {
1346+
FIRDocumentReference *doc = [self documentRef];
1347+
FIRFirestore *firestore = doc.firestore;
1348+
FIRApp *app = firestore.app;
1349+
NSString *appName = app.name;
1350+
FIROptions *options = app.options;
1351+
1352+
NSDictionary<NSString *, id> *initialData = @{@"foo" : @"42"};
1353+
[self writeDocumentRef:doc data:initialData];
1354+
1355+
[firestore terminateWithCompletion:[self completionForExpectationWithName:@"Terminate"]];
1356+
[self.firestores removeObject:firestore];
1357+
[self awaitExpectations];
1358+
[self deleteApp:app];
1359+
1360+
// We restart the app with the same name and options to check that the previous instance's
1361+
// persistent storage is actually cleared after the restart. Calling [self firestore] here would
1362+
// create a new instance of firestore, which defeats the purpose of this test.
1363+
[FIRApp configureWithName:appName options:options];
1364+
FIRApp *app2 = [FIRApp appNamed:appName];
1365+
FIRFirestore *firestore2 = [self firestoreWithApp:app2];
1366+
[firestore2
1367+
clearPersistenceWithCompletion:[self completionForExpectationWithName:@"ClearPersistence"]];
1368+
[self awaitExpectations];
1369+
FIRDocumentReference *docRef2 = [firestore2 documentWithPath:doc.path];
1370+
XCTestExpectation *expectation2 = [self expectationWithDescription:@"getData"];
1371+
[docRef2 getDocumentWithSource:FIRFirestoreSourceCache
1372+
completion:^(FIRDocumentSnapshot *, NSError *_Nullable error) {
1373+
XCTAssertNotNil(error);
1374+
XCTAssertEqualObjects(error.domain, FIRFirestoreErrorDomain);
1375+
XCTAssertEqual(error.code, FIRFirestoreErrorCodeUnavailable);
1376+
[expectation2 fulfill];
1377+
}];
1378+
[self awaitExpectations];
1379+
}
1380+
13451381
- (void)testClearPersistenceWhileRunningFails {
13461382
FIRDocumentReference *doc = [self documentRef];
13471383
FIRFirestore *firestore = doc.firestore;

0 commit comments

Comments
 (0)