Skip to content

Commit

Permalink
Rejecting 'null' and 'undefined' as arugments for CollectionReference…
Browse files Browse the repository at this point in the history
….doc()
  • Loading branch information
schmidt-sebastian committed Oct 6, 2017
1 parent 522dba1 commit 53605a8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/reference.js
Original file line number Diff line number Diff line change
Expand Up @@ -1783,10 +1783,10 @@ class CollectionReference extends Query {
* console.log(`Reference with auto-id: ${documentRefWithAutoId.path}`);
*/
doc(documentPath) {
validate.isOptionalResourcePath('documentPath', documentPath);

if (!is.defined(documentPath)) {
if (arguments.length === 0) {
documentPath = Firestore.autoId();
} else {
validate.isResourcePath('documentPath', documentPath);
}

let path = this._referencePath.append(documentPath);
Expand Down
10 changes: 7 additions & 3 deletions test/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ describe('Collection interface', function() {

assert.throws(() => {
collectionRef.doc(false);
}, new RegExp('Argument "documentPath" is not a valid ResourcePath. ' + 'Path is not a string.'));
}, /Argument "documentPath" is not a valid ResourcePath. Path is not a string./);

assert.throws(() => {
collectionRef.doc('doc/col');
}, /Argument "documentPath" must point to a document\./);
collectionRef.doc(null);
}, /Argument "documentPath" is not a valid ResourcePath. Path is not a string./);

assert.throws(() => {
collectionRef.doc(undefined);
}, /Argument "documentPath" is not a valid ResourcePath. Path is not a string./);

documentRef = collectionRef.doc('docId/colId/docId');
assert.ok(is.instance(documentRef, DocumentReference));
Expand Down

0 comments on commit 53605a8

Please sign in to comment.