Skip to content

Commit

Permalink
Fixed access to nested objects in arrays and updated Tests. Closes #95
Browse files Browse the repository at this point in the history
  • Loading branch information
LaughDonor committed Jun 25, 2020
1 parent 3ab4ae3 commit fe7b97a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Document.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Document implements FirestoreAPI.Document, FirestoreAPI.MapValue {
}

static unwrapArray(wrappedArray: FirestoreAPI.Value[] = []): Value[] {
return wrappedArray.map(this.unwrapValue);
return wrappedArray.map(this.unwrapValue, this);
}

static unwrapDate(wrappedDate: string): Date {
Expand Down
20 changes: 5 additions & 15 deletions Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Tests implements TestManager {
}

this.expected_ = {
'array value': ['string123', 42, false],
'array value': ['string123', 42, false, { 'nested map property': 123 }],
'number value': 100,
'string value 이': 'The fox jumps over the lazy dog 름',
'boolean value': true,
Expand Down Expand Up @@ -186,6 +186,9 @@ class Tests implements TestManager {
const path = 'Test Collection';
const docs = this.db.getDocuments(path);
GSUnit.assertEquals(8, docs.length);
const doc = docs.find((doc) => doc.name!.endsWith('/New Document !@#$%^&*(),.<>?;\':"[]{}|-=_+áéíóúæÆÑ'));
GSUnit.assertNotUndefined(doc);
GSUnit.assertObjectEquals(this.expected_, doc!.obj);
}

Test_Get_Documents_By_ID(): void {
Expand All @@ -201,14 +204,6 @@ 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 @@ -258,12 +253,6 @@ 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 Expand Up @@ -353,6 +342,7 @@ class Tests implements TestManager {
const path = 'Test Collection';
const docs = this.db.query(path).Where('null value', null).Execute();
GSUnit.assertEquals(1, docs.length);
GSUnit.assertObjectEquals(this.expected_, docs[0].obj);
}

Test_Query_OrderBy_Number(): void {
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firestore_google-apps-script",
"version": "1.0.30",
"version": "1.0.31",
"description": "A Google Apps Script library for accessing Google Cloud Firestore",
"homepage": "https://github.com/grahamearley/FirestoreGoogleAppsScript",
"bugs": "https://github.com/grahamearley/FirestoreGoogleAppsScript/issues",
Expand Down

0 comments on commit fe7b97a

Please sign in to comment.