Skip to content

Commit 14bce22

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

File tree

5 files changed

+122
-30
lines changed

5 files changed

+122
-30
lines changed

packages/app/lib/common/index.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,30 @@ const mapOfDeprecationReplacements = {
234234
remove: 'remove()',
235235
on: 'onValue()',
236236
once: 'get()',
237-
off: 'off()',
237+
// Query methods inherited from DatabaseQuery
238+
endAt: 'endAt()',
239+
endBefore: 'endBefore()',
240+
startAt: 'startAt()',
241+
startAfter: 'startAfter()',
242+
limitToFirst: 'limitToFirst()',
243+
limitToLast: 'limitToLast()',
244+
orderByChild: 'orderByChild()',
245+
orderByKey: 'orderByKey()',
246+
orderByValue: 'orderByValue()',
247+
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()',
238261
},
239262
},
240263
};
@@ -300,13 +323,10 @@ function getNamespace(target) {
300323
if (target._config && target._config.namespace) {
301324
return target._config.namespace;
302325
}
303-
if (target.constructor.name === 'DatabaseQuery') {
304-
return 'database';
305-
}
306326
if (target.constructor.name === 'DatabaseReference') {
307327
return 'database';
308328
}
309-
if (target.constructor.name === 'DatabaseTransaction') {
329+
if (target.constructor.name === 'DatabaseQuery') {
310330
return 'database';
311331
}
312332
const className = target.name ? target.name : target.constructor.name;

packages/database/__tests__/database.test.ts

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

303304
beforeEach(function () {
304305
databaseV9Deprecation = createCheckV9Deprecation(['database']);
305306
staticsV9Deprecation = createCheckV9Deprecation(['database', 'statics']);
306307
referenceV9Deprecation = createCheckV9Deprecation(['database', 'DatabaseReference']);
308+
queryV9Deprecation = createCheckV9Deprecation(['database', 'DatabaseQuery']);
307309

308310
// @ts-ignore test
309311
jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => {
@@ -484,17 +486,6 @@ describe('Database', function () {
484486
);
485487
});
486488

487-
// Commented out - off() is not implemented yet
488-
// it('off', function () {
489-
// const db = getDatabase();
490-
// const testRef = ref(db, 'test');
491-
// referenceV9Deprecation(
492-
// () => off(testRef, 'value', () => {}),
493-
// () => testRef.off('value', () => {}),
494-
// 'off',
495-
// );
496-
// });
497-
498489
it('onValue', function () {
499490
const db = getDatabase();
500491
const testRef = ref(db, 'test');
@@ -516,6 +507,86 @@ describe('Database', function () {
516507
});
517508
});
518509

519-
510+
describe('DatabaseQuery', function () {
511+
it('endAt', function () {
512+
const db = getDatabase();
513+
const testRef = ref(db, 'test');
514+
queryV9Deprecation(
515+
() => query(testRef, endAt('value')),
516+
() => testRef.endAt('value'),
517+
'endAt',
518+
);
519+
});
520+
521+
it('startAt', function () {
522+
const db = getDatabase();
523+
const testRef = ref(db, 'test');
524+
queryV9Deprecation(
525+
() => query(testRef, startAt('value')),
526+
() => testRef.startAt('value'),
527+
'startAt',
528+
);
529+
});
530+
531+
it('limitToFirst', function () {
532+
const db = getDatabase();
533+
const testRef = ref(db, 'test');
534+
queryV9Deprecation(
535+
() => query(testRef, limitToFirst(10)),
536+
() => testRef.limitToFirst(10),
537+
'limitToFirst',
538+
);
539+
});
540+
541+
it('limitToLast', function () {
542+
const db = getDatabase();
543+
const testRef = ref(db, 'test');
544+
queryV9Deprecation(
545+
() => query(testRef, limitToLast(10)),
546+
() => testRef.limitToLast(10),
547+
'limitToLast',
548+
);
549+
});
550+
551+
it('orderByChild', function () {
552+
const db = getDatabase();
553+
const testRef = ref(db, 'test');
554+
queryV9Deprecation(
555+
() => query(testRef, orderByChild('name')),
556+
() => testRef.orderByChild('name'),
557+
'orderByChild',
558+
);
559+
});
560+
561+
it('orderByKey', function () {
562+
const db = getDatabase();
563+
const testRef = ref(db, 'test');
564+
queryV9Deprecation(
565+
() => query(testRef, orderByKey()),
566+
() => testRef.orderByKey(),
567+
'orderByKey',
568+
);
569+
});
570+
571+
it('orderByValue', function () {
572+
const db = getDatabase();
573+
const testRef = ref(db, 'test');
574+
queryV9Deprecation(
575+
() => query(testRef, orderByValue()),
576+
() => testRef.orderByValue(),
577+
'orderByValue',
578+
);
579+
});
580+
581+
it('equalTo', function () {
582+
const db = getDatabase();
583+
const testRef = ref(db, 'test');
584+
queryV9Deprecation(
585+
() => query(testRef, equalTo('value')),
586+
() => testRef.equalTo('value'),
587+
'equalTo',
588+
);
589+
});
590+
});
520591
});
521592
});

