RemoteConfigInteropTests.swift 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright 2023 Google LLC
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. import FirebaseRemoteConfigInterop
  15. import XCTest
  16. class MockRCInterop: RemoteConfigInterop {
  17. weak var subscriber: FirebaseRemoteConfigInterop.RolloutsStateSubscriber?
  18. func registerRolloutsStateSubscriber(_ subscriber: FirebaseRemoteConfigInterop
  19. .RolloutsStateSubscriber,
  20. for namespace: String) {
  21. self.subscriber = subscriber
  22. }
  23. }
  24. class MockRolloutSubscriber: RolloutsStateSubscriber {
  25. var isSubscriberCalled = false
  26. var rolloutsState: RolloutsState?
  27. func rolloutsStateDidChange(_ rolloutsState: FirebaseRemoteConfigInterop.RolloutsState) {
  28. isSubscriberCalled = true
  29. self.rolloutsState = rolloutsState
  30. }
  31. }
  32. final class RemoteConfigInteropTests: XCTestCase {
  33. let rollouts: RolloutsState = {
  34. let assignment1 = RolloutAssignment(
  35. rolloutId: "rollout_1",
  36. variantId: "control",
  37. templateVersion: 1,
  38. parameterKey: "my_feature",
  39. parameterValue: "false"
  40. )
  41. let assignment2 = RolloutAssignment(
  42. rolloutId: "rollout_2",
  43. variantId: "enabled",
  44. templateVersion: 123,
  45. parameterKey: "themis_big_feature",
  46. parameterValue: "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111"
  47. )
  48. let rollouts = RolloutsState(assignmentList: [assignment1, assignment2])
  49. return rollouts
  50. }()
  51. func testRemoteConfigIntegration() throws {
  52. let rcSubscriber = MockRolloutSubscriber()
  53. let rcInterop = MockRCInterop()
  54. rcInterop.registerRolloutsStateSubscriber(rcSubscriber, for: "namespace")
  55. rcInterop.subscriber?.rolloutsStateDidChange(rollouts)
  56. XCTAssertTrue(rcSubscriber.isSubscriberCalled)
  57. XCTAssertEqual(rcSubscriber.rolloutsState?.assignments.count, 2)
  58. }
  59. }