Skip to content

feat: Complete velocity check implementation with proper threshold logic tests#718

Open
Belzabeem wants to merge 1 commit into
Fracverse:masterfrom
Belzabeem:feature/complete-compliance-velocity-check-implementation
Open

feat: Complete velocity check implementation with proper threshold logic tests#718
Belzabeem wants to merge 1 commit into
Fracverse:masterfrom
Belzabeem:feature/complete-compliance-velocity-check-implementation

Conversation

@Belzabeem
Copy link
Copy Markdown

Closes #625

Summary

Complete velocity check implementation with proper threshold logic tests for the ComplianceEngine.

Changes

backend/src/compliance.rs

  • Added test_velocity_threshold_evaluation() - validates velocity threshold and window configuration
  • Added test_volume_threshold_evaluation() - validates volume threshold configuration
  • Removed placeholder TODO comments

backend/tests/compliance_integration_tests.rs

  • Added test_velocity_no_flag_below_threshold() - verifies no flagging when events < threshold
  • Added test_velocity_events_outside_window_not_flagged() - verifies no flagging when events outside time window
  • Added test_velocity_exactly_at_threshold() - verifies flagging at exact threshold
  • Added test_velocity_repay_events_included() - verifies both borrow/repay events are counted
  • Added test_volume_below_threshold_not_flagged() - verifies volume threshold is enforced
  • Added test_velocity_suspicion_flags_stored() - verifies suspicion flags are persisted
  • Added test_velocity_audit_log_created() - verifies audit log creation
  • Added helper functions: insert_old_test_plan() and insert_test_lending_event()

Notes

The detect_high_velocity implementation was already complete - the SQL query uses HAVING COUNT(*) >= $2 correctly. This change adds comprehensive test coverage to ensure no potential violations slip undetected.

Add comprehensive test coverage for detect_high_velocity in ComplianceEngine:
- Test for no flagging when events are below threshold
- Test for no flagging when events are outside velocity window
- Test for flagging when events exactly equal threshold
- Test for borrow and repay events both being counted
- Test for volume threshold below/above scenarios
- Test for suspicion flags being stored correctly
- Test for audit log entry creation

The detect_high_velocity implementation was already complete - the SQL query
uses HAVING COUNT(*) >= threshold correctly. This change adds missing test
coverage to ensure the threshold logic works as expected.
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@Belzabeem 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! 🚀

Learn more about application limits

Copy link
Copy Markdown
Contributor

@ONEONUORA ONEONUORA left a comment

Choose a reason for hiding this comment

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

Great job @Belzabeem

@ONEONUORA
Copy link
Copy Markdown
Contributor

@Belzabeem Pls fix conflict

@ONEONUORA
Copy link
Copy Markdown
Contributor

@Belzabeem Pls update on this

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.

Backend: Complete compliance velocity check implementation

3 participants