RCNRemoteConfig+FIRAppTest.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright 2019 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 <OCMock/OCMock.h>
  17. #import <XCTest/XCTest.h>
  18. // #import "FIRRemoteConfig+FIRApp.h"
  19. #import "FirebaseCore/Extension/FirebaseCoreInternal.h"
  20. #import "FirebaseRemoteConfig/Sources/Private/FIRRemoteConfig_Private.h"
  21. // #import "third_party/firebase/ios/Releases/FirebaseCore/Tests/FIRTestCase.h"
  22. @interface RCNRemoteConfig_FIRAppTest : FIRTestCase
  23. @end
  24. @implementation RCNRemoteConfig_FIRAppTest
  25. - (void)setUp {
  26. [super setUp];
  27. [FIRApp resetApps];
  28. }
  29. - (void)testConfigureConfigWithValidInput {
  30. XCTAssertNoThrow([FIRApp configure]);
  31. FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
  32. XCTAssertEqualObjects(rc.GMPProjectID, kGoogleAppID);
  33. XCTAssertEqualObjects(rc.senderID, kGCMSenderID);
  34. }
  35. - (void)testConfigureConfigWithEmptyGoogleAppID {
  36. NSDictionary *optionsDictionary = @{kFIRGoogleAppID : @""};
  37. FIROptions *options = [[FIROptions alloc] initInternalWithOptionsDictionary:optionsDictionary];
  38. FIRApp *app = [[FIRApp alloc] initInstanceWithName:kFIRDefaultAppName options:options];
  39. FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
  40. XCTAssertThrows([rc configureConfig:app]);
  41. }
  42. - (void)testConfigureConfigWithNilGoogleAppID {
  43. NSDictionary *optionsDictionary = @{};
  44. FIROptions *options = [[FIROptions alloc] initInternalWithOptionsDictionary:optionsDictionary];
  45. FIRApp *app = [[FIRApp alloc] initInstanceWithName:kFIRDefaultAppName options:options];
  46. FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
  47. XCTAssertThrows([rc configureConfig:app]);
  48. }
  49. - (void)testConfigureConfigWithEmptySenderID {
  50. NSDictionary *optionsDictionary = @{kFIRGoogleAppID : kGoogleAppID, kFIRGCMSenderID : @""};
  51. FIROptions *options = [[FIROptions alloc] initInternalWithOptionsDictionary:optionsDictionary];
  52. FIRApp *app = [[FIRApp alloc] initInstanceWithName:kFIRDefaultAppName options:options];
  53. FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
  54. XCTAssertThrows([rc configureConfig:app]);
  55. }
  56. - (void)testConfigureConfigWithNilSenderID {
  57. NSDictionary *optionsDictionary = @{kFIRGoogleAppID : kGoogleAppID};
  58. FIROptions *options = [[FIROptions alloc] initInternalWithOptionsDictionary:optionsDictionary];
  59. FIRApp *app = [[FIRApp alloc] initInstanceWithName:kFIRDefaultAppName options:options];
  60. FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
  61. XCTAssertThrows([rc configureConfig:app]);
  62. }
  63. - (void)testConfigureConfigNotInstallingSenderID {
  64. id settingsMock = OCMClassMock([RCNConfigSettings class]);
  65. OCMStub([settingsMock instancesRespondToSelector:@selector(senderID)]).andReturn(NO);
  66. XCTAssertNoThrow([FIRApp configure]);
  67. FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
  68. XCTAssertEqualObjects(rc.GMPProjectID, kGoogleAppID);
  69. XCTAssertEqualObjects(rc.senderID, nil);
  70. [settingsMock stopMocking];
  71. }
  72. - (void)testConfigureWithOptions {
  73. FIROptions *options =
  74. [[FIROptions alloc] initWithGoogleAppID:@"1:966600170131:ios:a750b5ff97fbf47d"
  75. GCMSenderID:@"966600170131"];
  76. XCTAssertNoThrow([FIRApp configureWithOptions:options]);
  77. FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
  78. XCTAssertEqualObjects(rc.GMPProjectID, @"1:966600170131:ios:a750b5ff97fbf47d");
  79. XCTAssertEqualObjects(rc.senderID, @"966600170131");
  80. }
  81. - (void)testConfigureWithMultipleProjects {
  82. XCTAssertNoThrow([FIRApp configure]);
  83. FIRRemoteConfig *rc = [FIRRemoteConfig remoteConfig];
  84. XCTAssertEqualObjects(rc.GMPProjectID, kGoogleAppID);
  85. XCTAssertEqualObjects(rc.senderID, kGCMSenderID);
  86. FIROptions *options =
  87. [[FIROptions alloc] initWithGoogleAppID:@"1:966600170131:ios:a750b5ff97fbf47d"
  88. GCMSenderID:@"966600170131"];
  89. [FIRApp configureWithName:@"nonDefault" options:options];
  90. XCTAssertEqualObjects(rc.GMPProjectID, kGoogleAppID);
  91. XCTAssertEqualObjects(rc.senderID, kGCMSenderID);
  92. }
  93. @end