RCNRemoteConfig+FIRAppTest.m 4.3 KB

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