-
Notifications
You must be signed in to change notification settings - Fork 946
Fix array-contains queries #1913
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
Changes from all commits
81f3b29
e2ac222
f415822
a84e4de
ec32b9d
af30584
4d3f1c0
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 |
---|---|---|
|
@@ -25,8 +25,12 @@ import { GeoPoint } from '../../../../src/api/geo_point'; | |
import { Timestamp } from '../../../../src/api/timestamp'; | ||
import { DatabaseId } from '../../../../src/core/database_info'; | ||
import { | ||
ArrayContainsAnyFilter, | ||
ArrayContainsFilter, | ||
Direction, | ||
FieldFilter, | ||
InFilter, | ||
KeyFieldFilter, | ||
Operator, | ||
OrderBy, | ||
Query | ||
|
@@ -684,7 +688,7 @@ describe('Serializer', () => { | |
|
||
it('makes dotted-property names', () => { | ||
const path = new FieldPath(['item', 'part', 'top']); | ||
const input = new FieldFilter(path, Operator.EQUAL, wrap('food')); | ||
const input = FieldFilter.create(path, Operator.EQUAL, wrap('food')); | ||
const actual = s.toUnaryOrFieldFilter(input); | ||
expect(actual).to.deep.equal({ | ||
fieldFilter: { | ||
|
@@ -693,7 +697,9 @@ describe('Serializer', () => { | |
value: { stringValue: 'food' } | ||
} | ||
}); | ||
expect(s.fromFieldFilter(actual)).to.deep.equal(input); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(FieldFilter); | ||
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. FWIW we could instead do:
to avoid the redundancy of specifying the type of 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. I don't know how 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. Ah, yes. I believe the prototype check would be more strict than that... that said it's not super normal to deal with an object's prototype directly or do equal checks on it. I am not 100% confident it wouldn't bite us in the future some day (due to browser differences or something). So I don't feel strongly that it's a better approach or anything (i.e. feel free to leave as-is). |
||
}); | ||
|
||
it('converts LessThan', () => { | ||
|
@@ -706,7 +712,9 @@ describe('Serializer', () => { | |
value: { integerValue: '42' } | ||
} | ||
}); | ||
expect(s.fromFieldFilter(actual)).to.deep.equal(input); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(FieldFilter); | ||
}); | ||
|
||
it('converts LessThanOrEqual', () => { | ||
|
@@ -719,7 +727,9 @@ describe('Serializer', () => { | |
value: { stringValue: 'food' } | ||
} | ||
}); | ||
expect(s.fromFieldFilter(actual)).to.deep.equal(input); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(FieldFilter); | ||
}); | ||
|
||
it('converts GreaterThan', () => { | ||
|
@@ -732,7 +742,9 @@ describe('Serializer', () => { | |
value: { booleanValue: false } | ||
} | ||
}); | ||
expect(s.fromFieldFilter(actual)).to.deep.equal(input); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(FieldFilter); | ||
}); | ||
|
||
it('converts GreaterThanOrEqual', () => { | ||
|
@@ -745,7 +757,31 @@ describe('Serializer', () => { | |
value: { doubleValue: 1e100 } | ||
} | ||
}); | ||
expect(s.fromFieldFilter(actual)).to.deep.equal(input); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(FieldFilter); | ||
}); | ||
|
||
it('converts key field', () => { | ||
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. Thanks for adding! |
||
const input = filter( | ||
DOCUMENT_KEY_NAME, | ||
'==', | ||
ref('project/database', 'coll/doc') | ||
); | ||
const actual = s.toUnaryOrFieldFilter(input); | ||
expect(actual).to.deep.equal({ | ||
fieldFilter: { | ||
field: { fieldPath: '__name__' }, | ||
op: 'EQUAL', | ||
value: { | ||
referenceValue: | ||
'projects/project/databases/database/documents/coll/doc' | ||
} | ||
} | ||
}); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(KeyFieldFilter); | ||
}); | ||
|
||
it('converts array-contains', () => { | ||
|
@@ -758,7 +794,9 @@ describe('Serializer', () => { | |
value: { integerValue: '42' } | ||
} | ||
}); | ||
expect(s.fromFieldFilter(actual)).to.deep.equal(input); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(ArrayContainsFilter); | ||
}); | ||
|
||
it('converts IN', () => { | ||
|
@@ -779,7 +817,9 @@ describe('Serializer', () => { | |
} | ||
} | ||
}); | ||
expect(s.fromFieldFilter(actual)).to.deep.equal(input); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(InFilter); | ||
}); | ||
|
||
it('converts array-contains-any', () => { | ||
|
@@ -800,7 +840,9 @@ describe('Serializer', () => { | |
} | ||
} | ||
}); | ||
expect(s.fromFieldFilter(actual)).to.deep.equal(input); | ||
const roundtripped = s.fromFieldFilter(actual); | ||
expect(roundtripped).to.deep.equal(input); | ||
expect(roundtripped).to.be.instanceof(ArrayContainsAnyFilter); | ||
}); | ||
}); | ||
|
||
|
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 couldn't figure out how to test
KeyFieldFilter
due to problems with creating a query with this filter.Uh oh!
There was an error while loading. Please reload this page.
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.
Not sure if this is what you mean, but it might look something like:
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.
Thanks! That worked.