airqo-platform/AirQo-api
Add unit tests for cohort validator — updateCohort and updateCohortName
Open
#6,209 opened on Mar 10, 2026
device-registrygood first issuetesting
Repository metrics
- Stars
- (26 stars)
- PR merge metrics
- (PR metrics pending)
Description
Add unit tests for cohort validator — updateCohort and updateCohortName
🏷️ Labels
good first issue · testing · device-registry
📋 Background
As part of the hotfix in fix-cohort-name (which added an explicit rejection of the name field on PUT /cohorts/:cohort_id), a Copilot reviewer flagged that there are no unit tests covering the cohort validators in src/device-registry/validators/cohorts.validators.js.
Other validators in the same service already have test coverage (e.g., validators/test/ut_device.validators.js). Cohort validators should follow the same pattern to prevent regressions.
🎯 What needs to be done
Create a new test file:
src/device-registry/validators/test/ut_cohort.validators.js
At minimum, the following cases should be covered:
updateCohort — PUT /cohorts/:cohort_id
- Returns
400with message"name cannot be updated via this endpoint; use PUT /cohorts/:cohort_id/name instead"whennameis present in the request body - Returns
200(passes validation) whennameis absent and other valid fields are provided (description,visibility,cohort_tags,groups,network) - Returns
400whencohort_idparam is not a valid MongoDB ObjectId
updateCohortName — PUT /cohorts/:cohort_id/name
- Returns
400whennameis missing - Returns
400whenconfirm_updateis missing or set tofalse - Returns
400whenupdate_reasonis missing, empty, or shorter than 10 characters - Returns
400whenupdate_reasonexceeds 500 characters - Passes validation when all required fields (
name,confirm_update: true,update_reason) are correctly provided
General
- Returns
400whentenantquery param is provided but is not in the allowed tenants list
📁 Reference
- Validators file:
src/device-registry/validators/cohorts.validators.js - Existing test example to follow:
src/device-registry/validators/test/ut_device.validators.js - Related hotfix PR:
fix-cohort-name
✅ Acceptance Criteria
- New test file exists at the path above
- All cases listed are covered with assertions on both the HTTP status code and the error message
- All existing tests continue to pass
- No changes to production code are required for this issue