Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Realtime db Ref returns root value rather than the child node #61

Open
jamescrowley opened this issue Apr 16, 2020 · 3 comments
Open

Realtime db Ref returns root value rather than the child node #61

jamescrowley opened this issue Apr 16, 2020 · 3 comments

Comments

@jamescrowley
Copy link

jamescrowley commented Apr 16, 2020

Hi folks, I've got some code that works as expected with the 'real' firebase, but not the mock. Is this a known issue/limitation?

  const mockRealtimeDb = new firebaseMock.MockFirebase();
  mockRealtimeDb.autoFlush(true);
  const mockSdk = new firebaseMock.MockFirebaseSdk(
    () => mockRealtimeDb
  );
  const firebase = mockSdk.initializeApp({});
  await firebase
    .database()
    .ref()
    .update({ "devices/xyz": 123 });
  const savedValue = await firebase
    .database()
    .ref(`devices/xyz`)
    .once('value');
  expect(savedValue.val()).toStrictEqual(123);

however, savedValue.val() returns {"devices": {"xyz": 123}}

@lesmo
Copy link

lesmo commented May 4, 2020

It seems FireMock is "unfolding" the field path when using the / symbol. I did a quick search and couldn't find any documentation about it for RTDB, but in Firestore there are constraints in fields that won't let you do that.

I'm guessing FireMock is using the same code to process and unfold the fields from RTDB and Firestore type of calls.

@jamescrowley
Copy link
Author

jamescrowley commented May 5, 2020

@lesmo the fields don't have a / in - it's just updating multiple paths, as a 'merge' essentially. the update syntax (at least in Firebase rather than firestore) allows you to do

.update({
   "devices/xyz": 123,
   "someOtherDoc/abc": 123,
});

and so on, but when doing a 'ref' of devices/xyz for the value, I'd expect just the value of the 'xyz' key, not the full document from root.

@lesmo
Copy link

lesmo commented May 5, 2020

Oh, you're right!

I've never used the path "shortcut", I'm always calling .collection().doc() (on Firestore, though) to get to my document so it's possible I never faced this issue. I'm guessing that could be a workaround?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants