Skip to content

Commit 7eddfa3

Browse files
committed
Fixes for firebase-js-sdk/integration/firestore
1 parent 82cda06 commit 7eddfa3

File tree

4 files changed

+203
-130
lines changed

4 files changed

+203
-130
lines changed

integration/firestore/gulpfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ function copyTests() {
4848
testBase + '/integration/util/settings.ts',
4949
testBase + '/integration/util/testing_hooks_util.ts',
5050
testBase + '/util/equality_matcher.ts',
51-
testBase + '/util/promise.ts'
51+
testBase + '/util/promise.ts',
52+
testBase + '/util/mocha_extensions.ts'
5253
],
5354
{ base: '../../packages/firestore' }
5455
)

packages/firestore/pipelines/pipelines.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717
import { PipelineSource, Pipeline } from '../dist/pipelines';
1818

19-
// Augument the Firestore and Query classes with the pipeline() method.
19+
// Augment the Firestore and Query classes with the pipeline() method.
2020
// This is stripped from dist/lite/pipelines.d.ts during the build
2121
// so it needs to be re-added here.
2222
declare module '@firebase/firestore' {

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

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ import {
105105
xor,
106106
field,
107107
constant,
108-
_internalPipelineToExecutePipelineRequestProto,
109108
FindNearestStageOptions,
110109
AggregateFunction,
111110
arrayGet,
@@ -340,133 +339,6 @@ apiDescribe.skipClassic('Pipelines', persistence => {
340339
await withTestCollectionPromise;
341340
});
342341

343-
describe('console support', () => {
344-
it('supports pipeline query serialization to proto', async () => {
345-
// Perform the same test as the console
346-
const pipeline = firestore
347-
.pipeline()
348-
.collection('customers')
349-
.where(field('country').equal('United Kingdom'));
350-
351-
const proto = _internalPipelineToExecutePipelineRequestProto(pipeline);
352-
353-
const expectedStructuredPipelineProto =
354-
'{"pipeline":{"stages":[{"name":"collection","options":{},"args":[{"referenceValue":"/customers"}]},{"name":"where","options":{},"args":[{"functionValue":{"name":"equal","args":[{"fieldReferenceValue":"country"},{"stringValue":"United Kingdom"}]}}]}]}}';
355-
expect(JSON.stringify(proto.structuredPipeline)).to.equal(
356-
expectedStructuredPipelineProto
357-
);
358-
});
359-
360-
it('supports PipelineSnapshot serialization to proto', async () => {
361-
// Perform the same test as the console
362-
const pipeline = firestore
363-
.pipeline()
364-
.collection(randomCol)
365-
.sort(field('title').ascending())
366-
.limit(1);
367-
368-
const result = await execute(pipeline);
369-
370-
expect(result.results[0]._fieldsProto()).to.deep.equal({
371-
'author': {
372-
'stringValue': 'George Orwell'
373-
},
374-
'awards': {
375-
'mapValue': {
376-
'fields': {
377-
'prometheus': {
378-
'booleanValue': true
379-
}
380-
}
381-
}
382-
},
383-
'embedding': {
384-
'mapValue': {
385-
'fields': {
386-
'__type__': {
387-
'stringValue': '__vector__'
388-
},
389-
'value': {
390-
'arrayValue': {
391-
'values': [
392-
{
393-
'doubleValue': 1
394-
},
395-
{
396-
'doubleValue': 1
397-
},
398-
{
399-
'doubleValue': 1
400-
},
401-
{
402-
'doubleValue': 1
403-
},
404-
{
405-
'doubleValue': 1
406-
},
407-
{
408-
'doubleValue': 1
409-
},
410-
{
411-
'doubleValue': 1
412-
},
413-
{
414-
'doubleValue': 10
415-
},
416-
{
417-
'doubleValue': 1
418-
},
419-
{
420-
'doubleValue': 1
421-
}
422-
]
423-
}
424-
}
425-
}
426-
}
427-
},
428-
'genre': {
429-
'stringValue': 'Dystopian'
430-
},
431-
'published': {
432-
'integerValue': '1949'
433-
},
434-
'rating': {
435-
'doubleValue': 4.2
436-
},
437-
'tags': {
438-
'arrayValue': {
439-
'values': [
440-
{
441-
'stringValue': 'surveillance'
442-
},
443-
{
444-
'stringValue': 'totalitarianism'
445-
},
446-
{
447-
'stringValue': 'propaganda'
448-
}
449-
]
450-
}
451-
},
452-
'title': {
453-
'stringValue': '1984'
454-
}
455-
});
456-
});
457-
458-
it('performs validation', async () => {
459-
expect(() => {
460-
const pipeline = firestore
461-
.pipeline()
462-
.collection('customers')
463-
.where(field('country').equal(new Map([])));
464-
465-
_internalPipelineToExecutePipelineRequestProto(pipeline);
466-
}).to.throw();
467-
});
468-
});
469-
470342
describe('pipeline results', () => {
471343
it('empty snapshot as expected', async () => {
472344
const snapshot = await execute(
Lines changed: 200 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,200 @@
1+
/**
2+
* @license
3+
* Copyright 2025 Google LLC
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
import { expect } from 'chai';
19+
20+
import { Deferred } from '../../util/promise';
21+
import {
22+
addDoc,
23+
CollectionReference,
24+
Firestore,
25+
vector
26+
} from '../util/firebase_export';
27+
import { apiDescribe, withTestCollection } from '../util/helpers';
28+
import {
29+
field,
30+
_internalPipelineToExecutePipelineRequestProto,
31+
execute
32+
} from '../util/pipeline_export';
33+
34+
apiDescribe.skipClassic('Pipelines', persistence => {
35+
let firestore: Firestore;
36+
let randomCol: CollectionReference;
37+
let testDeferred: Deferred<void> | undefined;
38+
let withTestCollectionPromise: Promise<unknown> | undefined;
39+
40+
beforeEach(async () => {
41+
const setupDeferred = new Deferred<void>();
42+
testDeferred = new Deferred<void>();
43+
withTestCollectionPromise = withTestCollection(
44+
persistence,
45+
{},
46+
async (collectionRef, firestoreInstance) => {
47+
randomCol = collectionRef;
48+
firestore = firestoreInstance;
49+
setupDeferred.resolve();
50+
51+
return testDeferred?.promise;
52+
}
53+
);
54+
55+
await setupDeferred.promise;
56+
});
57+
58+
afterEach(async () => {
59+
testDeferred?.resolve();
60+
await withTestCollectionPromise;
61+
});
62+
63+
describe('console support', () => {
64+
it('supports pipeline query serialization to proto', async () => {
65+
// Perform the same test as the console
66+
const pipeline = firestore
67+
.pipeline()
68+
.collection('customers')
69+
.where(field('country').equal('United Kingdom'));
70+
71+
const proto = _internalPipelineToExecutePipelineRequestProto(pipeline);
72+
73+
const expectedStructuredPipelineProto =
74+
'{"pipeline":{"stages":[{"name":"collection","options":{},"args":[{"referenceValue":"/customers"}]},{"name":"where","options":{},"args":[{"functionValue":{"name":"equal","args":[{"fieldReferenceValue":"country"},{"stringValue":"United Kingdom"}]}}]}]}}';
75+
expect(JSON.stringify(proto.structuredPipeline)).to.equal(
76+
expectedStructuredPipelineProto
77+
);
78+
});
79+
80+
it('supports PipelineSnapshot serialization to proto', async () => {
81+
await addDoc(randomCol, {
82+
title: '1984',
83+
author: 'George Orwell',
84+
genre: 'Dystopian',
85+
published: 1949,
86+
rating: 4.2,
87+
tags: ['surveillance', 'totalitarianism', 'propaganda'],
88+
awards: { prometheus: true },
89+
embedding: vector([1, 1, 1, 1, 1, 1, 1, 10, 1, 1])
90+
});
91+
92+
// Perform the same test as the console
93+
const pipeline = firestore
94+
.pipeline()
95+
.collection(randomCol)
96+
.sort(field('title').ascending())
97+
.limit(1);
98+
99+
const result = await execute(pipeline);
100+
101+
expect(result.results[0]._fieldsProto()).to.deep.equal({
102+
'author': {
103+
'stringValue': 'George Orwell'
104+
},
105+
'awards': {
106+
'mapValue': {
107+
'fields': {
108+
'prometheus': {
109+
'booleanValue': true
110+
}
111+
}
112+
}
113+
},
114+
'embedding': {
115+
'mapValue': {
116+
'fields': {
117+
'__type__': {
118+
'stringValue': '__vector__'
119+
},
120+
'value': {
121+
'arrayValue': {
122+
'values': [
123+
{
124+
'doubleValue': 1
125+
},
126+
{
127+
'doubleValue': 1
128+
},
129+
{
130+
'doubleValue': 1
131+
},
132+
{
133+
'doubleValue': 1
134+
},
135+
{
136+
'doubleValue': 1
137+
},
138+
{
139+
'doubleValue': 1
140+
},
141+
{
142+
'doubleValue': 1
143+
},
144+
{
145+
'doubleValue': 10
146+
},
147+
{
148+
'doubleValue': 1
149+
},
150+
{
151+
'doubleValue': 1
152+
}
153+
]
154+
}
155+
}
156+
}
157+
}
158+
},
159+
'genre': {
160+
'stringValue': 'Dystopian'
161+
},
162+
'published': {
163+
'integerValue': '1949'
164+
},
165+
'rating': {
166+
'doubleValue': 4.2
167+
},
168+
'tags': {
169+
'arrayValue': {
170+
'values': [
171+
{
172+
'stringValue': 'surveillance'
173+
},
174+
{
175+
'stringValue': 'totalitarianism'
176+
},
177+
{
178+
'stringValue': 'propaganda'
179+
}
180+
]
181+
}
182+
},
183+
'title': {
184+
'stringValue': '1984'
185+
}
186+
});
187+
});
188+
189+
it('performs validation', async () => {
190+
expect(() => {
191+
const pipeline = firestore
192+
.pipeline()
193+
.collection('customers')
194+
.where(field('country').equal(new Map([])));
195+
196+
_internalPipelineToExecutePipelineRequestProto(pipeline);
197+
}).to.throw();
198+
});
199+
});
200+
});

0 commit comments

Comments
 (0)