Skip to content

Commit

Permalink
Fixed bug where .getDocuments and .query didn't return Document fields.
Browse files Browse the repository at this point in the history
Closes #94

Added UnitTests to cover the above scenario.
Added .gitattributes to handle line endings. Closes #93
Removed all GitHub domain prefixes on Markdown files. Enhances #92
  • Loading branch information
LaughDonor committed Jun 24, 2020
1 parent cc1be09 commit 3ab4ae3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Set the default behavior, in case people don't have core.autocrlf set.
* text=auto

# Files with crlf endings
LICENSE text eol=crlf
*.ts text eol=crlf
*.json text eol=crlf
*.md text eol=crlf
*.yml text eol=crlf
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Hi! Thanks for creating a pull request.

Please make sure you have read the [Contributing](https://github.com/grahamearley/FirestoreGoogleAppsScript/blob/main/.github/CONTRIBUTING.md) guidelines before submitting.
Please make sure you have read the [Contributing](/grahamearley/FirestoreGoogleAppsScript/blob/main/.github/CONTRIBUTING.md) guidelines before submitting.

(You can delete this text).
10 changes: 5 additions & 5 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
![GitHub release (latest by date)](https://img.shields.io/github/v/release/grahamearley/FirestoreGoogleAppsScript)
[![Google Apps Script](https://img.shields.io/badge/google%20apps%20script-v8-%234285f4)](https://developers.google.com/apps-script/guides/v8-runtime)
[![TypeScript](https://img.shields.io/badge/typescript-3.9.5-%23294E80)](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-9.html)
[![clasp](https://img.shields.io/badge/built%20with-clasp-4285f4.svg)](https://github.com/google/clasp)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/grahamearley/FirestoreGoogleAppsScript)](https://github.com/grahamearley/FirestoreGoogleAppsScript/pulls)
[![GitHub issues](https://img.shields.io/github/issues/grahamearley/FirestoreGoogleAppsScript)](https://github.com/grahamearley/FirestoreGoogleAppsScript/issues)
[![clasp](https://img.shields.io/badge/built%20with-clasp-4285f4.svg)](/google/clasp)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](/prettier/prettier)
[![GitHub pull requests](https://img.shields.io/github/issues-pr/grahamearley/FirestoreGoogleAppsScript)](/grahamearley/FirestoreGoogleAppsScript/pulls)
[![GitHub issues](https://img.shields.io/github/issues/grahamearley/FirestoreGoogleAppsScript)](/grahamearley/FirestoreGoogleAppsScript/issues)
![Tests](https://img.shields.io/endpoint?url=https%3A%2F%2Fscript.google.com%2Fmacros%2Fs%2FAKfycbzle3ze4mtGAcTNPlqISSFxtmPqvdcNOFauiC4Q0g%2Fexec)

### A Google Apps Script library for accessing Google Cloud Firestore.
Expand Down Expand Up @@ -152,7 +152,7 @@ See other library methods and details [in the wiki](/grahamearley/FirestoreGoogl
## Contributions
Contributions are welcome — send a pull request! See [here](/grahamearley/FirestoreGoogleAppsScript/blob/main/.github/CONTRIBUTING.md) for more information on contributing.

After cloning this repository, you can push it to your own private copy of this Google Apps Script project to test it yourself. See [here](https://github.com/google/clasp) for directions on using `clasp` to develop App Scripts locally.
After cloning this repository, you can push it to your own private copy of this Google Apps Script project to test it yourself. See [here](/google/clasp) for directions on using `clasp` to develop App Scripts locally.
Install all packages from `package.json` with a bare `npm install`.


Expand Down
2 changes: 1 addition & 1 deletion FirestoreRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class FirestoreRead {
// Remove missing entries
documents = documents.filter((docItem: FirestoreAPI.BatchGetDocumentsResponse) => docItem.found);
return documents.map((docItem: FirestoreAPI.BatchGetDocumentsResponse) => {
const doc = docItem.found! as Document;
const doc = new Document(docItem.found!, { readTime: docItem.readTime } as Document);
doc.readTime = docItem.readTime;
return doc;
});
Expand Down
7 changes: 4 additions & 3 deletions Query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ enum UnaryFilterOps_ {
* @see {@link https://firebase.google.com/docs/firestore/reference/rest/v1/StructuredQuery Firestore Structured Query}
*/
class Query implements FirestoreAPI.StructuredQuery {
select: FirestoreAPI.Projection;
select?: FirestoreAPI.Projection;
from?: FirestoreAPI.CollectionSelector[];
where?: FirestoreAPI.Filter;
orderBy?: FirestoreAPI.Order[];
Expand All @@ -45,7 +45,6 @@ class Query implements FirestoreAPI.StructuredQuery {
* @param {QueryCallback} callback the function that is executed with the internally compiled query
*/
constructor(from: string, callback: QueryCallback) {
this.select = { fields: [] };
this.callback = callback;
if (from) {
this.from = [{ collectionId: from }];
Expand Down Expand Up @@ -141,7 +140,9 @@ class Query implements FirestoreAPI.StructuredQuery {
// Catch undefined or blank strings and return document name
field = '__name__';
}

if (!this.select) {
this.select = { fields: [] };
}
this.select['fields']!.push(this.fieldRef_(field));
return this;
}
Expand Down
16 changes: 15 additions & 1 deletion Tests.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function StoreCredentials_(): void {
function StoreCredentials_(): void {
/** DO NOT SAVE CREDENTIALS HERE */
const email = '[email protected]';
const key = '-----BEGIN PRIVATE KEY-----\nLine\nLine\n-----END PRIVATE KEY-----';
Expand Down Expand Up @@ -201,6 +201,14 @@ class Tests implements TestManager {
GSUnit.assertEquals(ids.length - 1, docs.length);
}

Test_Get_Documents_Content(): void {
const path = 'Test Collection';
const ids = ['New Document !@#$%^&*(),.<>?;\':"[]{}|-=_+áéíóúæÆÑ'];
const docs = this.db.getDocuments(path, ids);
GSUnit.assertEquals(ids.length, docs.length);
GSUnit.assertObjectEquals(this.expected_, docs[0].obj);
}

Test_Get_Documents_By_ID_Missing(): void {
const path = 'Missing Collection';
const ids = [
Expand Down Expand Up @@ -250,6 +258,12 @@ class Tests implements TestManager {
GSUnit.assertArrayEquals(expected, docs);
}

Test_Query_One(): void {
const path = 'Test Collection';
const docs = this.db.query(path).Where('null value', null).Execute();
GSUnit.assertObjectEquals(this.expected_, docs[0].obj);
}

Test_Query_Select_Name(): void {
const path = 'Test Collection';
const docs = this.db.query(path).Select().Execute();
Expand Down

0 comments on commit 3ab4ae3

Please sign in to comment.