mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2025-11-14 08:42:08 +10:00
Firebase Stub: query parameters not kept between ref calls
This commit is contained in:
@ -255,5 +255,30 @@ describe('FirebaseStub', () => {
|
||||
expect(resume.user).toEqual(DatabaseConstants.user1.uid),
|
||||
);
|
||||
});
|
||||
|
||||
it('previously set query parameters are not kept when retrieving reference again', async () => {
|
||||
let reference = null;
|
||||
|
||||
reference = FirebaseStub.database().ref(DatabaseConstants.resumesPath);
|
||||
expect(reference).toBeTruthy();
|
||||
const { uuid } = reference;
|
||||
expect(reference.orderByChildPath).toHaveLength(0);
|
||||
expect(reference.equalToValue).toHaveLength(0);
|
||||
|
||||
reference = FirebaseStub.database()
|
||||
.ref(DatabaseConstants.resumesPath)
|
||||
.orderByChild('user')
|
||||
.equalTo('testuser1');
|
||||
expect(reference).toBeTruthy();
|
||||
expect(reference.uuid).toBe(uuid);
|
||||
expect(reference.orderByChildPath).toBe('user');
|
||||
expect(reference.equalToValue).toBe('testuser1');
|
||||
|
||||
reference = FirebaseStub.database().ref(DatabaseConstants.resumesPath);
|
||||
expect(reference).toBeTruthy();
|
||||
expect(reference.uuid).toBe(uuid);
|
||||
expect(reference.orderByChildPath).toHaveLength(0);
|
||||
expect(reference.equalToValue).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@ -78,6 +78,7 @@ class Database {
|
||||
const newRef = new Reference(referencePath, () => this._data);
|
||||
const existingRef = this._references[newRef.path];
|
||||
if (existingRef) {
|
||||
existingRef.initializeQueryParameters();
|
||||
return existingRef;
|
||||
}
|
||||
|
||||
|
||||
@ -29,8 +29,7 @@ class Reference {
|
||||
|
||||
this._getDatabaseData = getDatabaseData;
|
||||
|
||||
this._orderByChildPath = '';
|
||||
this._equalToValue = '';
|
||||
this.initializeQueryParameters();
|
||||
}
|
||||
|
||||
get path() {
|
||||
@ -41,6 +40,14 @@ class Reference {
|
||||
return this._uuid;
|
||||
}
|
||||
|
||||
get orderByChildPath() {
|
||||
return this._orderByChildPath;
|
||||
}
|
||||
|
||||
get equalToValue() {
|
||||
return this._equalToValue;
|
||||
}
|
||||
|
||||
getData() {
|
||||
const databaseData = this._getDatabaseData();
|
||||
|
||||
@ -59,10 +66,10 @@ class Reference {
|
||||
) {
|
||||
data = this.path in databaseData ? databaseData[this.path] : null;
|
||||
|
||||
if (data && this._orderByChildPath && this._equalToValue) {
|
||||
if (data && this.orderByChildPath && this.equalToValue) {
|
||||
return Object.fromEntries(
|
||||
Object.entries(data).filter(
|
||||
([, value]) => value[this._orderByChildPath] === this._equalToValue,
|
||||
([, value]) => value[this.orderByChildPath] === this.equalToValue,
|
||||
),
|
||||
);
|
||||
}
|
||||
@ -92,6 +99,11 @@ class Reference {
|
||||
return null;
|
||||
}
|
||||
|
||||
initializeQueryParameters() {
|
||||
this._orderByChildPath = '';
|
||||
this._equalToValue = '';
|
||||
}
|
||||
|
||||
off() {
|
||||
return this !== null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user