Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

Fixing Invalid Referral Status and Raising Test Coverage in the Brokers API (NestJS)

Description and use

Implemented enum validation in NestJS controller, fixed SQL typo, and expanded unit tests, raising coverage above 80% and eliminating 500 errors caused by invalid referral statuses.

Problem

BrokersController threw 500 errors when referral status was not a valid enum value, and a SQL typo caused query failures. The test coverage for brokers and communications was below 3%, allowing bugs to slip through.

Outcome

Implemented robust enum validation, corrected SQL typo, and expanded unit tests, raising test coverage from ~1% to >80% and eliminating 500 errors caused by invalid referral statuses.

Workflow

  • Align controller with ReferralStatus enum using ParseEnumPipe
  • Replace hard‑coded status guard with automatic enum validation
  • Fix SQL query to use correct alias 'total' instead of 'count'
  • Create brokers.test.ts covering CRUD, agent management, portal flows, and status updates
  • Create communications.test.ts covering email logic with sendMail mock
  • Run tests to confirm 400 on invalid status and 200 on valid status
  • Verify coverage reports exceed 80%
  • Commit changes and push to repository

Evidence

The pipe throws a BadRequestException automatically if the payload isn’t a valid enum value

Source

A snippet from brokers.test.ts that verifies enum validation

Source

  • Record date: 2026-09-20T02:30:18.935Z