PropertyWrapperDefaultConfigsTests.swift 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*
  2. * Copyright 2022 Google LLC
  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
  17. import FirebaseRemoteConfig
  18. import XCTest
  19. let ConfigKeyForThisTestOnly = "PropertyWrapperDefaultConfigsTestsKey"
  20. @available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 14.0, watchOS 7.0, *)
  21. class PropertyWrapperDefaultConfigsTests: XCTestCase {
  22. struct Recipe: Decodable, Encodable {
  23. var recipeName: String
  24. var ingredients: [String]
  25. var cookTime: Int
  26. }
  27. static let defaultRecipe = Recipe(
  28. recipeName: "muffin", ingredients: ["flour", "sugar"], cookTime: 45
  29. )
  30. // MARK: - Test Remote Config default values with property wrapper
  31. struct DefaultsValuesTester {
  32. @RemoteConfigProperty(
  33. key: ConfigKeyForThisTestOnly,
  34. fallback: Recipe(recipeName: "test", ingredients: [], cookTime: 0)
  35. )
  36. var dictValue: Recipe
  37. }
  38. override class func setUp() {
  39. if FirebaseApp.app() == nil {
  40. let options = FirebaseOptions(googleAppID: "1:123:ios:123abc",
  41. gcmSenderID: "correct_gcm_sender_id")
  42. options.apiKey = "A23456789012345678901234567890123456789"
  43. options.projectID = "Fake_Project"
  44. FirebaseApp.configure(options: options)
  45. }
  46. }
  47. func testDefaultValues() async throws {
  48. try? RemoteConfig.remoteConfig().setDefaults(
  49. from: [ConfigKeyForThisTestOnly: PropertyWrapperDefaultConfigsTests.defaultRecipe]
  50. )
  51. let tester = await DefaultsValuesTester()
  52. let dictValue = await tester.dictValue
  53. XCTAssertEqual(dictValue.recipeName, "muffin")
  54. XCTAssertEqual(dictValue.cookTime, 45)
  55. XCTAssertEqual(dictValue.ingredients, ["flour", "sugar"])
  56. }
  57. }