PropertyWrapperDefaultConfigsTests.swift 2.3 KB

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