[database] Fix wrong path from snapshot reference #679
This commit is contained in:
parent
3f1c8c4571
commit
0ace49ca81
@ -16,11 +16,7 @@ export default class Query {
|
||||
_reference: Reference;
|
||||
modifiers: Array<DatabaseModifier>;
|
||||
|
||||
constructor(
|
||||
ref: Reference,
|
||||
path: string,
|
||||
existingModifiers?: Array<DatabaseModifier>
|
||||
) {
|
||||
constructor(ref: Reference, existingModifiers?: Array<DatabaseModifier>) {
|
||||
this.modifiers = existingModifiers ? [...existingModifiers] : [];
|
||||
this._reference = ref;
|
||||
}
|
||||
|
@ -89,7 +89,7 @@ export default class Reference extends ReferenceBase {
|
||||
this._promise = null;
|
||||
this._refListeners = {};
|
||||
this._database = database;
|
||||
this._query = new Query(this, path, existingModifiers);
|
||||
this._query = new Query(this, existingModifiers);
|
||||
getLogger(database).debug('Created new Reference', this._getRefKey());
|
||||
}
|
||||
|
||||
@ -493,7 +493,7 @@ export default class Reference extends ReferenceBase {
|
||||
* @returns {string}
|
||||
*/
|
||||
toString(): string {
|
||||
return this.path;
|
||||
return `${this._database.app.options.databaseURL}/${this.path}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -5,7 +5,14 @@ export default class ReferenceBase {
|
||||
path: string;
|
||||
|
||||
constructor(path: string) {
|
||||
this.path = path || '/';
|
||||
if (path) {
|
||||
this.path =
|
||||
path.length > 1 && path.endsWith('/')
|
||||
? path.substring(0, path.length - 1)
|
||||
: path;
|
||||
} else {
|
||||
this.path = '/';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -315,6 +315,34 @@ function issueTests({ describe, it, context, firebase }) {
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('issue_679', () => {
|
||||
context('path from snapshot reference', () => {
|
||||
it('should match web SDK', async () => {
|
||||
// Setup
|
||||
const nativeRef = firebase.native.database().ref('tests/issues/679');
|
||||
const webRef = firebase.web.database().ref('tests/issues/679');
|
||||
const nativeRef2 = firebase.native.database().ref('tests/issues/679/');
|
||||
const webRef2 = firebase.web.database().ref('tests/issues/679/');
|
||||
|
||||
// Test
|
||||
|
||||
webRef.toString().should.equal(nativeRef.toString());
|
||||
webRef2.toString().should.equal(nativeRef2.toString());
|
||||
});
|
||||
|
||||
it('should be correct when returned from native', async () => {
|
||||
// Setup
|
||||
const nativeRef = firebase.native.database().ref('tests/issues/679/');
|
||||
const webRef = firebase.web.database().ref('tests/issues/679/');
|
||||
|
||||
const nativeSnapshot = await nativeRef.once('value');
|
||||
const webSnapshot = await webRef.once('value');
|
||||
|
||||
webSnapshot.ref.toString().should.equal(nativeSnapshot.ref.toString());
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default issueTests;
|
||||
|
Loading…
x
Reference in New Issue
Block a user