@@ -53,6 +53,56 @@ - (void) testDatabaseForAppWithInvalidURLs {
53
53
XCTAssertThrows ([self databaseForURL: @" http://x.example.com/paths/are/bad" ]);
54
54
}
55
55
56
+ - (void ) testDeleteDatabase {
57
+ FIRDatabase *defaultDatabase = [FIRDatabase database ];
58
+ FIRApp *defaultApp = [FIRApp defaultApp ];
59
+ XCTAssertEqualObjects (defaultDatabase.app , defaultApp);
60
+
61
+ // Set up expectation for the default app to be deleted.
62
+ XCTestExpectation *defaultAppDeletedExpectation =
63
+ [self expectationWithDescription: @" Deleting the default app should invalidate the default "
64
+ @" database." ];
65
+ [defaultApp deleteApp: ^(BOOL success) {
66
+ // Deleting the default app should make the default database unavailable.
67
+ XCTAssertThrows ([FIRDatabase database ]);
68
+
69
+ [defaultAppDeletedExpectation fulfill ];
70
+ }];
71
+
72
+ // Wait for the default app to be deleted.
73
+ [self waitForExpectations: @[defaultAppDeletedExpectation] timeout: 2 ];
74
+
75
+ // Set up a custom FIRApp with a custom database based on it.
76
+ FIROptions *options = [[FIROptions alloc ] initWithGoogleAppID: @" 1:123:ios:123abc"
77
+ GCMSenderID: @" gcm_sender_id" ];
78
+ options.databaseURL = self.databaseURL ;
79
+ NSString *customAppName = @" MyCustomApp" ;
80
+ [FIRApp configureWithName: customAppName options: options];
81
+ FIRApp *customApp = [FIRApp appNamed: customAppName];
82
+ FIRDatabase *customDatabase = [FIRDatabase databaseForApp: customApp];
83
+ XCTAssertNotNil (customDatabase);
84
+
85
+ // Delete the custom app and wait for it to be done.
86
+ XCTestExpectation *customAppDeletedExpectation =
87
+ [self expectationWithDescription: @" Deleting the custom app should be successful." ];
88
+ [customApp deleteApp: ^(BOOL success) {
89
+ // The app shouldn't exist anymore, ensure that the databaseForApp throws.
90
+ XCTAssertThrows ([FIRDatabase databaseForApp: [FIRApp appNamed: customAppName]]);
91
+
92
+ [customAppDeletedExpectation fulfill ];
93
+ }];
94
+
95
+ // Wait for the custom app to be deleted.
96
+ [self waitForExpectations: @[customAppDeletedExpectation] timeout: 2 ];
97
+
98
+ // Configure the app again, then grab a reference to the database. Assert it's different.
99
+ [FIRApp configureWithName: customAppName options: options];
100
+ FIRApp *secondCustomApp = [FIRApp appNamed: customAppName];
101
+ FIRDatabase *secondCustomDatabase = [FIRDatabase databaseForApp: secondCustomApp];
102
+ XCTAssertNotNil (secondCustomDatabase);
103
+ XCTAssertNotEqualObjects (customDatabase, secondCustomDatabase);
104
+ }
105
+
56
106
- (void ) testReferenceWithPath {
57
107
FIRDatabase *db = [self defaultDatabase ];
58
108
NSString *expectedURL = [NSString stringWithFormat: @" %@ /foo" , self .databaseURL];
0 commit comments