-
Notifications
You must be signed in to change notification settings - Fork 150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add totalDocuments and totalBytes to bundle metadata. #1085
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
import {expect} from 'chai'; | ||
import * as extend from 'extend'; | ||
import {afterEach, beforeEach, describe, it} from 'mocha'; | ||
import {firestore} from '../protos/firestore_v1_proto_api'; | ||
import {firestore, google} from '../protos/firestore_v1_proto_api'; | ||
import {Firestore, QuerySnapshot, Timestamp} from '../src'; | ||
import { | ||
bundleToElementArray, | ||
|
@@ -24,6 +24,28 @@ import { | |
verifyInstance, | ||
} from './util/helpers'; | ||
import IBundleElement = firestore.IBundleElement; | ||
import IBundleMetadata = firestore.IBundleMetadata; | ||
import ITimestamp = google.protobuf.ITimestamp; | ||
|
||
export const TEST_BUNDLE_ID = 'test-bundle'; | ||
const TEST_BUNDLE_VERSION = 1; | ||
|
||
export function verifyMetadata( | ||
meta: IBundleMetadata, | ||
createTime: ITimestamp, | ||
totalDocuments: number, | ||
expectEmptyContent = false | ||
): void { | ||
if (!expectEmptyContent) { | ||
expect(meta.totalBytes).greaterThan(0); | ||
} else { | ||
expect(meta.totalBytes).to.equal(0); | ||
} | ||
expect(meta.id).to.equal(TEST_BUNDLE_ID); | ||
expect(meta.version).to.equal(TEST_BUNDLE_VERSION); | ||
expect(meta.totalDocuments).to.equal(totalDocuments); | ||
expect(meta.createTime).to.deep.equal(createTime); | ||
} | ||
|
||
describe('Bundle Buidler', () => { | ||
let firestore: Firestore; | ||
|
@@ -49,7 +71,7 @@ describe('Bundle Buidler', () => { | |
}); | ||
|
||
it('succeeds with document snapshots', async () => { | ||
const bundle = firestore._bundle('test-bundle'); | ||
const bundle = firestore._bundle(TEST_BUNDLE_ID); | ||
const snap1 = firestore.snapshot_( | ||
{ | ||
name: `${DATABASE_ROOT}/documents/collectionId/doc1`, | ||
|
@@ -80,12 +102,12 @@ describe('Bundle Buidler', () => { | |
expect(elements.length).to.equal(3); | ||
|
||
const meta = (elements[0] as IBundleElement).metadata; | ||
expect(meta).to.deep.equal({ | ||
id: 'test-bundle', | ||
verifyMetadata( | ||
meta!, | ||
// `snap1.readTime` is the bundle createTime, because it is larger than `snap2.readTime`. | ||
createTime: snap1.readTime.toProto().timestampValue, | ||
version: 1, | ||
}); | ||
snap1.readTime.toProto().timestampValue!, | ||
1 | ||
); | ||
|
||
// Verify doc1Meta and doc1Snap | ||
const docMeta = (elements[1] as IBundleElement).documentMetadata; | ||
|
@@ -99,7 +121,7 @@ describe('Bundle Buidler', () => { | |
}); | ||
|
||
it('succeeds with query snapshots', async () => { | ||
const bundle = firestore._bundle('test-bundle'); | ||
const bundle = firestore._bundle(TEST_BUNDLE_ID); | ||
const snap = firestore.snapshot_( | ||
{ | ||
name: `${DATABASE_ROOT}/documents/collectionId/doc1`, | ||
|
@@ -128,12 +150,12 @@ describe('Bundle Buidler', () => { | |
expect(elements.length).to.equal(4); | ||
|
||
const meta = (elements[0] as IBundleElement).metadata; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind adding a helper for the metadata comparison? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
expect(meta).to.deep.equal({ | ||
id: 'test-bundle', | ||
verifyMetadata( | ||
meta!, | ||
// `snap.readTime` is the bundle createTime, because it is larger than `snap2.readTime`. | ||
createTime: snap.readTime.toProto().timestampValue, | ||
version: 1, | ||
}); | ||
snap.readTime.toProto().timestampValue!, | ||
1 | ||
); | ||
|
||
// Verify named query | ||
const namedQuery = (elements[1] as IBundleElement).namedQuery; | ||
|
@@ -162,7 +184,7 @@ describe('Bundle Buidler', () => { | |
}); | ||
|
||
it('succeeds with multiple calls to build()', async () => { | ||
const bundle = firestore._bundle('test-bundle'); | ||
const bundle = firestore._bundle(TEST_BUNDLE_ID); | ||
const snap1 = firestore.snapshot_( | ||
{ | ||
name: `${DATABASE_ROOT}/documents/collectionId/doc1`, | ||
|
@@ -181,12 +203,12 @@ describe('Bundle Buidler', () => { | |
expect(elements.length).to.equal(3); | ||
|
||
const meta = (elements[0] as IBundleElement).metadata; | ||
expect(meta).to.deep.equal({ | ||
id: 'test-bundle', | ||
verifyMetadata( | ||
meta!, | ||
// `snap1.readTime` is the bundle createTime, because it is larger than `snap2.readTime`. | ||
createTime: snap1.readTime.toProto().timestampValue, | ||
version: 1, | ||
}); | ||
snap1.readTime.toProto().timestampValue!, | ||
1 | ||
); | ||
|
||
// Verify doc1Meta and doc1Snap | ||
const doc1Meta = (elements[1] as IBundleElement).documentMetadata; | ||
|
@@ -215,7 +237,14 @@ describe('Bundle Buidler', () => { | |
const newElements = await bundleToElementArray(bundle.build()); | ||
|
||
expect(newElements.length).to.equal(5); | ||
expect(newElements.slice(0, 3)).to.deep.equal(elements); | ||
const newMeta = (newElements[0] as IBundleElement).metadata; | ||
verifyMetadata( | ||
newMeta!, | ||
// `snap1.readTime` is the bundle createTime, because it is larger than `snap2.readTime`. | ||
snap1.readTime.toProto().timestampValue!, | ||
2 | ||
); | ||
expect(newElements.slice(1, 3)).to.deep.equal(elements.slice(1)); | ||
|
||
// Verify doc2Meta and doc2Snap | ||
const doc2Meta = (newElements[3] as IBundleElement).documentMetadata; | ||
|
@@ -229,17 +258,18 @@ describe('Bundle Buidler', () => { | |
}); | ||
|
||
it('succeeds when nothing is added', async () => { | ||
const bundle = firestore._bundle('test-bundle'); | ||
const bundle = firestore._bundle(TEST_BUNDLE_ID); | ||
|
||
// `elements` is expected to be [bundleMeta]. | ||
const elements = await bundleToElementArray(bundle.build()); | ||
expect(elements.length).to.equal(1); | ||
|
||
const meta = (elements[0] as IBundleElement).metadata; | ||
expect(meta).to.deep.equal({ | ||
id: 'test-bundle', | ||
createTime: new Timestamp(0, 0).toProto().timestampValue, | ||
version: 1, | ||
}); | ||
verifyMetadata( | ||
meta!, | ||
new Timestamp(0, 0).toProto().timestampValue!, | ||
0, | ||
true | ||
); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure I understand how this will work. I assume this was added to allow the progress handler to display their status. For that to work, would this not need to be the first message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note the order of the arguments to
Buffer.concat
is different here. Also added a comment.