FIRFirestoreTests.mm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #import <FirebaseFirestore/FIRFirestore.h>
  17. #import <XCTest/XCTest.h>
  18. #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  19. #include "Firestore/core/test/unit/testutil/app_testing.h"
  20. namespace testutil = firebase::firestore::testutil;
  21. @interface FIRFirestoreTests : XCTestCase
  22. @end
  23. @implementation FIRFirestoreTests
  24. - (void)testDeleteApp {
  25. // Ensure the app is set appropriately.
  26. FIRApp *app = testutil::AppForUnitTesting();
  27. NSString *appName = app.name;
  28. FIROptions *options = app.options;
  29. FIRFirestore *firestore = [FIRFirestore firestoreForApp:app];
  30. XCTAssertEqualObjects(firestore.app, app);
  31. // Ensure that firestoreForApp returns the same instance.
  32. XCTAssertEqualObjects(firestore, [FIRFirestore firestoreForApp:app]);
  33. XCTestExpectation *defaultAppDeletedExpectation =
  34. [self expectationWithDescription:@"Deleting the default app should invalidate the default "
  35. @"Firestore instance."];
  36. [app deleteApp:^(BOOL success) {
  37. XCTAssertTrue(success);
  38. // Recreate the FIRApp with the same name, fetch a new Firestore instance and make sure it's
  39. // different than the other one.
  40. [FIRApp configureWithName:appName options:options];
  41. FIRApp *newApp = [FIRApp appNamed:appName];
  42. FIRFirestore *newInstance = [FIRFirestore firestoreForApp:newApp];
  43. XCTAssertNotEqualObjects(newInstance, firestore);
  44. [defaultAppDeletedExpectation fulfill];
  45. }];
  46. [self waitForExpectationsWithTimeout:2
  47. handler:^(NSError *_Nullable error) {
  48. XCTAssertNil(error);
  49. }];
  50. }
  51. @end