Skip to content

Commit 086d478

Browse files
committed
Manually prepares the bundle strings.
1 parent 7fda4c4 commit 086d478

File tree

1 file changed

+10
-24
lines changed

1 file changed

+10
-24
lines changed

packages/firestore/test/integration/api/bundle.test.ts

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,17 @@ function verifyInProgress(
4545
expect(p.documentsLoaded).to.equal(expectedDocuments);
4646
}
4747

48-
const TEMPLATE_PROJECT_ID = 'test-project';
4948
// This template is generated from bundleWithTestDocsAndQueries in '../util/internal_helpsers.ts',
5049
// and manually copied here.
51-
const BUNDLE_TEMPLATE =
52-
'125{"metadata":{"id":"test-bundle","createTime":{"seconds":1001,"nanos":9999},"version":1,"totalDocuments":2,"totalBytes":1503}}374{"namedQuery":{"name":"limit","readTime":{"seconds":1000,"nanos":9999},"bundledQuery":{"parent":"projects/test-project/databases/(default)/documents","structuredQuery":{"from":[{"collectionId":"coll-1"}],"orderBy":[{"field":{"fieldPath":"bar"},"direction":"DESCENDING"},{"field":{"fieldPath":"__name__"},"direction":"DESCENDING"}],"limit":{"value":1}},"limitType":"FIRST"}}}381{"namedQuery":{"name":"limit-to-last","readTime":{"seconds":1000,"nanos":9999},"bundledQuery":{"parent":"projects/test-project/databases/(default)/documents","structuredQuery":{"from":[{"collectionId":"coll-1"}],"orderBy":[{"field":{"fieldPath":"bar"},"direction":"DESCENDING"},{"field":{"fieldPath":"__name__"},"direction":"DESCENDING"}],"limit":{"value":1}},"limitType":"LAST"}}}147{"documentMetadata":{"name":"projects/test-project/databases/(default)/documents/coll-1/a","readTime":{"seconds":1000,"nanos":9999},"exists":true}}218{"document":{"name":"projects/test-project/databases/(default)/documents/coll-1/a","createTime":{"seconds":1,"nanos":9},"updateTime":{"seconds":1,"nanos":9},"fields":{"k":{"stringValue":"a"},"bar":{"integerValue":1}}}}147{"documentMetadata":{"name":"projects/test-project/databases/(default)/documents/coll-1/b","readTime":{"seconds":1000,"nanos":9999},"exists":true}}218{"document":{"name":"projects/test-project/databases/(default)/documents/coll-1/b","createTime":{"seconds":1,"nanos":9},"updateTime":{"seconds":1,"nanos":9},"fields":{"k":{"stringValue":"b"},"bar":{"integerValue":2}}}}';
50+
const BUNDLE_TEMPLATE = [
51+
'{"metadata":{"id":"test-bundle","createTime":{"seconds":1001,"nanos":9999},"version":1,"totalDocuments":2,"totalBytes":1503}}',
52+
'{"namedQuery":{"name":"limit","readTime":{"seconds":1000,"nanos":9999},"bundledQuery":{"parent":"projects/{0}/databases/(default)/documents","structuredQuery":{"from":[{"collectionId":"coll-1"}],"orderBy":[{"field":{"fieldPath":"bar"},"direction":"DESCENDING"},{"field":{"fieldPath":"__name__"},"direction":"DESCENDING"}],"limit":{"value":1}},"limitType":"FIRST"}}}',
53+
'{"namedQuery":{"name":"limit-to-last","readTime":{"seconds":1000,"nanos":9999},"bundledQuery":{"parent":"projects/{0}/databases/(default)/documents","structuredQuery":{"from":[{"collectionId":"coll-1"}],"orderBy":[{"field":{"fieldPath":"bar"},"direction":"DESCENDING"},{"field":{"fieldPath":"__name__"},"direction":"DESCENDING"}],"limit":{"value":1}},"limitType":"LAST"}}}',
54+
'{"documentMetadata":{"name":"projects/{0}/databases/(default)/documents/coll-1/a","readTime":{"seconds":1000,"nanos":9999},"exists":true}}',
55+
'{"document":{"name":"projects/{0}/databases/(default)/documents/coll-1/a","createTime":{"seconds":1,"nanos":9},"updateTime":{"seconds":1,"nanos":9},"fields":{"k":{"stringValue":"a"},"bar":{"integerValue":1}}}}',
56+
'{"documentMetadata":{"name":"projects/{0}/databases/(default)/documents/coll-1/b","readTime":{"seconds":1000,"nanos":9999},"exists":true}}',
57+
'{"document":{"name":"projects/{0}/databases/(default)/documents/coll-1/b","createTime":{"seconds":1,"nanos":9},"updateTime":{"seconds":1,"nanos":9},"fields":{"k":{"stringValue":"b"},"bar":{"integerValue":2}}}}'
58+
];
5359

5460
apiDescribe('Bundles', (persistence: boolean) => {
5561
function verifySnapEqualTestDocs(snap: firestore.QuerySnapshot): void {
@@ -67,27 +73,7 @@ apiDescribe('Bundles', (persistence: boolean) => {
6773
const projectId: string = db.app.options.projectId;
6874

6975
// Extract elements from BUNDLE_TEMPLATE, and replace project ID.
70-
let runningElement: string = '';
71-
const elements: string[] = [];
72-
let depth = 0;
73-
for (const char of BUNDLE_TEMPLATE) {
74-
if (char === '{') {
75-
runningElement += char;
76-
depth += 1;
77-
} else if (depth > 0) {
78-
runningElement += char;
79-
}
80-
81-
if (char === '}') {
82-
depth -= 1;
83-
if (depth === 0) {
84-
// Obviously assuming TEMPLATE_PROJECT_ID only appear as project id in
85-
// the bundle, not as document id or filed value.
86-
elements.push(runningElement.replace(TEMPLATE_PROJECT_ID, projectId));
87-
runningElement = '';
88-
}
89-
}
90-
}
76+
const elements = BUNDLE_TEMPLATE.map(e => e.replace('{0}', projectId));
9177

9278
// Recalculating length prefixes for elements that are not BundleMetadata.
9379
let bundleContent = '';

0 commit comments

Comments
 (0)