|
| 1 | +/* |
| 2 | + * Copyright 2018 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 | + |
| 17 | +#import <FirebaseCore/FIRAppInternal.h> |
| 18 | +#import <FirebaseCore/FIROptionsInternal.h> |
| 19 | +#import <FirebaseFirestore/FIRFirestore.h> |
| 20 | + |
| 21 | +#import <XCTest/XCTest.h> |
| 22 | + |
| 23 | +@interface FIRFirestoreTests : XCTestCase |
| 24 | +@end |
| 25 | + |
| 26 | +@implementation FIRFirestoreTests |
| 27 | + |
| 28 | +- (void)testDeleteApp { |
| 29 | + // Create a FIRApp for testing. |
| 30 | + NSString *appName = @"custom_app_name"; |
| 31 | + FIROptions *options = |
| 32 | + [[FIROptions alloc] initWithGoogleAppID:@"1:123:ios:123ab" GCMSenderID:@"gcm_sender_id"]; |
| 33 | + options.projectID = @"project_id"; |
| 34 | + [FIRApp configureWithName:appName options:options]; |
| 35 | + |
| 36 | + // Ensure the app is set appropriately. |
| 37 | + FIRApp *app = [FIRApp appNamed:appName]; |
| 38 | + FIRFirestore *firestore = [FIRFirestore firestoreForApp:app]; |
| 39 | + XCTAssertEqualObjects(firestore.app, app); |
| 40 | + |
| 41 | + // Ensure that firestoreForApp returns the same instance. |
| 42 | + XCTAssertEqualObjects(firestore, [FIRFirestore firestoreForApp:app]); |
| 43 | + |
| 44 | + XCTestExpectation *defaultAppDeletedExpectation = |
| 45 | + [self expectationWithDescription: |
| 46 | + @"Deleting the default app should invalidate the default " |
| 47 | + @"Firestore instance."]; |
| 48 | + [app deleteApp:^(BOOL success) { |
| 49 | + // Recreate the FIRApp with the same name, fetch a new Firestore instance and make sure it's |
| 50 | + // different than the other one. |
| 51 | + [FIRApp configureWithName:appName options:options]; |
| 52 | + FIRApp *newApp = [FIRApp appNamed:appName]; |
| 53 | + FIRFirestore *newInstance = [FIRFirestore firestoreForApp:newApp]; |
| 54 | + XCTAssertNotEqualObjects(newInstance, firestore); |
| 55 | + |
| 56 | + [defaultAppDeletedExpectation fulfill]; |
| 57 | + }]; |
| 58 | + |
| 59 | + [self waitForExpectations:@[ defaultAppDeletedExpectation ] timeout:2]; |
| 60 | +} |
| 61 | + |
| 62 | +@end |
0 commit comments