FirebaseRemoteConfigSwift_APIBuildTests.swift 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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 XCTest
  15. import FirebaseCore
  16. import FirebaseRemoteConfig
  17. import FirebaseRemoteConfigInterop
  18. import FirebaseRemoteConfigSwift
  19. final class FirebaseRemoteConfigSwift_APIBuildTests: XCTestCase {
  20. func usage() throws {
  21. // MARK: - FirebaseRemoteConfig
  22. // TODO(ncooke3): These global constants should be lowercase.
  23. let _: String = FirebaseRemoteConfig.NamespaceGoogleMobilePlatform
  24. let _: String = FirebaseRemoteConfig.RemoteConfigThrottledEndTimeInSecondsKey
  25. // TODO(ncooke3): This should probably not be initializable.
  26. FirebaseRemoteConfig.ConfigUpdateListenerRegistration().remove()
  27. let fetchStatus: FirebaseRemoteConfig.RemoteConfigFetchStatus? = nil
  28. switch fetchStatus! {
  29. case .noFetchYet: break
  30. case .success: break
  31. case .failure: break
  32. case .throttled: break
  33. @unknown default: break
  34. }
  35. let fetchAndActivateStatus: FirebaseRemoteConfig.RemoteConfigFetchAndActivateStatus? = nil
  36. switch fetchAndActivateStatus! {
  37. case .successFetchedFromRemote: break
  38. case .successUsingPreFetchedData: break
  39. case .error: break
  40. @unknown default: break
  41. }
  42. // Used to pass into the intializers for the custom errors below.
  43. let nsError = NSError(domain: "", code: 0, userInfo: nil)
  44. // TODO(ncooke3): Global constants should be lowercase.
  45. let _: String = FirebaseRemoteConfig.RemoteConfigErrorDomain
  46. let _ = FirebaseRemoteConfig.RemoteConfigError(_nsError: nsError)
  47. let _: FirebaseRemoteConfig.RemoteConfigError.Code._ErrorType = FirebaseRemoteConfig
  48. .RemoteConfigError(_nsError: nsError)
  49. let _: String = FirebaseRemoteConfig.RemoteConfigError.errorDomain
  50. let code: FirebaseRemoteConfig.RemoteConfigError.Code? = nil
  51. switch code! {
  52. case .unknown: break
  53. case .throttled: break
  54. case .internalError: break
  55. @unknown default: break
  56. }
  57. _ = FirebaseRemoteConfig.RemoteConfigError.unknown
  58. _ = FirebaseRemoteConfig.RemoteConfigError.throttled
  59. _ = FirebaseRemoteConfig.RemoteConfigError.internalError
  60. // TODO(ncooke3): Global constants should be lowercase.
  61. let _: String = FirebaseRemoteConfig.RemoteConfigUpdateErrorDomain
  62. let _ = FirebaseRemoteConfig.RemoteConfigUpdateError(_nsError: nsError)
  63. let _: FirebaseRemoteConfig.RemoteConfigUpdateError.Code._ErrorType = FirebaseRemoteConfig
  64. .RemoteConfigUpdateError(_nsError: nsError)
  65. let _: String = FirebaseRemoteConfig.RemoteConfigUpdateError.errorDomain
  66. let updateErrorCode: FirebaseRemoteConfig.RemoteConfigUpdateError.Code? = nil
  67. switch updateErrorCode! {
  68. case .streamError: break
  69. case .notFetched: break
  70. case .messageInvalid: break
  71. case .unavailable: break
  72. @unknown default: break
  73. }
  74. _ = FirebaseRemoteConfig.RemoteConfigUpdateError.streamError
  75. _ = FirebaseRemoteConfig.RemoteConfigUpdateError.notFetched
  76. _ = FirebaseRemoteConfig.RemoteConfigUpdateError.messageInvalid
  77. _ = FirebaseRemoteConfig.RemoteConfigUpdateError.unavailable
  78. // TODO(ncooke3): This should probably not be initializable.
  79. let value = FirebaseRemoteConfig.RemoteConfigValue()
  80. let _: String? = value.stringValue
  81. // TODO(ncooke3): Returns an Objective-C reference type.
  82. let _: NSNumber = value.numberValue
  83. let _: Data = value.dataValue
  84. let _: Bool = value.boolValue
  85. let _: Any? = value.jsonValue
  86. let source: FirebaseRemoteConfig.RemoteConfigSource = value.source
  87. switch source {
  88. case .remote: break
  89. case .default: break
  90. case .static: break
  91. @unknown default: break
  92. }
  93. let settings = FirebaseRemoteConfig.RemoteConfigSettings()
  94. settings.minimumFetchInterval = TimeInterval(100)
  95. settings.fetchTimeout = TimeInterval(100)
  96. // TODO(ncooke3): This should probably not be initializable.
  97. let update = FirebaseRemoteConfig.RemoteConfigUpdate()
  98. let _: Set<String> = update.updatedKeys
  99. let _ = FirebaseRemoteConfig.RemoteConfig.remoteConfig()
  100. let config = FirebaseRemoteConfig.RemoteConfig
  101. .remoteConfig(app: FirebaseCore.FirebaseApp.app()!)
  102. let _: Date? = config.lastFetchTime
  103. let _: FirebaseRemoteConfig.RemoteConfigFetchStatus = config.lastFetchStatus
  104. let _: FirebaseRemoteConfig.RemoteConfigSettings = config.configSettings
  105. config.ensureInitialized(completionHandler: { (error: Error?) in })
  106. config.fetch(completionHandler: { (status: FirebaseRemoteConfig.RemoteConfigFetchStatus,
  107. error: Error?) in })
  108. config.fetch()
  109. config.fetch(
  110. withExpirationDuration: TimeInterval(100),
  111. completionHandler: { (status: FirebaseRemoteConfig.RemoteConfigFetchStatus, error: Error?) in
  112. }
  113. )
  114. config.fetch(withExpirationDuration: TimeInterval(100))
  115. config
  116. .fetchAndActivate(
  117. completionHandler: { (status: FirebaseRemoteConfig.RemoteConfigFetchAndActivateStatus,
  118. error: Error?) in }
  119. )
  120. config.fetchAndActivate()
  121. config.activate(completion: { (success: Bool, error: Error?) in })
  122. config.activate()
  123. if #available(iOS 13.0, *) {
  124. Task {
  125. let _: Void = try await config.ensureInitialized()
  126. let _: FirebaseRemoteConfig.RemoteConfigFetchStatus = try await config.fetch()
  127. let _: FirebaseRemoteConfig.RemoteConfigFetchStatus = try await config
  128. .fetch(withExpirationDuration: TimeInterval(100))
  129. let _: FirebaseRemoteConfig.RemoteConfigFetchAndActivateStatus = try await config
  130. .fetchAndActivate()
  131. let _: Bool = try await config.activate()
  132. }
  133. }
  134. let _: FirebaseRemoteConfig.RemoteConfigValue = config["key"]
  135. let _: FirebaseRemoteConfig.RemoteConfigValue = config.configValue(forKey: "key")
  136. // TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
  137. let _: FirebaseRemoteConfig.RemoteConfigValue = config.configValue(forKey: nil)
  138. let _: FirebaseRemoteConfig.RemoteConfigValue = config.configValue(
  139. forKey: "key",
  140. source: source
  141. )
  142. // TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
  143. let _: FirebaseRemoteConfig.RemoteConfigValue = config.configValue(forKey: nil, source: source)
  144. let _: [String] = config.allKeys(from: source)
  145. let _: Set<String> = config.keys(withPrefix: "")
  146. // TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
  147. let _: Set<String> = config.keys(withPrefix: nil)
  148. let defaults: [String: NSObject]? = [:]
  149. config.setDefaults(defaults)
  150. // TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
  151. config.setDefaults(nil)
  152. config.setDefaults(fromPlist: "")
  153. // TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
  154. config.setDefaults(fromPlist: nil)
  155. let _: FirebaseRemoteConfig.RemoteConfigValue? = config.defaultValue(forKey: "")
  156. // TODO(ncooke3): Should `nil` be acceptable here in a Swift context?
  157. let _: FirebaseRemoteConfig.RemoteConfigValue? = config.defaultValue(forKey: nil)
  158. let _: FirebaseRemoteConfig.ConfigUpdateListenerRegistration = config
  159. .addOnConfigUpdateListener(
  160. remoteConfigUpdateCompletion: { (update: FirebaseRemoteConfig.RemoteConfigUpdate?,
  161. error: Error?) in
  162. }
  163. )
  164. // MARK: - FirebaseRemoteConfigSwift
  165. let valueError: FirebaseRemoteConfigSwift
  166. .RemoteConfigValueCodableError = .unsupportedType("foo")
  167. switch valueError {
  168. case .unsupportedType: break
  169. }
  170. let error: FirebaseRemoteConfigSwift.RemoteConfigCodableError = .invalidSetDefaultsInput("foo")
  171. switch error {
  172. case .invalidSetDefaultsInput: break
  173. }
  174. @available(iOS 14.0, macOS 11.0, macCatalyst 14.0, tvOS 14.0, watchOS 7.0, *)
  175. struct PropertyWrapperTester {
  176. @FirebaseRemoteConfigSwift.RemoteConfigProperty(key: "", fallback: "")
  177. var stringValue: String!
  178. }
  179. // This should not build because `FirebaseRemoteConfigSwift` does not
  180. // re-export `FirebaseRemoteConfig`.
  181. // let _: FirebaseRemoteConfigSwift.RemoteConfig
  182. struct MyDecodableValue: Decodable {}
  183. let _: MyDecodableValue? = config[decodedValue: ""]
  184. let _: [String: AnyHashable]? = config[jsonValue: ""]
  185. let _: MyDecodableValue = try value.decoded()
  186. let _: MyDecodableValue = try value.decoded(asType: MyDecodableValue.self)
  187. let _: MyDecodableValue? = try config.decoded()
  188. let _: MyDecodableValue? = try config.decoded(asType: MyDecodableValue.self)
  189. struct MyEncodableValue: Encodable {}
  190. let _: Void = try config.setDefaults(from: MyEncodableValue())
  191. }
  192. }