Skip to content

Commit c7391f0

Browse files
committed
fix(database, other): correctly reject for unsupported keepSynced API
previously it was attempting to reject but using an undefined helper function to do so, and there was no e2e test to probe it
1 parent 2828adc commit c7391f0

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

packages/database/e2e/query/keepSynced.e2e.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,23 @@ describe('database().ref().keepSynced()', function () {
3737
}
3838
});
3939

40-
it('toggles keepSynced on and off without throwing', async function () {
40+
it('toggles keepSynced on and off without throwing on supported platforms', async function () {
4141
if (Platform.other) return;
4242
const ref = firebase.database().ref('noop').orderByValue();
4343
await ref.keepSynced(true);
4444
await ref.keepSynced(false);
4545
});
46+
47+
it('keepSynced throws on unsupported platforms', async function () {
48+
if (!Platform.other) return;
49+
try {
50+
await firebase.database().ref('noop').orderByValue().keepSynced(true);
51+
throw new Error('did not throw');
52+
} catch (error) {
53+
error.code.should.containEql('unsupported');
54+
error.message.should.containEql('This operation is not supported on this environment.');
55+
}
56+
});
4657
});
4758

4859
describe('modular', function () {
@@ -58,13 +69,26 @@ describe('database().ref().keepSynced()', function () {
5869
}
5970
});
6071

61-
it('toggles keepSynced on and off without throwing', async function () {
72+
it('toggles keepSynced on and off without throwing on supported platforms', async function () {
6273
if (Platform.other) return;
6374
const { getDatabase, ref, orderByValue, query, keepSynced } = databaseModular;
6475

6576
const dbRef = query(ref(getDatabase(), 'noop'), orderByValue());
6677
await keepSynced(dbRef, true);
6778
await keepSynced(dbRef, false);
6879
});
80+
81+
it('keepSynced throws on unsupported platforms', async function () {
82+
if (!Platform.other) return;
83+
const { getDatabase, ref, orderByValue, query, keepSynced } = databaseModular;
84+
85+
try {
86+
await keepSynced(query(ref(getDatabase(), 'noop'), orderByValue()), true);
87+
throw new Error('did not throw');
88+
} catch (error) {
89+
error.code.should.containEql('unsupported');
90+
error.message.should.containEql('This operation is not supported on this environment.');
91+
}
92+
});
6993
});
7094
});

packages/database/lib/web/RNFBDatabaseModule.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ import {
2222
import { guard, getWebError, emitEvent } from '@react-native-firebase/app/lib/internal/web/utils';
2323
import { getQueryInstance } from './query';
2424

25+
function rejectWithCodeAndMessage(code, message) {
26+
return Promise.reject(
27+
getWebError({
28+
code,
29+
message,
30+
}),
31+
);
32+
}
33+
2534
// Converts a DataSnapshot to an object.
2635
function snapshotToObject(snapshot) {
2736
const childKeys = [];
@@ -385,7 +394,7 @@ export default {
385394
},
386395

387396
keepSynced() {
388-
return rejectPromiseWithCodeAndMessage(
397+
return rejectWithCodeAndMessage(
389398
'unsupported',
390399
'This operation is not supported on this environment.',
391400
);

0 commit comments

Comments
 (0)