lundi 7 mai 2018

Mocking firebase's auth as object and function at the same time?

I am trying to write minimalistic mocks fro firebase's auth to satisfy use cases like

  facebookSignIn = async () => {
    try {
      const user = await FacebookLogIn.logIn();
      const credential = firebase.auth.FacebookAuthProvider.credential(user.accessToken);
      await firebase.auth().signInAndRetrieveDataWithCredential(credential);
    } catch (e) {
      Alert.alert("Error", e.message);
    }
  };

I've got this far

const firebase = {
  auth: {
    onAuthStateChange: callback => {
      callback({
        user: {
          uid: "123",
          email: "test@email.com"
        }
      });
    },
    FacebookAuthProvider: {
      credential: accessToken => ({ param: "1" });
    }
  }
};

my main concern now is difference when doing

const credential = firebase.auth.FacebookAuthProvider.credential(user.accessToken);

and

await firebase.auth().signInAndRetrieveDataWithCredential(credential);

you can see that auth here is an object and a function at the same time, I'm not entirely sure about how I can mock that :/

Aucun commentaire:

Enregistrer un commentaire