test(cli): add tests for alerts test command - #281
Conversation
Cover the 'alerts test' subcommand with unit tests: - dispatcher is invoked with correct channel type, target, and event - test message delivered to webhook and Slack channels - webhook secret passed through to dispatcher - exits with code 1 on delivery failure - exits with code 1 when config ID is not found or not numeric
📝 WalkthroughSummary by CodeRabbit
WalkthroughAdds a Vitest mock for alerts test command coverage
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
@Tijesunimi004 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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 `@tests/commands/alerts.test.ts`:
- Around line 297-298: The timestamp check in the alerts test is not actually
validating the value because `new Date(event.timestamp)` can succeed for invalid
strings. Update the assertion in the test around `event.timestamp` to use a real
parseability/validity check instead, and keep the existing `typeof
event.timestamp` guard so the test verifies the timestamp produced by the alert
event is truly valid.
🪄 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: Organization UI
Review profile: ASSERTIVE
Plan: Pro Plus
Run ID: 8a0fd8ec-e5e3-4920-9c1c-7e729cea7b05
📒 Files selected for processing (1)
tests/commands/alerts.test.ts
📜 Review details
🔇 Additional comments (1)
tests/commands/alerts.test.ts (1)
10-15: LGTM!Also applies to: 250-282, 303-427
| expect(typeof event.timestamp).toBe("string"); | ||
| expect(() => new Date(event.timestamp)).not.toThrow(); |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Make the timestamp assertion actually validate the value
new Date(event.timestamp) never throws for malformed strings, so this can pass with an invalid timestamp. Use a parseability check instead.
🤖 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 `@tests/commands/alerts.test.ts` around lines 297 - 298, The timestamp check in
the alerts test is not actually validating the value because `new
Date(event.timestamp)` can succeed for invalid strings. Update the assertion in
the test around `event.timestamp` to use a real parseability/validity check
instead, and keep the existing `typeof event.timestamp` guard so the test
verifies the timestamp produced by the alert event is truly valid.
|
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| - | - | Generic High Entropy Secret | 3dd17ce | tests/core/vault.test.ts | View secret |
| - | - | Generic High Entropy Secret | 3dd17ce | tests/core/vault.test.ts | View secret |
| - | - | Generic High Entropy Secret | 3dd17ce | tests/core/vault.test.ts | View secret |
| - | - | Generic High Entropy Secret | b59bef4 | tests/core/vault.test.ts | View secret |
| - | - | Generic High Entropy Secret | b59bef4 | tests/core/vault.test.ts | View secret |
| - | - | Generic High Entropy Secret | b59bef4 | tests/core/vault.test.ts | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
Cover the 'alerts test' subcommand with unit tests: - dispatcher is invoked with correct channel type, target, and event - test message delivered to webhook and Slack channels - webhook secret passed through to dispatcher - exits with code 1 on delivery failure - exits with code 1 when config ID is not found or not numeric
Cover the 'alerts test' subcommand with unit tests: - dispatcher is invoked with correct channel type, target, and event - test message delivered to webhook and Slack channels - webhook secret passed through to dispatcher - exits with code 1 on delivery failure - exits with code 1 when config ID is not found or not numeric
Closes #124.
What changed
Added unit tests for the
alerts testsubcommand intests/commands/alerts.test.ts.The implementation (
src/commands/alerts.ts) was already present; this PR adds the test coverage required by the issue.Tests added
threshold_crossedevent--idexits with code 1 without calling the dispatcher