Skip to content
This repository was archived by the owner on Mar 4, 2026. It is now read-only.

test: Add test coverage for logical termination#1743

Merged
cherylEnkidu merged 7 commits intomainfrom
cheryllin/RunQueryTest
Dec 14, 2023
Merged

test: Add test coverage for logical termination#1743
cherylEnkidu merged 7 commits intomainfrom
cheryllin/RunQueryTest

Conversation

@cherylEnkidu
Copy link
Copy Markdown
Contributor

No description provided.

@product-auto-label product-auto-label Bot added size: m Pull request size is medium. api: firestore Issues related to the googleapis/nodejs-firestore API. labels Jun 30, 2022
@cherylEnkidu cherylEnkidu force-pushed the cheryllin/RunQueryTest branch 2 times, most recently from f91e1a5 to bb2015d Compare July 4, 2022 14:32
@product-auto-label product-auto-label Bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Jul 4, 2022
@cherylEnkidu cherylEnkidu force-pushed the cheryllin/RunQueryTest branch from bb2015d to da544d4 Compare July 4, 2022 14:51
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Jul 4, 2022
@cherylEnkidu cherylEnkidu force-pushed the cheryllin/RunQueryTest branch from da544d4 to 5bf5e0b Compare July 4, 2022 15:08
@cherylEnkidu cherylEnkidu force-pushed the cheryllin/RunQueryTest branch from 5bf5e0b to 885ecec Compare December 7, 2023 20:55
@product-auto-label product-auto-label Bot added size: l Pull request size is large. and removed size: m Pull request size is medium. labels Dec 7, 2023
@cherylEnkidu cherylEnkidu marked this pull request as ready for review December 7, 2023 21:44
@cherylEnkidu cherylEnkidu requested review from a team December 7, 2023 21:44
@cherylEnkidu cherylEnkidu force-pushed the cheryllin/RunQueryTest branch from 2897101 to 2d168b0 Compare December 7, 2023 21:50
@product-auto-label product-auto-label Bot added size: m Pull request size is medium. and removed size: l Pull request size is large. labels Dec 7, 2023
Comment thread dev/system-test/firestore.ts Outdated
@cherylEnkidu cherylEnkidu force-pushed the cheryllin/RunQueryTest branch from c3d8246 to bd095b1 Compare December 8, 2023 16:33
@cherylEnkidu cherylEnkidu added kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 8, 2023
@yoshi-kokoro yoshi-kokoro removed kokoro:run Add this label to force Kokoro to re-run the tests. kokoro:force-run Add this label to force Kokoro to re-run the tests. labels Dec 8, 2023
Copy link
Copy Markdown
Contributor

@MarkDuckworth MarkDuckworth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new tests look fine, but the use of promises could be improved for readability and consistency. I gave a few suggestions for improvement.

Comment thread dev/system-test/firestore.ts Outdated

it('can stream()', done => {
let received = 0;
return randomCol
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You shouldn't need to return the result here. Returning anything could be misleading, since it could be confused with returning a promise, and I think this code is returning a Stream.

You use the done callback to signal that the test is complete instead of returning a promise. That's fine since that pattern is used in other tests in this file.

Comment thread dev/system-test/firestore.ts Outdated

it('has limit() method on stream()', done => {
let received = 0;
Promise.all([addDocs({foo: 'a'}, {foo: 'b'})]).then(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrapping this statement in Promise.all(...) is misleading, and I don't think it adds value. Consider instead

addDocs(...).then(...

Comment thread dev/system-test/firestore.ts Outdated

it('can run limit(num), where num is larger than the collection size on stream()', done => {
let received = 0;
Promise.all([addDocs({foo: 'a'}, {foo: 'b'})]).then(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same.

Comment thread dev/system-test/firestore.ts Outdated
});

it('has offset() method', async () => {
it('has offset() method on get()', async () => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offset method is on Query. Maybe consider rewording this test to 'can use offset() method with get()'

Comment thread dev/system-test/firestore.ts Outdated
expectDocs(res, {foo: 'b'});
});

it('has offset() method on stream()', done => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Offset method is on Query. Maybe consider rewording this test to 'can use offset() method with get()'

Comment thread dev/system-test/firestore.ts Outdated

it('has offset() method on stream()', done => {
let received = 0;
Promise.all([addDocs({foo: 'a'}, {foo: 'b'})]).then(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern with use of Promise.all

Comment thread dev/system-test/firestore.ts Outdated

it('can run offset(num), where num is larger than the collection size on stream()', done => {
let received = 0;
Promise.all([addDocs({foo: 'a'}, {foo: 'b'})]).then(() => {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same concern with use of Promise.all

Comment thread dev/system-test/firestore.ts
@cherylEnkidu cherylEnkidu force-pushed the cheryllin/RunQueryTest branch from 7b1d052 to 6307c44 Compare December 13, 2023 15:48
@cherylEnkidu cherylEnkidu force-pushed the cheryllin/RunQueryTest branch from 8c1ae2f to c02f2c5 Compare December 13, 2023 15:53
Copy link
Copy Markdown
Contributor

@MarkDuckworth MarkDuckworth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with additional recommendations on clean up.

for await (const doc of stream) {
expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot);
++received;
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of for await...of!

Comment thread dev/system-test/firestore.ts Outdated
Comment on lines +1712 to +1720
await addDocs({foo: 'a'}, {foo: 'b'}).then(async () => {
const stream = randomCol.orderBy('foo').limit(1).stream();
for await (const doc of stream) {
expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot);
++received;
}

expect(received).to.equal(1);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since you have an async test, you can drop the use of promise.then(...) and make the code even more readable.

  await addDocs({foo: 'a'}, {foo: 'b'});

  const stream = randomCol.orderBy('foo').limit(1).stream();
  for await (const doc of stream) {
    expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot);
    ++received;
  }

  expect(received).to.equal(1);

Comment thread dev/system-test/firestore.ts Outdated
Comment on lines +1731 to +1738
await addDocs({foo: 'a'}, {foo: 'b'}).then(async () => {
const stream = randomCol.orderBy('foo').limit(3).stream();
for await (const doc of stream) {
expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot);
++received;
}
expect(received).to.equal(2);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same nit here.

Comment thread dev/system-test/firestore.ts Outdated
Comment on lines +1766 to +1774
await addDocs({foo: 'a'}, {foo: 'b'}).then(async () => {
const stream = randomCol.orderBy('foo').offset(1).stream();
for await (const doc of stream) {
expect(doc).to.be.an.instanceOf(QueryDocumentSnapshot);
++received;
}

expect(received).to.equal(1);
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same nit here

@cherylEnkidu cherylEnkidu merged commit 85f1008 into main Dec 14, 2023
@cherylEnkidu cherylEnkidu deleted the cheryllin/RunQueryTest branch December 14, 2023 20:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

api: firestore Issues related to the googleapis/nodejs-firestore API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants