Skip to content

Commit 09a3ca0

Browse files
More tests
1 parent a6ce575 commit 09a3ca0

File tree

1 file changed

+65
-7
lines changed

1 file changed

+65
-7
lines changed

packages/firestore/test/unit/model/target.test.ts

Lines changed: 65 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ import {
4141
} from '../../util/helpers';
4242

4343
describe('Target Bounds', () => {
44+
// TODO(indexing): Consider adding more test helpers to reduce the boilerplate
45+
// in these tests.
46+
4447
it('empty query', () => {
4548
const target = queryToTarget(query('c'));
4649
const index = fieldIndex('c');
@@ -52,7 +55,7 @@ describe('Target Bounds', () => {
5255
verifyBound(upperBound, true);
5356
});
5457

55-
it('equals query', () => {
58+
it('equals query with ascending index', () => {
5659
const target = queryToTarget(query('c', filter('foo', '==', 'bar')));
5760
const index = fieldIndex('c', { fields: [['foo', IndexKind.ASCENDING]] });
5861

@@ -63,18 +66,40 @@ describe('Target Bounds', () => {
6366
verifyBound(upperBound, true, 'bar');
6467
});
6568

66-
it('less than query', () => {
67-
const target = queryToTarget(query('c', filter('foo', '<', 'bar')));
69+
it('equals query with descending index', () => {
70+
const target = queryToTarget(query('c', filter('foo', '==', 'bar')));
6871
const index = fieldIndex('c', { fields: [['foo', IndexKind.DESCENDING]] });
6972

73+
const lowerBound = targetGetLowerBound(target, index);
74+
verifyBound(lowerBound, true, 'bar');
75+
76+
const upperBound = targetGetUpperBound(target, index);
77+
verifyBound(upperBound, true, 'bar');
78+
});
79+
80+
it('less than query with ascending index', () => {
81+
const target = queryToTarget(query('c', filter('foo', '<', 'bar')));
82+
const index = fieldIndex('c', { fields: [['foo', IndexKind.ASCENDING]] });
83+
7084
const lowerBound = targetGetLowerBound(target, index);
7185
verifyBound(lowerBound, true, '');
7286

7387
const upperBound = targetGetUpperBound(target, index);
7488
verifyBound(upperBound, false, 'bar');
7589
});
7690

77-
it('less than or equals query', () => {
91+
it('less than query with descending index', () => {
92+
const target = queryToTarget(query('c', filter('foo', '<', 'bar')));
93+
const index = fieldIndex('c', { fields: [['foo', IndexKind.DESCENDING]] });
94+
95+
const lowerBound = targetGetLowerBound(target, index);
96+
verifyBound(lowerBound, false, 'bar');
97+
98+
const upperBound = targetGetUpperBound(target, index);
99+
verifyBound(upperBound, true, '');
100+
});
101+
102+
it('less than or equals query with ascending index', () => {
78103
const target = queryToTarget(query('c', filter('foo', '<=', 'bar')));
79104
const index = fieldIndex('c', { fields: [['foo', IndexKind.ASCENDING]] });
80105

@@ -85,7 +110,18 @@ describe('Target Bounds', () => {
85110
verifyBound(upperBound, true, 'bar');
86111
});
87112

88-
it('greater than query', () => {
113+
it('less than or equals query with descending index', () => {
114+
const target = queryToTarget(query('c', filter('foo', '<=', 'bar')));
115+
const index = fieldIndex('c', { fields: [['foo', IndexKind.DESCENDING]] });
116+
117+
const lowerBound = targetGetLowerBound(target, index);
118+
verifyBound(lowerBound, true, 'bar');
119+
120+
const upperBound = targetGetUpperBound(target, index);
121+
verifyBound(upperBound, true, '');
122+
});
123+
124+
it('greater than query with ascending index', () => {
89125
const target = queryToTarget(query('c', filter('foo', '>', 'bar')));
90126
const index = fieldIndex('c', { fields: [['foo', IndexKind.ASCENDING]] });
91127

@@ -96,17 +132,39 @@ describe('Target Bounds', () => {
96132
verifyBound(upperBound, false, blob());
97133
});
98134

99-
it('greater than or equals query', () => {
100-
const target = queryToTarget(query('c', filter('foo', '>=', 'bar')));
135+
it('greater than query with descending index', () => {
136+
const target = queryToTarget(query('c', filter('foo', '>', 'bar')));
101137
const index = fieldIndex('c', { fields: [['foo', IndexKind.DESCENDING]] });
102138

139+
const lowerBound = targetGetLowerBound(target, index);
140+
verifyBound(lowerBound, false, blob());
141+
142+
const upperBound = targetGetUpperBound(target, index);
143+
verifyBound(upperBound, false, 'bar');
144+
});
145+
146+
it('greater than or equals query with ascending index', () => {
147+
const target = queryToTarget(query('c', filter('foo', '>=', 'bar')));
148+
const index = fieldIndex('c', { fields: [['foo', IndexKind.ASCENDING]] });
149+
103150
const lowerBound = targetGetLowerBound(target, index);
104151
verifyBound(lowerBound, true, 'bar');
105152

106153
const upperBound = targetGetUpperBound(target, index);
107154
verifyBound(upperBound, false, blob());
108155
});
109156

157+
it('greater than or equals query with descending index', () => {
158+
const target = queryToTarget(query('c', filter('foo', '>=', 'bar')));
159+
const index = fieldIndex('c', { fields: [['foo', IndexKind.DESCENDING]] });
160+
161+
const lowerBound = targetGetLowerBound(target, index);
162+
verifyBound(lowerBound, false, blob());
163+
164+
const upperBound = targetGetUpperBound(target, index);
165+
verifyBound(upperBound, true, 'bar');
166+
});
167+
110168
it('arrayContains query', () => {
111169
const target = queryToTarget(
112170
query('c', filter('foo', 'array-contains', 'bar'))

0 commit comments

Comments
 (0)