packages/database/lib/DatabaseQuery.js

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
import DatabaseDataSnapshot from './DatabaseDataSnapshot';
3131
import DatabaseSyncTree from './DatabaseSyncTree';
3232

33-
import { createDeprecationProxy } from '@react-native-firebase/app/lib/common';
33+
import { createDeprecationProxy, MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common';
3434

3535
const eventTypes = ['value', 'child_added', 'child_changed', 'child_moved', 'child_removed'];
3636

@@ -85,7 +85,7 @@ export default class DatabaseQuery extends ReferenceBase {
8585
const modifiers = this._modifiers._copy().endAt(value, key);
8686
modifiers.validateModifiers('firebase.database().ref().endAt()');
8787

88-
return new DatabaseQuery(this._database, this.path, modifiers);
88+
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
8989
}
9090

9191
/**
@@ -119,7 +119,8 @@ export default class DatabaseQuery extends ReferenceBase {
119119
);
120120
}
121121

122-
return this.startAt(value, key).endAt(value, key);
122+
// Internal method calls should always use MODULAR_DEPRECATION_ARG to avoid false deprecation warnings
123+
return this.startAt.call(this, value, key, MODULAR_DEPRECATION_ARG).endAt.call(this, value, MODULAR_DEPRECATION_ARG);
123124
}
124125

125126
/**
@@ -157,11 +158,11 @@ export default class DatabaseQuery extends ReferenceBase {
157158
);
158159
}
159160

160-
return new DatabaseQuery(
161+
return createDeprecationProxy(new DatabaseQuery(
161162
this._database,
162163
this.path,
163164
this._modifiers._copy().limitToFirst(limit),
164-
);
165+
));
165166
}
166167

167168
/**
@@ -182,7 +183,7 @@ export default class DatabaseQuery extends ReferenceBase {
182183
);
183184
}
184185

185-
return new DatabaseQuery(this._database, this.path, this._modifiers._copy().limitToLast(limit));
186+
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, this._modifiers._copy().limitToLast(limit)));
186187
}
187188

188189
/**
@@ -436,7 +437,7 @@ export default class DatabaseQuery extends ReferenceBase {
436437
const modifiers = this._modifiers._copy().orderByChild(path);
437438
modifiers.validateModifiers('firebase.database().ref().orderByChild()');
438439

439-
return new DatabaseQuery(this._database, this.path, modifiers);
440+
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
440441
}
441442

442443
/**
@@ -452,7 +453,7 @@ export default class DatabaseQuery extends ReferenceBase {
452453
const modifiers = this._modifiers._copy().orderByKey();
453454
modifiers.validateModifiers('firebase.database().ref().orderByKey()');
454455

455-
return new DatabaseQuery(this._database, this.path, modifiers);
456+
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
456457
}
457458

458459
/**
@@ -468,7 +469,7 @@ export default class DatabaseQuery extends ReferenceBase {
468469
const modifiers = this._modifiers._copy().orderByPriority();
469470
modifiers.validateModifiers('firebase.database().ref().orderByPriority()');
470471

471-
return new DatabaseQuery(this._database, this.path, modifiers);
472+
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
472473
}
473474

474475
/**
@@ -484,7 +485,7 @@ export default class DatabaseQuery extends ReferenceBase {
484485
const modifiers = this._modifiers._copy().orderByValue();
485486
modifiers.validateModifiers('firebase.database().ref().orderByValue()');
486487

487-
return new DatabaseQuery(this._database, this.path, modifiers);
488+
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
488489
}
489490

490491
startAt(value, key) {
@@ -509,7 +510,7 @@ export default class DatabaseQuery extends ReferenceBase {
509510
const modifiers = this._modifiers._copy().startAt(value, key);
510511
modifiers.validateModifiers('firebase.database().ref().startAt()');
511512

512-
return new DatabaseQuery(this._database, this.path, modifiers);
513+
return createDeprecationProxy(new DatabaseQuery(this._database, this.path, modifiers));
513514
}
514515

515516
toJSON() {

packages/database/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class FirebaseDatabaseModule extends FirebaseModule {
114114
path = path.slice(0, path.indexOf('?'));
115115
}
116116

117-
return new DatabaseReference(this, path || '/');
117+
return createDeprecationProxy(new DatabaseReference(this, path || '/'));
118118
}
119119

120120
/**

packages/database/lib/modular/query.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class QueryConstraint {
2424

2525
_apply(query) {
2626
// eslint-disable-next-line prefer-spread
27-
return query[this._type].apply(query, this._args, MODULAR_DEPRECATION_ARG);
27+
return query[this._type].apply(query, [...this._args, MODULAR_DEPRECATION_ARG]);
2828
}
2929
}
3030

0 commit comments

Comments
 (0)