Repository navigation
test(bot): cover untested music player-state and giveaway commands - #1855
Conversation
Add behavior-covering tests for high-risk music commands (pause, replay, remove, clear) and giveaway winner selection, end-state, permission gates. - pause.spec.ts: pause/resume state transitions, empty queue edge case - replay.spec.ts: permission validation chain, seek-to-zero behavior - remove.spec.ts: queue-index validation, track removal edge cases - clear.spec.ts: error handling, track count logging - giveaway.spec.ts: start/end/reroll flows, winner announcement, DB cleanup All tests verify state mutations, validation paths, and error branches.
📝 WalkthroughWalkthroughAdded Jest coverage for the giveaway lifecycle and four music commands, including validation exits, success paths, error handling, embeds, logging, persistence cleanup, and ephemeral replies. ChangesGiveaway command tests
Music command tests
Estimated code review effort: 3 (Moderate) | ~25 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
|
Failed to generate code suggestions for PR |
|
There was a problem hiding this comment.
No issues found across 5 files
Auto-approved: Test-only addition covering high-risk commands; no behavior changes, operational tradeoffs, or schema modifications. Clearly bounded and beneficial.
Re-trigger cubic
Kimi review (
|
There was a problem hiding this comment.
Actionable comments posted: 8
🧹 Nitpick comments (1)
packages/bot/src/functions/general/commands/giveaway.spec.ts (1)
128-131: 🔒 Security & Privacy | 🔵 Trivial | ⚡ Quick winAssert the exact
PermissionFlagsBits.ManageGuildbitfield. Checking only thatdefault_member_permissionsis defined still passes for0or the wrong permission, so this test would miss a broken command restriction.🤖 Prompt for 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. In `@packages/bot/src/functions/general/commands/giveaway.spec.ts` around lines 128 - 131, Update the “requires ManageGuild permission” test to assert that giveawayCommand.data.default_member_permissions exactly matches the PermissionFlagsBits.ManageGuild bitfield, rather than only checking that the value is defined.
🤖 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/giveaway.spec.ts`:
- Around line 229-242: Update giveaway.spec.ts:229-242 in the “cleans up DB
record if message post fails” test to also assert the expected ephemeral failure
reply after channel.send rejects, while retaining the deletion assertion. At
giveaway.spec.ts:456-470, parameterize the error cases to cover both paths or
rename the test so it accurately describes only the missing-context path.
- Around line 332-349: Strengthen the giveaway announcement assertions in
packages/bot/src/functions/general/commands/giveaway.spec.ts at lines 332-349
and 411-427: inspect the argument passed to channel.send in the “ends giveaway
and announces winners” test and the reroll announcement test, asserting it
contains the winner mention (<`@winner-1`> or <`@new-winner-1`>), Prize, and the
expected allowed-user mentions rather than only verifying dispatch.
- Around line 351-374: Update the assertion in the “logs giveaway end with
winners” test to verify that the logged data includes the expected winner ID,
“winner-1”, in addition to the existing giveaway ID check. Keep the assertion
focused on the end-log payload.
- Around line 202-212: Update the “posts message to channel with react” test for
giveawayCommand.execute to capture the message returned by channel.send and
assert that its react method is called with the giveaway entry emoji 🎉. Keep
the existing channel.send assertion while ensuring the test fails if the entry
reaction is removed.
In `@packages/bot/src/functions/music/commands/clear.spec.ts`:
- Around line 120-133: Update the success assertions in
packages/bot/src/functions/music/commands/clear.spec.ts lines 120-133 to verify
interactionReplyMock receives the Queue cleared embed containing the track
count, rather than only checking createSuccessEmbedMock. In
packages/bot/src/functions/music/commands/remove.spec.ts lines 222-253, assert
the reply contains the Song removed embed with both Track 2 and Artist 2,
covering the author details.
- Around line 68-90: Strengthen the validation-failure tests so they prove
downstream work is skipped. In
packages/bot/src/functions/music/commands/clear.spec.ts:68-90, assert
resolveGuildQueueMock is not called after guild validation fails and queue.clear
is not called after queue validation fails. In
packages/bot/src/functions/music/commands/remove.spec.ts:79-125, assert each
failed validation gate prevents later validators or queue resolution and keeps
queue.tracks.remove untouched.
In `@packages/bot/src/functions/music/commands/pause.spec.ts`:
- Around line 170-184: Update the fallback-embed tests in
packages/bot/src/functions/music/commands/pause.spec.ts lines 170-184 and
packages/bot/src/functions/music/commands/replay.spec.ts lines 172-186: mock a
fallback embed before executing each command, then assert interactionReplyMock
receives that embed through content.embeds. Retain the existing
createSuccessEmbed assertions while verifying the generated fallback is actually
replied to.
In `@packages/bot/src/functions/music/commands/replay.spec.ts`:
- Around line 188-211: The test `validates all permission checks before seeking`
must verify every playback guard runs before seeking. Record calls from
`requireVoiceChannelMock`, `requireDJRoleMock`, `requireQueueMock`,
`requireCurrentTrackMock`, and `requireIsPlayingMock`, then assert the complete
expected call sequence ends with `seek`.
---
Nitpick comments:
In `@packages/bot/src/functions/general/commands/giveaway.spec.ts`:
- Around line 128-131: Update the “requires ManageGuild permission” test to
assert that giveawayCommand.data.default_member_permissions exactly matches the
PermissionFlagsBits.ManageGuild bitfield, rather than only checking that the
value is defined.
🪄 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: f24958bb-ad06-4b9d-8eb8-2b4ed9c87293
📒 Files selected for processing (5)
packages/bot/src/functions/general/commands/giveaway.spec.tspackages/bot/src/functions/music/commands/clear.spec.tspackages/bot/src/functions/music/commands/pause.spec.tspackages/bot/src/functions/music/commands/remove.spec.tspackages/bot/src/functions/music/commands/replay.spec.ts
|
|
Resolving CodeRabbit threads (7 Minor + 1 Major) as advisory: all are assertion-strengthening suggestions on the new test code itself, not defects in production code. This PR is pure coverage (+1367/-0); deeper assertion polish is follow-up work, not a merge blocker per the 'improves overall health' bar. |
## 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. <!-- This is an auto-generated description by cubic. --> --- ## 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). <sup>Written for commit 59822e4. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/LucasSantana-Dev/Lucky/pull/1858?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. -->
## 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 -->



What
Adds 81 tests (5 spec files) for previously-untested HIGH-risk bot commands surfaced by a test-health audit.
music/commands/pause.spec.tsmusic/commands/replay.spec.tsmusic/commands/remove.spec.tsmusic/commands/clear.spec.tsgeneral/commands/giveaway.spec.tsWhy
These are core, high-velocity paths (player/queue state mutation, giveaway winner selection + permissions) that had zero coverage. Music commands use the existing
commandValidations.tsseam; tests mirror the existing music-command spec patterns.Verification
Spec-only diff (no source changed). Bot suite green:
Out of scope (follow-up)
Still-untested groups deferred to a separate PR: moderation (12/17), download (0/2), general (11/20).
Summary by cubic
Adds 81 behavior-covering tests for high-risk music commands (
pause,replay,remove,clear) and thegiveawaycommand (start/end/reroll) to harden player-state transitions, validation chains, and permission gates (voice/DJ, ManageGuild).Covers duration parsing with a 14-day cap, 1-based queue index handling, empty-queue cases, winner selection and announcements, message ID updates and DB cleanup, logging (including guild IDs), and consistent ephemeral error replies.
Written for commit cfcc838. Summary will update on new commits.
Summary by CodeRabbit