Skip to content

Conversation

@pranav718
Copy link
Contributor

Summary

Continuation of #1089 - adding unit tests for the remaining untested controllers as suggested by @marcgc21.

This PR adds 12 new unit tests for:

  • EmailController (5 tests) - axios-based email sending
  • ReportController (7 tests) - Firestore report removal

Changes

File Status
tests/unit/EmailController.spec.js NEW
tests/unit/ReportController.spec.js NEW

Test Coverage

EmailController

  • Structure verification
  • Axios POST with correct URL/payload
  • Success/error response handling

ReportController

  • HEURISTIC type → heuristicAnswers field
  • USER type → taskAnswers field
  • User/answer document existence checks
  • Error handling

Testing

npm test -- --testPathPattern="EmailController|ReportController"

@github-actions
Copy link

github-actions bot commented Jan 4, 2026

⚠️ PR Description Issues Detected

Please update the PR description to address these issues.

@marcgc21
Copy link
Member

marcgc21 commented Jan 5, 2026

@pranav718 everything seems okay just the SonarCloud is failing due to duplicated code. Can you make something to make the files more reusable?

@pranav718
Copy link
Contributor Author

Thanks for the feedback @marcgc21!

I'll refactor the test files to reduce duplication by:

  1. Creating a shared tests/unit/helpers/testUtils.js with reusable utilities:

    • createControllerSpies()- which will extract repetitive spy setup for parent controller methods
    • createMockDoc()- helper for creating mock firestore documents
  2. Refactoring ReportController.spec.js to use these shared helpers (which will reduce the number of lines from ~225 to ~100 lines)

The duplicated code % will reduce a lot with this.

Will push the changes shortly!

@pranav718 pranav718 force-pushed the add-email-report-controller-tests branch from 84eeda4 to 5e08cd1 Compare January 5, 2026 14:30
@marcgc21
Copy link
Member

marcgc21 commented Jan 6, 2026

Hi @pranav718, just one question, when you run the npm run test, it appears something like that?

Screenshot 2026-01-06 at 08 39 43

@pranav718
Copy link
Contributor Author

Hi @marcgc21! Sorry about that! Yes, you're right, those console.error messages were appearing in the test output. I should have caught that earlier.

Those were expected errors from the error handling test cases, but they were cluttering the output and making it look messy. My apologies for the oversight!

I've fixed this by mocking console.error in both test files during beforeEach and restoring it in afterEach. The tests still verify the error handling behavior correctly, but now the output is clean:
Screenshot 2026-01-06 at 5 19 53 PM

Thanks for pointing this out

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 6, 2026

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