Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('constructed using helper', function() {
assert.ok(is.instance(Firestore.Timestamp.now(), Firestore.Timestamp));
let actual = Firestore.Timestamp.fromDate(new Date(123123));
let expected = new Firestore.Timestamp(123, 123000000);
assert.ok(actual.isEqual(expected));
actual = Firestore.Timestamp.fromMillis(123123);
expected = new Firestore.Timestamp(123, 123000000);
assert.ok(actual.isEqual(expected));
});
it('returns collection', function() {
let collection = firestore.collection('col1/doc1/col2');
assert.ok(is.instance(collection, CollectionReference));
});
return promise.then(documentRef => {
assert.ok(is.instance(documentRef, DocumentReference));
assert.equal(collectionRef.id, 'collectionId');
assert.ok(documentRef.id.length, 20);
});
});
}, /Argument "documentPath" is not a valid ResourcePath. Path must be a non-empty string./);
assert.throws(() => {
collectionRef.doc('');
}, /Argument "documentPath" is not a valid ResourcePath. Path must be a non-empty string./);
assert.throws(() => {
collectionRef.doc(undefined);
}, /Argument "documentPath" is not a valid ResourcePath. Path must be a non-empty string./);
assert.throws(function() {
collectionRef.doc('doc/coll');
}, /Argument "documentPath" must point to a document, but was "doc\/coll". Your path does not contain an even number of components\./);
documentRef = collectionRef.doc('docId/colId/docId');
assert.ok(is.instance(documentRef, DocumentReference));
});
setImmediate(function() {
for (let arg of args) {
if (is.instance(arg, Error)) {
stream.destroy(arg);
return;
}
stream.push(arg);
}
stream.push(null);
});
return createInstance(overrides).then(firestore => {
let collectionRef = firestore.collection('collectionId');
assert.ok(collectionRef.add);
let promise = collectionRef.add({});
assert.ok(is.instance(promise, Promise));
return promise.then(documentRef => {
assert.ok(is.instance(documentRef, DocumentReference));
assert.equal(collectionRef.id, 'collectionId');
assert.ok(documentRef.id.length, 20);
});
});
});
setImmediate(function() {
for (let arg of args) {
if (is.instance(arg, Error)) {
stream.destroy(arg);
return;
}
stream.push(arg);
}
stream.push(null);
});
setImmediate(function() {
for (let arg of args) {
if (is.instance(arg, Error)) {
stream.destroy(arg);
return;
}
stream.push(arg);
}
stream.push(null);
});
get(refOrQuery) {
if (!this._writeBatch.isEmpty) {
throw new Error(
'Firestore transactions require all reads to be ' +
'executed before all writes.'
);
}
if (is.instance(refOrQuery, DocumentReference)) {
return this._firestore
.getAll_([refOrQuery], {transactionId: this._transactionId})
.then(res => {
return Promise.resolve(res[0]);
});
}
if (is.instance(refOrQuery, Query)) {
return refOrQuery._get({transactionId: this._transactionId});
}
throw new Error('Argument "refOrQuery" must be a DocumentRef or a Query.');
}
get(refOrQuery) {
if (!this._writeBatch.isEmpty) {
throw new Error(READ_AFTER_WRITE_ERROR_MSG);
}
if (is.instance(refOrQuery, DocumentReference)) {
return this._firestore
.getAll_([refOrQuery], this._requestTag, this._transactionId)
.then(res => {
return Promise.resolve(res[0]);
});
}
if (is.instance(refOrQuery, Query)) {
return refOrQuery._get(this._transactionId);
}
throw new Error('Argument "refOrQuery" must be a DocumentRef or a Query.');
}