Skip to content

Commit

Permalink
fix(database, update): allow empty objects in ref.update()
Browse files Browse the repository at this point in the history
As pointed out by @daveGregorian firebase-js-sdk allows empty objects
while the code here was enforcing that the objects had at least one key

Fixes #5218
  • Loading branch information
mikehardy committed Apr 27, 2021
1 parent 589fcb0 commit 90087ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 27 deletions.
30 changes: 9 additions & 21 deletions packages/database/e2e/reference/update.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,6 @@ describe('database().ref().update()', function () {
await firebase.database().ref(TEST_PATH).remove();
});

it('throws if values is not an object', async function () {
try {
await firebase.database().ref(TEST_PATH).update('foo');
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql("'values' must be an object");
return Promise.resolve();
}
});

it('throws if values does not contain any values', async function () {
try {
await firebase.database().ref(TEST_PATH).update({});
return Promise.reject(new Error('Did not throw an Error.'));
} catch (error) {
error.message.should.containEql("'values' must be an object containing multiple values");
return Promise.resolve();
}
});

it('throws if update paths are not valid', async function () {
try {
await firebase.database().ref(TEST_PATH).update({
Expand Down Expand Up @@ -71,7 +51,7 @@ describe('database().ref().update()', function () {
}
});

it('updates values', async function () {
it.only('updates values', async function () {
const value = Date.now();
const ref = firebase.database().ref(TEST_PATH);
await ref.update({
Expand All @@ -83,6 +63,14 @@ describe('database().ref().update()', function () {
foo: value,
}),
);

await ref.update({}); // empty update should be get same result
const snapshot2 = await ref.once('value');
snapshot2.val().should.eql(
jet.contextify({
foo: value,
}),
);
});

it('callback if function is passed', async function () {
Expand Down
6 changes: 0 additions & 6 deletions packages/database/lib/DatabaseReference.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ export default class DatabaseReference extends DatabaseQuery {
throw new Error("firebase.database().ref().update(*) 'values' must be an object.");
}

if (!Object.keys(values).length) {
throw new Error(
"firebase.database().ref().update(*) 'values' must be an object containing multiple values.",
);
}

const keys = Object.keys(values);
for (let i = 0; i < keys.length; i++) {
if (!isValidPath(keys[i])) {
Expand Down

0 comments on commit 90087ce

Please sign in to comment.