FIRFirestoreTests.mm 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 <FirebaseFirestore/FIRFirestoreSettings.h>
  18. #import <XCTest/XCTest.h>
  19. #import "FirebaseCore/Sources/Private/FirebaseCoreInternal.h"
  20. #include "Firestore/core/test/unit/testutil/app_testing.h"
  21. using firebase::firestore::testutil::AppForUnitTesting;
  22. @interface FIRFirestoreTests : XCTestCase
  23. @end
  24. @implementation FIRFirestoreTests
  25. - (void)testDeleteApp {
  26. // Ensure the app is set appropriately.
  27. FIRApp *app = 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. XCTAssertTrue(success);
  39. // Recreate the FIRApp with the same name, fetch a new Firestore instance and make sure it's
  40. // different than the other one.
  41. [FIRApp configureWithName:appName options:options];
  42. FIRApp *newApp = [FIRApp appNamed:appName];
  43. FIRFirestore *newInstance = [FIRFirestore firestoreForApp:newApp];
  44. XCTAssertNotEqualObjects(newInstance, firestore);
  45. [defaultAppDeletedExpectation fulfill];
  46. }];
  47. [self waitForExpectationsWithTimeout:2
  48. handler:^(NSError *_Nullable error) {
  49. XCTAssertNil(error);
  50. }];
  51. }
  52. - (void)testSetEmulatorSettingsSetsHost {
  53. // Ensure the app is set appropriately.
  54. FIRApp *app = AppForUnitTesting();
  55. FIRFirestore *firestore = [FIRFirestore firestoreForApp:app];
  56. [firestore useEmulatorWithHost:@"localhost" port:1000];
  57. NSString *host = firestore.settings.host;
  58. XCTAssertEqualObjects(host, @"localhost:1000");
  59. }
  60. @end