Skip to content

test(bot): cover untested moderation and download commands - #1858

Merged
LucasSantana-Dev merged 4 commits into
mainfrom
test/moderation-download-coverage
Jul 22, 2026
Merged

LucasSantana-Dev merged 4 commits into
mainfrom
test/moderation-download-coverage

Conversation

@LucasSantana-Dev

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

Copy link
Copy Markdown
Owner

What

Adds 70 tests (5 spec files) for previously-untested HIGH-risk bot commands. Follow-up to #1855 (music+giveaway), same rigor.

File Tests Covers
moderation/commands/ban.spec.ts 14 BanMembers gate, DM, message deletion, case creation, error paths
moderation/commands/kick.spec.ts 14 KickMembers gate, member fetch, DM, audit log, guild validation
moderation/commands/mute.spec.ts 15 ModerateMembers gate, duration parsing (60s-7d), timeout conversion, case log
moderation/commands/warn.spec.ts 16 case creation, DM + silent mode, error recovery
download/commands/download/command.spec.ts 11 service integration, file-size edge cases (0/undefined/>1GB), URL extraction, errors

Why

Moderation (ban/kick/mute/warn) and download commands had zero coverage — permission gates, target validation, and audit-log paths were unvalidated. These are destructive/sensitive flows.

Verification

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

Test Suites: 1 skipped, 225 passed, 225 of 226 total
Tests:       1 skipped, 3026 passed, 3027 total

Coverage status after this + #1855

Music, giveaway, moderation, download now covered. Remaining lighter gaps: general commands (11/20) — a possible future follow-up.


Summary by cubic

Adds 70 Jest tests for high‑risk moderation commands (ban, kick, mute, warn) and the download command; spec‑only with no source changes. Also removes an unused test import flagged by CodeQL.

  • Coverage

    • Moderation: permission gates, member fetch/validation, default reasons, guild‑only checks, command metadata, and ban message deletion seconds.
    • DMs and silent mode: pre‑action DMs with graceful failure handling.
    • Mod logs and responses: case creation/posting and case numbers in replies.
    • Mute: parse 60s–7d, convert to ms, and show friendly durations.
    • Download: immediate “Processing” reply, service integration, URL extraction, default video format, context (userId/guildId), file‑size edges (0/undefined/>1GB), ephemeral errors, and ordered replies.
  • Refactors

    • Drop unused EmbedBuilder import in tests (CodeQL).

Written for commit 59822e4. Summary will update on new commits.

Review in cubic

Add comprehensive test coverage for high-risk moderation commands
(ban, kick, mute, warn) and download command. Tests cover permission
gates, user validation, DM sending, duration parsing, audit logging,
error handling, and edge cases. All tests pass with green suite.
@coderabbitai

coderabbitai Bot commented Jul 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 6 minutes

Your organization has reached its usage spending cap. Adjust your spending cap in the billing tab.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: a77b1100-bbe7-46ec-833a-f8cebea9b8d3

📥 Commits

Reviewing files that changed from the base of the PR and between 10afb9b and 59822e4.

📒 Files selected for processing (5)
  • packages/bot/src/functions/download/commands/download/command.spec.ts
  • packages/bot/src/functions/moderation/commands/ban.spec.ts
  • packages/bot/src/functions/moderation/commands/kick.spec.ts
  • packages/bot/src/functions/moderation/commands/mute.spec.ts
  • packages/bot/src/functions/moderation/commands/warn.spec.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/moderation-download-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 — 1783 lines changed across 5 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 59822e4

Comment thread packages/bot/src/functions/moderation/commands/ban.spec.ts Fixed

@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 5 files

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

Re-trigger cubic

Comment thread packages/bot/src/functions/moderation/commands/warn.spec.ts
Comment thread packages/bot/src/functions/moderation/commands/warn.spec.ts
Comment thread packages/bot/src/functions/moderation/commands/kick.spec.ts
Comment thread packages/bot/src/functions/moderation/commands/mute.spec.ts
Comment thread packages/bot/src/functions/moderation/commands/mute.spec.ts
Comment thread packages/bot/src/functions/moderation/commands/warn.spec.ts
Comment thread packages/bot/src/functions/moderation/commands/ban.spec.ts
@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

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

• VERDICT: ISSUES

  • [SEVERITY high] command.spec.ts:8-14, ban.spec.ts:19, kick.spec.ts:11, mute.spec.ts:15, warn.spec.ts:11 — jest.mock(...) factories reference const-declared mock variables. Jest hoists jest.mock above those const declarations, so the factory bodies evaluate the mocks while they are still in the temporal dead zone and the tests will fail with a ReferenceError on load. Fix: declare the mock variables with var instead of const so they are hoisted and initialized before the hoisted mock factories run, or move the mock setup into jest.doMock calls after the variable declarations.

  • [SEVERITY medium] ban.spec.ts:'includes message deletion info in embed when deleteMessages > 0', kick.spec.ts:'includes case number in response embed', mute.spec.ts:'includes duration in response embed', warn.spec.ts:'includes case number in response embed' and 'includes reason in both embed and DM' — these tests only assert that a reply or DM was sent, not that the expected content (case number, duration, reason, deletion info) actually appears. A regression that removes those fields from the embed/DM will still pass. Fix: inspect interactionReplyMock.mock.calls and targetUser.send.mock.calls for the expected strings/embed fields.

  • [SEVERITY medium] ban.spec.ts:'handles ban failure', kick.spec.ts:'handles kick failure', mute.spec.ts:'handles mute failure', warn.spec.ts:'handles warning creation failure' — failure-path tests assert an error reply and logging, but they do not assert that downstream side effects are prevented. A regression that still creates a moderation case after a failed ban/kick/mute, or still sends a DM after a failed warning creation, would slip through. Fix: add negative expectations such as expect(moderationServiceMock.createCase).not.toHaveBeenCalled() for ban/kick/mute failures and expect(targetUser.send).not.toHaveBeenCalled() for warning-creation failure.

  • [SEVERITY medium] command.spec.ts download URL tests — the URL is passed straight through to the service without any coverage for validation/sanitization. A regression that allows non-HTTP schemes, file://, or internal/private URLs to reach the downloader (SSRF / injection risk) would not be caught. Fix: add tests for rejected URL schemes, local/internal addresses, and malformed URLs.

  • [SEVERITY medium] command.spec.ts:'handles downloads larger than 1 GB' — the test expects 1024.00 MB for 1 GB. If the formatter is intended to switch to GB above 1 GB, this test either fails or locks in the wrong behavior; if it intentionally stays in MB, the test name is misleading. Fix: align the expected output with the intended formatter behavior and add an explicit GB-threshold test if GB formatting is expected.


Head c01c358. Posted by kimi-review-watch (launchd).

@LucasSantana-Dev

Copy link
Copy Markdown
Owner Author

CodeQL unused-import fixed (59822e4). cubic P2s on warn.spec assertions are advisory test-strength suggestions on the new test code (same class as #1855's resolved threads) — follow-up polish, not merge blockers for a coverage-only PR.

@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: Adds 70 tests for high-risk moderation and download commands. No source changes, only spec addition. Bounded and clearly beneficial.

Re-trigger cubic

@sonarqubecloud

Copy link
Copy Markdown

@LucasSantana-Dev
LucasSantana-Dev merged commit 183e0e1 into main Jul 22, 2026
46 of 48 checks passed
@LucasSantana-Dev
LucasSantana-Dev deleted the test/moderation-download-coverage branch July 22, 2026 02:23
LucasSantana-Dev added a commit that referenced this pull request Jul 22, 2026
## 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.

<!-- This is an auto-generated description by cubic. -->
---
## 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.

<sup>Written for commit f361b1e.
Summary will update on new commits.</sup>

<a
href="https://cubic.dev/pr/LucasSantana-Dev/Lucky/pull/1859?utm_source=github"
target="_blank" rel="noopener noreferrer"
data-no-image-dialog="true"><picture><source
media="(prefers-color-scheme: dark)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source
media="(prefers-color-scheme: light)"
srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img
alt="Review in cubic"
src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a>

<!-- End of auto-generated description by cubic. -->

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## 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.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
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.

2 participants