Skip to content

test: cover bot.ts #860

Merged
KnorpelSenf merged 10 commits intogrammyjs:mainfrom
arunr-inji:test/improve-bot-coverage
Jan 20, 2026
Merged

test: cover bot.ts #860
KnorpelSenf merged 10 commits intogrammyjs:mainfrom
arunr-inji:test/improve-bot-coverage

Conversation

@arunr-inji
Copy link
Contributor

@arunr-inji arunr-inji commented Jan 10, 2026

Description

This PR adds comprehensive test coverage for bot.ts

Closes #851

Test Coverage Improvements

  • Before: 15.4% line coverage, 50.0% branch coverage
  • After:
image

@arunr-inji arunr-inji changed the title use fake time in bot tests Tests for bot.ts Jan 10, 2026
@KnorpelSenf KnorpelSenf changed the title Tests for bot.ts test: cover bot.ts Jan 10, 2026
@arunr-inji arunr-inji marked this pull request as ready for review January 11, 2026 00:12
Copy link
Member

@KnorpelSenf KnorpelSenf left a comment

Choose a reason for hiding this comment

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

A few nitpicks, a few needless usages of fake time. Overall, very solid!

@arunr-inji arunr-inji force-pushed the test/improve-bot-coverage branch from d91545b to 7e73bbb Compare January 18, 2026 06:42
@KnorpelSenf
Copy link
Member

Still some unaddressed comments from the previous review about needles fake time usage (unless it's needed and I don't understand why), feel free to ping me once this is ready

@arunr-inji
Copy link
Contributor Author

Still some unaddressed comments from the previous review about needles fake time usage (unless it's needed and I don't understand why), feel free to ping me once this is ready

Yeah I meant to convert this into a draft again. I'll do that and re open for review!

@KnorpelSenf
Copy link
Member

Top notch

@KnorpelSenf KnorpelSenf marked this pull request as draft January 18, 2026 08:44
@arunr-inji arunr-inji force-pushed the test/improve-bot-coverage branch from e27f445 to a19ccf6 Compare January 19, 2026 05:40
@arunr-inji
Copy link
Contributor Author

Top notch

I think I addressed your feedback + added 3 more tests (mentioned in my other comment)

}
});

it("should retry on HttpError during initialization", async () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@KnorpelSenf added this and two more tests below (5xx, 429 handling) to this describe block since you last reviewed

Copy link
Member

Choose a reason for hiding this comment

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

Very cool! That's a great addition.

Btw why doesn't the library actually perform a sleep here? I assumed it would do a 3 second delay, and you're not faking time ... but the test execution is still fast. How?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Based on my understanding, even though these are errors with strategy set to retry, the delay is only enforced after at least one error and not for the first retry:

strategy = "retry";
). In our tests since the second call succeeds, there's no sleep.

But the sleep duration in that case would be 50ms * 2 right? and so on right?

Copy link
Contributor Author

@arunr-inji arunr-inji Jan 19, 2026

Choose a reason for hiding this comment

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

Or perhaps you were referring to the 3s delays for handlePollingError?
the retry + delay + retry functionality is actually not tested; For errors during getUpdates, we only have tests below for the basic error handling functionality. Do you think that is something that is worth adding tests for?

Copy link
Member

Choose a reason for hiding this comment

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

Ah great point, the first error is retried immediately. This is reasonable because of a quirk in the Bot API server.

The tests are fine the way they are, let's merge them now. In a subsequent PQ, it is worth improving the tests, for the retry mechanism in particular.

@arunr-inji arunr-inji marked this pull request as ready for review January 19, 2026 06:50
Copy link
Member

@KnorpelSenf KnorpelSenf left a comment

Choose a reason for hiding this comment

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

A bunch of stubs are not cleaned up properly, and a few usages can be simplified. All of my comments are nitpicks, I assume that you can just commit my suggestions (perhaps take a look if I messed up) and then we can merge. Almost there!

arunr-inji and others added 2 commits January 19, 2026 12:17
Co-authored-by: KnorpelSenf <shtrog@gmail.com>
@arunr-inji
Copy link
Contributor Author

A bunch of stubs are not cleaned up properly, and a few usages can be simplified. All of my comments are nitpicks, I assume that you can just commit my suggestions (perhaps take a look if I messed up) and then we can merge. Almost there!

I committed your changes but had to fix some lint failures so pushed a commit.

Thanks for the thorough reviews!

Copy link
Member

@KnorpelSenf KnorpelSenf left a comment

Choose a reason for hiding this comment

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

Lessgoooo

@KnorpelSenf KnorpelSenf merged commit c5287d7 into grammyjs:main Jan 20, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve test coverage for bot.ts

2 participants