Skip to content

test : add unit tests for _gather_scan_summary in notification_service #2423

Description

@tmdeveloper007

Summary of What Needs to be Done:
Add unit tests for the _gather_scan_summary() async helper function in backend/secuscan/notification_service.py. This function collects task status, severity counts, and a report link for a scan completion webhook. It queries the database for task and finding records.

The existing test file testing/backend/unit/test_notification_service.py has 36 tests that cover process_scan_completion_webhook and other delivery functions, but _gather_scan_summary is not directly imported or tested — it is only exercised indirectly through process_scan_completion_webhook.

Changes that Need to be Made:
Add a new test section (or new test class) in testing/backend/unit/test_notification_service.py:

  • Import _gather_scan_summary from backend.secuscan.notification_service
  • Test that it returns None when the task_id does not exist in the database
  • Test that it returns a summary dict with correct structure when the task exists
  • Test that severity_counts correctly aggregates findings by severity
  • Test that the report_link includes the task_id and uses the configured base_url
  • Test that error_message from the task record is included in the summary
  • Test that tool_name falls back to plugin_id when tool_name is not set
  • Use the existing test_db fixture (AsyncDatabase) to set up test data

Impact that it would Provide:

  • Directly validates the summary aggregation logic independent of webhook delivery
  • Ensures severity counts are computed correctly regardless of webhook configuration
  • Provides clear unit-level coverage for the helper before it is used in more complex flows

Note: This task is being handled by tmdeveloper007 — please assign to that account when picking it up.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions