Skip to content

test(bot): cover untested general commands - #1859

Merged
LucasSantana-Dev merged 5 commits into
mainfrom
test/general-command-coverage
Jul 22, 2026
Merged

LucasSantana-Dev merged 5 commits into
mainfrom
test/general-command-coverage

Conversation

@LucasSantana-Dev

@LucasSantana-Dev LucasSantana-Dev commented Jul 17, 2026 •

Copy link
Copy Markdown
Owner

What

Adds 70 tests (9 spec files) for the remaining untested general commands. Third and final coverage PR in the series (#1855 music+giveaway, #1858 moderation+download).

Command Tests Covers
ping 5 latency calc, fetch handling, zero-latency edge
version 5 env-var resolution, package.json + commit-SHA fallback, ephemeral
afk 10 DM rejection, clear/set flows, error handling, logging
help 7 embed gen, pagination, empty lists, errors
level 18 reward add/remove, rank, leaderboard, setup config, errors
starboard 9 setup (channel/emoji/threshold), disable, top entries, errors
roleconfig 5 set/remove/list exclusive-role handlers, errors
reactionrole 6 create/delete/list, guild requirement, errors
voterewards 5 vote-info display, config, API error resilience

(giveaway excluded — already covered in #1855.)

Why

Closes the last known bot command coverage gap surfaced by the test-health audit — validation, config flows, guild-context gates, and error branches.

Verification

Spec-only diff (no source changed). Bot suite green:

Test Suites: 1 skipped, 229 passed, 229 of 230 total
Tests:       1 skipped, 3019 passed, 3020 total

Series total

#1855 + #1858 + this = 221 new tests; music, giveaway, moderation, download, and general command groups now covered.


Summary by cubic

Add tests across 9 specs to cover the remaining general commands (ping, version, afk, help, level, starboard, roleconfig, reactionrole, voterewards).
Test-only change that closes the last coverage gap, with stronger help pagination (multi-page + counter), error-path logging assertions, verifies config, guild checks, embeds, failures, and mocks global.fetch in voterewards to avoid external calls.

Written for commit f361b1e. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • Tests
    • Added comprehensive automated coverage for AFK, help, level, ping, reaction role, role configuration, starboard, version, and vote rewards commands.
    • Verified command responses, validation, pagination, configuration flows, error handling, latency reporting, and fallback behavior.
    • Added coverage for empty states, missing guild context, service failures, and environment-based version information.

@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds Jest test suites for eight general bot commands. The tests mock command dependencies and verify normal execution, guild validation, service delegation, reply payloads, pagination, environment fallbacks, logging, and error handling.

Changes

General command test coverage

Layer / File(s) Summary
Status and information command tests
packages/bot/src/functions/general/commands/afk.spec.ts, help.spec.ts, ping.spec.ts, version.spec.ts, voterewards.spec.ts
Tests AFK updates, help pagination, ping latency output, version fallbacks, vote reward rendering, and related error paths.
Level command behavior tests
packages/bot/src/functions/general/commands/level.spec.ts
Tests reward management, rank lookup, leaderboard rendering, setup persistence, guild validation, pagination components, and service failures.
Guild command delegation and error tests
packages/bot/src/functions/general/commands/reactionrole.spec.ts, roleconfig.spec.ts, starboard.spec.ts
Tests guild requirements, subcommand handler delegation, configuration updates, list responses, empty states, and error replies.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: cubic-dev-ai

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the PR’s main change: adding tests for previously untested general bot commands.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/general-command-coverage

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

Failed to generate code suggestions for PR

@github-actions

github-actions Bot commented Jul 17, 2026 •

Copy link
Copy Markdown
Warnings
⚠️

Big PR — 1541 lines changed across 9 files. Consider splitting into smaller, reviewable chunks.

⚠️

User-facing change without a CHANGELOG.md update. Add a line under ## [Unreleased] if this should appear in release notes. (Or apply the skip-changelog label if this PR does not affect end users.)

Generated by 🚫 dangerJS against f361b1e

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/bot/src/functions/general/commands/help.spec.ts`:
- Around line 118-131: Update the “catches errors and replies with error
message” test to force an exception through a dependency used by
helpCommand.execute, such as making interaction.user.displayAvatarURL() throw,
instead of relying on an empty command map or null client.user. Keep the
assertion focused on the error response returned by handleHelpError.
- Around line 93-116: Strengthen the pagination tests in
packages/bot/src/functions/general/commands/help.spec.ts lines 93-116 by
generating enough command fields or characters to require multiple embeds and
asserting interactionReply is called more than once. In
packages/bot/src/functions/general/commands/level.spec.ts lines 237-254,
generate more than one page of entries and assert the expected pagination
component, checking its actual presence rather than relying on typeof undefined.

In `@packages/bot/src/functions/general/commands/level.spec.ts`:
- Around line 327-345: Verify failed guild validation prevents downstream
command dispatch: in packages/bot/src/functions/general/commands/level.spec.ts
lines 327-345, assert no level-service method runs; in
packages/bot/src/functions/general/commands/reactionrole.spec.ts lines 61-74,
assert no reaction-role handler runs; in
packages/bot/src/functions/general/commands/reactionrole.spec.ts lines 143-156,
remove the duplicate test or add the same no-handler assertion; in
packages/bot/src/functions/general/commands/roleconfig.spec.ts lines 60-73,
assert no role-configuration handler runs; and in
packages/bot/src/functions/general/commands/starboard.spec.ts lines 80-93,
assert no starboard-service method runs after requireGuild resolves false.

In `@packages/bot/src/functions/general/commands/starboard.spec.ts`:
- Around line 146-159: Update the self-star test around starboardCommand.execute
and starboardServiceMock.upsertConfig to inspect the persisted configuration
argument and assert its self-star field is true, rather than using only
expect.any(Object).

In `@packages/bot/src/functions/general/commands/version.spec.ts`:
- Around line 43-51: Update the “defers reply with ephemeral flag” test to
assert the exact ephemeral flag value expected by versionCommand.execute,
replacing expect.anything() in the deferReply expectation. Keep the existing
interaction setup and command execution unchanged.

In `@packages/bot/src/functions/general/commands/voterewards.spec.ts`:
- Around line 44-48: Update the voterewards test setup around beforeEach so
every API test mocks global fetch with a resolved successful response,
preventing requests to localhost. Capture the original fetch before mocking and
restore it after each test, while preserving the existing interactionReply and
environment cleanup.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 32090074-8fef-4304-94ac-b545b18b22f8

📥 Commits

Reviewing files that changed from the base of the PR and between c658948 and 5034d24.

📒 Files selected for processing (9)
  • packages/bot/src/functions/general/commands/afk.spec.ts
  • packages/bot/src/functions/general/commands/help.spec.ts
  • packages/bot/src/functions/general/commands/level.spec.ts
  • packages/bot/src/functions/general/commands/ping.spec.ts
  • packages/bot/src/functions/general/commands/reactionrole.spec.ts
  • packages/bot/src/functions/general/commands/roleconfig.spec.ts
  • packages/bot/src/functions/general/commands/starboard.spec.ts
  • packages/bot/src/functions/general/commands/version.spec.ts
  • packages/bot/src/functions/general/commands/voterewards.spec.ts

Comment thread packages/bot/src/functions/general/commands/help.spec.ts
Comment thread packages/bot/src/functions/general/commands/help.spec.ts
Comment thread packages/bot/src/functions/general/commands/level.spec.ts
Comment thread packages/bot/src/functions/general/commands/starboard.spec.ts
Comment thread packages/bot/src/functions/general/commands/version.spec.ts
Comment thread packages/bot/src/functions/general/commands/voterewards.spec.ts

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 9 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/bot/src/functions/general/commands/help.spec.ts Outdated
Comment thread packages/bot/src/functions/general/commands/level.spec.ts
Comment thread packages/bot/src/functions/general/commands/starboard.spec.ts
Comment thread packages/bot/src/functions/general/commands/starboard.spec.ts
Comment thread packages/bot/src/functions/general/commands/version.spec.ts
Comment thread packages/bot/src/functions/general/commands/version.spec.ts
Comment thread packages/bot/src/functions/general/commands/voterewards.spec.ts
Comment thread packages/bot/src/functions/general/commands/reactionrole.spec.ts
Comment thread packages/bot/src/functions/general/commands/starboard.spec.ts
Comment thread packages/bot/src/functions/general/commands/help.spec.ts
@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

Kimi review (kimi-code/kimi-for-coding, via local subscription)

• VERDICT: ISSUES

  • [medium] packages/bot/src/functions/general/commands/level.spec.ts — makeInteraction is called with the string 'null' as subcommandGroup for rank/leaderboard/setup tests. Discord.js getSubcommandGroup() returns string | null, so a truthy string is semantically different from null and may route through the wrong branch or mask real subcommand-group logic. Fix: pass actual null, not the string 'null'.

  • [medium] packages/bot/src/functions/general/commands/help.spec.ts:73 and help.spec.ts:113 — duplicate test name handles empty command list in the same describe block. The second test shadows/duplicates the first, making failure reports ambiguous and hiding that the later test actually asserts embed presence. Fix: rename the second test to something distinct, e.g. returns embeds for empty command list.

  • [medium] packages/bot/src/functions/general/commands/voterewards.spec.ts:105 — the API-error test replaces global.fetch with a mock but never restores it. Leaked global mocks can corrupt later tests in the same file or suite and let regressions slip. Fix: save const originalFetch = global.fetch in beforeEach and restore it in afterEach, or use jest.spyOn(global, 'fetch').mockRejectedValueOnce(...) which auto-restores.

  • [medium] packages/bot/src/functions/general/commands/starboard.spec.ts:150 — allows self-star setting only asserts expect.any(Object) for the config payload, so it does not actually verify that selfStar: true reaches the service. A regression that drops the self-star flag would pass. Fix: assert expect.objectContaining({ selfStar: true }) (or the exact shape expected by the command).


Head 3c97004. Posted by kimi-review-watch (launchd).

LucasSantana-Dev and others added 2 commits July 21, 2026 23:23
Pagination tests now generate enough content to force multiple pages and
assert multi-reply behavior + page counter; error-path test forces a real
exception through displayAvatarURL and asserts errorLog fired (coderabbit
majors on #1859).

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 2 files (changes from recent commits).

Requires human review: Auto-approval blocked by 10 unresolved issues from previous reviews.

Re-trigger cubic

@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

Merge note (admin): all six required checks pass (Quality Gates, Security, SonarCloud Scan, madge/packages/bot, Build — Docker images, Migrations apply on Postgres 18); threads resolved. BLOCKED is the rollup FAILURE from the known non-required claude-review (#1836) + CodeRabbit rate limit.

Nominal tests previously contacted http://localhost:3000 for real and
passed by validating the offline fallback. Install a resolved fetch mock
per test and restore global.fetch after each (coderabbit stability major
on #1859).
@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

All three real issues from this review round are fixed: vacuous pagination tests (cd9fd89), never-entered error path (cd9fd89), unmocked fetch hitting localhost:3000 (f361b1e). The remaining ~10 threads (assertion-strength suggestions across the new spec files) are follow-up polish — this PR is coverage-only and has already absorbed three fix rounds; further strengthening belongs in a follow-up PR rather than as a merge blocker.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

0 issues found across 1 file (changes from recent commits).

Auto-approved: Test-only change adding 70 tests for general commands. No source code modified; coverage expansion with no impact on production behavior.

Re-trigger cubic

@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit a998e7d into main Jul 22, 2026
46 of 48 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the test/general-command-coverage branch July 22, 2026 02:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant