-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,16 @@ import { | |
verifyInstance, | ||
} from './util/helpers'; | ||
import IBundleElement = firestore.IBundleElement; | ||
import IBundleMetadata = firestore.IBundleMetadata; | ||
|
||
export function verifyMetadata( | ||
meta: IBundleMetadata, | ||
expected: IBundleMetadata | ||
): void { | ||
expect(meta!.totalBytes).greaterThan(0); | ||
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. Drop 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. |
||
delete meta!.totalBytes; | ||
expect(meta).to.deep.equal(expected); | ||
} | ||
|
||
describe('Bundle Buidler', () => { | ||
let firestore: Firestore; | ||
|
@@ -80,9 +90,7 @@ describe('Bundle Buidler', () => { | |
expect(elements.length).to.equal(3); | ||
|
||
const meta = (elements[0] as IBundleElement).metadata; | ||
expect(meta!.totalBytes).greaterThan(0); | ||
delete meta!.totalBytes; | ||
expect(meta).to.deep.equal({ | ||
verifyMetadata(meta!, { | ||
id: 'test-bundle', | ||
// `snap1.readTime` is the bundle createTime, because it is larger than `snap2.readTime`. | ||
createTime: snap1.readTime.toProto().timestampValue, | ||
|
@@ -131,9 +139,7 @@ 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!.totalBytes).greaterThan(0); | ||
delete meta!.totalBytes; | ||
expect(meta).to.deep.equal({ | ||
verifyMetadata(meta!, { | ||
id: 'test-bundle', | ||
// `snap.readTime` is the bundle createTime, because it is larger than `snap2.readTime`. | ||
createTime: snap.readTime.toProto().timestampValue, | ||
|
@@ -187,9 +193,7 @@ describe('Bundle Buidler', () => { | |
expect(elements.length).to.equal(3); | ||
|
||
const meta = (elements[0] as IBundleElement).metadata; | ||
expect(meta!.totalBytes).greaterThan(0); | ||
delete meta!.totalBytes; | ||
expect(meta).to.deep.equal({ | ||
verifyMetadata(meta!, { | ||
id: 'test-bundle', | ||
// `snap1.readTime` is the bundle createTime, because it is larger than `snap2.readTime`. | ||
createTime: snap1.readTime.toProto().timestampValue, | ||
|
@@ -225,9 +229,7 @@ describe('Bundle Buidler', () => { | |
|
||
expect(newElements.length).to.equal(5); | ||
const newMeta = (newElements[0] as IBundleElement).metadata; | ||
expect(newMeta!.totalBytes).greaterThan(0); | ||
delete newMeta!.totalBytes; | ||
expect(newMeta).to.deep.equal({ | ||
verifyMetadata(newMeta!, { | ||
id: 'test-bundle', | ||
// `snap1.readTime` is the bundle createTime, because it is larger than `snap2.readTime`. | ||
createTime: snap1.readTime.toProto().timestampValue, | ||
|
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 was hoping you would pass in the expected state one at a time:
From that, you can simplify further. Extract a constant for the bundle ID, and use it everywhere. The version is also always a constant. So in the end you have:
You can then also compare each field directly:
This removes the need to delete the field and ruins nasty surprises in the future.
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.
Done.