mercredi 25 juillet 2018

How to test and mock Firebase remote config is Swift

I need an advice to unit test and mock the Remote Config in swift, i have created a Protocol to avoid dependency in this particular library, but since the there's no response, i have no idea how to create a unit test or a mock for the firebase library

import Foundation
import Firebase

protocol RemoteConfiguration: class {
    func loadDefaultValues()
    func fetchCloudValues()
    func bool(forKey key: RemoteBooleanValues) -> Bool
}
enum RemoteBooleanValues: String {
    case someCase = "someKey"
}
class RemoteConfigService: RemoteConfiguration {
    static let sharedInstance = RemoteConfigService()
    let remoteConfigDefault = "RemoteConfigDefaults"

    private init() {
        loadDefaultValues()
    }

    func loadDefaultValues() {
        RemoteConfig.remoteConfig().setDefaults(fromPlist: remoteConfigDefault)
    }

    func fetchCloudValues() {
        var expirationDuration = 43200

        RemoteConfig.remoteConfig().fetch(withExpirationDuration: TimeInterval(expirationDuration)) { (_, error) in
            if let _ = error {
                return
            }
            RemoteConfig.remoteConfig().activateFetched()
        }
    }

    func bool(forKey key: RemoteBooleanValues) -> Bool {
        debugPrint("Bool Value \(RemoteConfig.remoteConfig()[key.rawValue].boolValue)")
        return RemoteConfig.remoteConfig()[key.rawValue].boolValue
    }

  }

Aucun commentaire:

Enregistrer un commentaire