FIRFirestoreTests.mm 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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 <FirebaseCore/FIRAppInternal.h>
  17. #import <FirebaseCore/FIROptionsInternal.h>
  18. #import <FirebaseFirestore/FIRFirestore.h>
  19. #import <XCTest/XCTest.h>
  20. #include "Firestore/core/test/firebase/firestore/testutil/app_testing.h"
  21. namespace testutil = firebase::firestore::testutil;
  22. @interface FIRFirestoreTests : XCTestCase
  23. @end
  24. @implementation FIRFirestoreTests
  25. - (void)testDeleteApp {
  26. // Ensure the app is set appropriately.
  27. FIRApp *app = testutil::AppForUnitTesting();
  28. NSString *appName = app.name;
  29. FIROptions *options = app.options;
  30. FIRFirestore *firestore = [FIRFirestore firestoreForApp:app];
  31. XCTAssertEqualObjects(firestore.app, app);
  32. // Ensure that firestoreForApp returns the same instance.
  33. XCTAssertEqualObjects(firestore, [FIRFirestore firestoreForApp:app]);
  34. XCTestExpectation *defaultAppDeletedExpectation =
  35. [self expectationWithDescription:@"Deleting the default app should invalidate the default "
  36. @"Firestore instance."];
  37. [app deleteApp:^(BOOL 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