Skip to content

Commit e3c5d2b

Browse files
committed
chore: query tests
1 parent 14bce22 commit e3c5d2b

File tree

3 files changed

+67
-40
lines changed

3 files changed

+67
-40
lines changed

packages/app/lib/common/index.js

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,6 @@ const mapOfDeprecationReplacements = {
234234
remove: 'remove()',
235235
on: 'onValue()',
236236
once: 'get()',
237-
// Query methods inherited from DatabaseQuery
238237
endAt: 'endAt()',
239238
endBefore: 'endBefore()',
240239
startAt: 'startAt()',
@@ -245,19 +244,11 @@ const mapOfDeprecationReplacements = {
245244
orderByKey: 'orderByKey()',
246245
orderByValue: 'orderByValue()',
247246
equalTo: 'equalTo()',
248-
},
249-
DatabaseQuery: {
250-
endAt: 'endAt()',
251-
endBefore: 'endBefore()',
252-
startAt: 'startAt()',
253-
startAfter: 'startAfter()',
254-
limitToFirst: 'limitToFirst()',
255-
limitToLast: 'limitToLast()',
256-
orderByChild: 'orderByChild()',
257-
orderByKey: 'orderByKey()',
258-
orderByValue: 'orderByValue()',
259-
equalTo: 'equalTo()',
260-
query: 'query()',
247+
setPriority: 'setPriority()',
248+
push: 'push()',
249+
onDisconnect: 'onDisconnect()',
250+
keepSynced: 'keepSynced()',
251+
transaction: 'runTransaction()',
261252
},
262253
},
263254
};
@@ -326,9 +317,6 @@ function getNamespace(target) {
326317
if (target.constructor.name === 'DatabaseReference') {
327318
return 'database';
328319
}
329-
if (target.constructor.name === 'DatabaseQuery') {
330-
return 'database';
331-
}
332320
const className = target.name ? target.name : target.constructor.name;
333321
return Object.keys(mapOfDeprecationReplacements).find(key => {
334322
if (mapOfDeprecationReplacements[key][className]) {
@@ -398,14 +386,6 @@ export function createDeprecationProxy(instance) {
398386
// we want to capture setLogLevel function call which we do below
399387
return Reflect.get(target, prop, receiver);
400388
}
401-
402-
if (target.constructor.name === 'DatabaseQuery') {
403-
return target.constructor.name;
404-
}
405-
406-
if (target.constructor.name === 'DatabaseTransaction') {
407-
return target.constructor.name;
408-
}
409389
}
410390

411391
if (typeof originalMethod === 'function') {

packages/database/__tests__/database.test.ts

Lines changed: 60 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,14 +299,11 @@ describe('Database', function () {
299299
let databaseV9Deprecation: CheckV9DeprecationFunction;
300300
let staticsV9Deprecation: CheckV9DeprecationFunction;
301301
let referenceV9Deprecation: CheckV9DeprecationFunction;
302-
let queryV9Deprecation: CheckV9DeprecationFunction;
303302

304303
beforeEach(function () {
305304
databaseV9Deprecation = createCheckV9Deprecation(['database']);
306305
staticsV9Deprecation = createCheckV9Deprecation(['database', 'statics']);
307306
referenceV9Deprecation = createCheckV9Deprecation(['database', 'DatabaseReference']);
308-
queryV9Deprecation = createCheckV9Deprecation(['database', 'DatabaseQuery']);
309-
310307
// @ts-ignore test
311308
jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => {
312309
return new Proxy(
@@ -505,13 +502,11 @@ describe('Database', function () {
505502
'once',
506503
);
507504
});
508-
});
509505

510-
describe('DatabaseQuery', function () {
511506
it('endAt', function () {
512507
const db = getDatabase();
513508
const testRef = ref(db, 'test');
514-
queryV9Deprecation(
509+
referenceV9Deprecation(
515510
() => query(testRef, endAt('value')),
516511
() => testRef.endAt('value'),
517512
'endAt',
@@ -521,7 +516,7 @@ describe('Database', function () {
521516
it('startAt', function () {
522517
const db = getDatabase();
523518
const testRef = ref(db, 'test');
524-
queryV9Deprecation(
519+
referenceV9Deprecation(
525520
() => query(testRef, startAt('value')),
526521
() => testRef.startAt('value'),
527522
'startAt',
@@ -531,7 +526,7 @@ describe('Database', function () {
531526
it('limitToFirst', function () {
532527
const db = getDatabase();
533528
const testRef = ref(db, 'test');
534-
queryV9Deprecation(
529+
referenceV9Deprecation(
535530
() => query(testRef, limitToFirst(10)),
536531
() => testRef.limitToFirst(10),
537532
'limitToFirst',
@@ -541,7 +536,7 @@ describe('Database', function () {
541536
it('limitToLast', function () {
542537
const db = getDatabase();
543538
const testRef = ref(db, 'test');
544-
queryV9Deprecation(
539+
referenceV9Deprecation(
545540
() => query(testRef, limitToLast(10)),
546541
() => testRef.limitToLast(10),
547542
'limitToLast',
@@ -551,7 +546,7 @@ describe('Database', function () {
551546
it('orderByChild', function () {
552547
const db = getDatabase();
553548
const testRef = ref(db, 'test');
554-
queryV9Deprecation(
549+
referenceV9Deprecation(
555550
() => query(testRef, orderByChild('name')),
556551
() => testRef.orderByChild('name'),
557552
'orderByChild',
@@ -561,7 +556,7 @@ describe('Database', function () {
561556
it('orderByKey', function () {
562557
const db = getDatabase();
563558
const testRef = ref(db, 'test');
564-
queryV9Deprecation(
559+
referenceV9Deprecation(
565560
() => query(testRef, orderByKey()),
566561
() => testRef.orderByKey(),
567562
'orderByKey',
@@ -571,7 +566,7 @@ describe('Database', function () {
571566
it('orderByValue', function () {
572567
const db = getDatabase();
573568
const testRef = ref(db, 'test');
574-
queryV9Deprecation(
569+
referenceV9Deprecation(
575570
() => query(testRef, orderByValue()),
576571
() => testRef.orderByValue(),
577572
'orderByValue',
@@ -581,12 +576,64 @@ describe('Database', function () {
581576
it('equalTo', function () {
582577
const db = getDatabase();
583578
const testRef = ref(db, 'test');
584-
queryV9Deprecation(
579+
referenceV9Deprecation(
585580
() => query(testRef, equalTo('value')),
586581
() => testRef.equalTo('value'),
587582
'equalTo',
588583
);
589584
});
585+
586+
it('setPriority', function () {
587+
const db = getDatabase();
588+
const testRef = ref(db, 'test');
589+
referenceV9Deprecation(
590+
() => setPriority(testRef, 'value'),
591+
() => testRef.setPriority('value'),
592+
'setPriority',
593+
);
594+
});
595+
596+
it('push', function () {
597+
const db = getDatabase();
598+
const testRef = ref(db, 'test');
599+
referenceV9Deprecation(
600+
() => push(testRef, 'value'),
601+
() => testRef.push('value'),
602+
'push',
603+
);
604+
});
605+
606+
it('onDisconnect', function () {
607+
const db = getDatabase();
608+
const testRef = ref(db, 'test');
609+
referenceV9Deprecation(
610+
() => onDisconnect(testRef),
611+
() => testRef.onDisconnect(),
612+
'onDisconnect',
613+
);
614+
});
615+
616+
it('keepSynced', function () {
617+
const db = getDatabase();
618+
const testRef = ref(db, 'test');
619+
referenceV9Deprecation(
620+
() => keepSynced(testRef, true),
621+
() => testRef.keepSynced(true),
622+
'keepSynced',
623+
);
624+
});
625+
});
626+
627+
describe('DatabaseTransaction', function() {
628+
it('runTransaction', function () {
629+
const db = getDatabase();
630+
const testRef = ref(db, 'test');
631+
referenceV9Deprecation(
632+
() => runTransaction(testRef, (currentData) => currentData, { applyLocally: true }),
633+
() => testRef.transaction((currentData) => currentData, undefined, true),
634+
'transaction'
635+
);
636+
});
590637
});
591638
});
592639
});

packages/database/lib/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*
1616
*/
1717

18-
import { isAndroid, isBoolean, isNumber, isString } from '@react-native-firebase/app/lib/common';
18+
import { isAndroid, isBoolean, isNumber, isString, MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common';
1919
import {
2020
createModuleNamespace,
2121
FirebaseModule,
@@ -58,7 +58,7 @@ class FirebaseDatabaseModule extends FirebaseModule {
5858
_syncServerTimeOffset() {
5959
this.ref('.info/serverTimeOffset').on('value', snapshot => {
6060
this._serverTimeOffset = snapshot.val();
61-
});
61+
}, MODULAR_DEPRECATION_ARG);
6262
}
6363

6464
/**

0 commit comments

Comments
 (0)