feat: enhance application scoring and update validation#2573
feat: enhance application scoring and update validation#2573iamitprakash merged 6 commits intodevelopfrom
Conversation
- Added score handling in nudgeApplication logic to increment score on nudging. - Updated application creation to set an initial score of 50. - Enhanced application update validation to include optional fields: firstName, lastName, college, skills, city, state, country, and role. - Improved integration tests to verify score updates and application modifications. - Adjusted unit tests to reflect changes in application scoring logic.
WalkthroughThe PR introduces a scoring system for applications by setting an initial score of 50 upon creation and incrementing it by 10 on each nudge. The application update payload is expanded to include personal information fields (firstName, lastName, city, state, country, college), skills, and role, with corresponding validator schema, type definitions, and field mapping updates. Tests are updated to verify score values and new update capabilities. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 4
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
middlewares/validators/application.ts (2)
159-159:⚠️ Potential issue | 🟡 Minor
numberOfHoursmax is 168 in update but 100 in creation.The creation schema (line 54) caps
numberOfHoursat 100, but the update schema allows up to 168. If this is intentional, it should be documented; otherwise, align both to the same max.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@middlewares/validators/application.ts` at line 159, The update schema allows numberOfHours up to 168 while the creation schema caps it at 100—ensure both schemas use the same limit by updating the creation or update validation to the agreed maximum; locate the creation validation (e.g., createApplicationSchema or the schema defined around line ~54) and the update validation (e.g., updateApplicationSchema where numberOfHours: joi.number().min(1).max(168).optional()) and make the max consistent (either change the creation max to 168 or the update max to 100), and add a brief comment if the discrepancy is intentional.
121-162:⚠️ Potential issue | 🟡 MinorConflicting flat and nested keys can produce ambiguous updates.
The schema accepts both flat keys (
skills,college) and the nestedprofessionalobject (professional.skills,professional.institution). If a client sends both in one request,buildApplicationUpdatePayloadinutils/application.tswrites to the same Firestore dot-notation paths (professional.skills,professional.institution) twice — the last write wins nondeterministically.Either:
- Remove the
professionalnested object from the update schema (since flat keys now cover the same fields), or- Add a Joi
.xor()/.without()constraint to prevent sending both flat and nested variants simultaneously.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@middlewares/validators/application.ts` around lines 121 - 162, The schema currently allows both flat keys (skills, college) and the nested professional object (professional.skills, professional.institution) which creates ambiguous Firestore dot-path writes in buildApplicationUpdatePayload; update the Joi schema to forbid sending both variants together by adding mutual-exclusion constraints (e.g., call .without('professional','skills') and .without('professional','college') or use .xor(['professional','skills'], ['professional','college']) on the main schema) so requests cannot include flat and nested fields simultaneously.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@models/applications.ts`:
- Around line 222-234: Replace the magic number 10 used to bump
application.score with a named constant (e.g., NUDGE_SCORE_INCREMENT) and use it
when computing updatedScore and updating the document; specifically, define
NUDGE_SCORE_INCREMENT alongside the initial score constant in
services/applicationService.ts and then change the calculation in
models/applications.ts from (application.score || 0) + 10 to (application.score
|| INITIAL_SCORE) + NUDGE_SCORE_INCREMENT (or similar referencing the existing
initial score constant), and update the transaction.update and the returned
score value to use the new updatedScore variable.
In `@services/applicationService.ts`:
- Line 89: The literal 50 assigned to the score property is a magic number;
define a named constant (e.g., INITIAL_APPLICATION_SCORE) in the application's
constants module alongside the existing nudge increment constant and replace the
hardcoded 50 in the score assignment with INITIAL_APPLICATION_SCORE so future
adjustments are centralized and self-documenting.
In `@test/integration/application.test.ts`:
- Line 884: The test inserts fixtures via
applicationModel.addApplication(applicationsData[0]) which lacks a score,
causing the nudge to produce 10; update the fixture so created apps reflect real
API behavior by setting score: 50 on the fixture used in beforeEach (modify
applicationsData[0] or the setup that calls applicationModel.addApplication) and
then change the assertion on expect(res.body.score) to expect 60; alternatively,
replace the fixture insertion with an end-to-end flow that POSTs the application
through the API, then calls the nudge endpoint and asserts the score is 60
(referencing applicationModel.addApplication, applicationsData, and the
expect(res.body.score) assertion).
- Around line 549-564: Convert the test "should return 400 when updating role
with an invalid role" to use async/await for consistency: change the it(...)
callback to an async function, await applicationModel.addApplication(...) to get
testApplicationId, then await
chai.request(app).patch(`/applications/${testApplicationId}`).set("cookie",
`${cookieName}=${jwt}`).send({ role: "invalid_role" }) and perform the same
expect assertions on the awaited response; remove the done() callback and any
.end(...) callback usage. Use the same assertion lines
(expect(res).to.have.status(400); expect(res.body.error).to.equal("Bad
Request");) after awaiting the request.
---
Outside diff comments:
In `@middlewares/validators/application.ts`:
- Line 159: The update schema allows numberOfHours up to 168 while the creation
schema caps it at 100—ensure both schemas use the same limit by updating the
creation or update validation to the agreed maximum; locate the creation
validation (e.g., createApplicationSchema or the schema defined around line ~54)
and the update validation (e.g., updateApplicationSchema where numberOfHours:
joi.number().min(1).max(168).optional()) and make the max consistent (either
change the creation max to 168 or the update max to 100), and add a brief
comment if the discrepancy is intentional.
- Around line 121-162: The schema currently allows both flat keys (skills,
college) and the nested professional object (professional.skills,
professional.institution) which creates ambiguous Firestore dot-path writes in
buildApplicationUpdatePayload; update the Joi schema to forbid sending both
variants together by adding mutual-exclusion constraints (e.g., call
.without('professional','skills') and .without('professional','college') or use
.xor(['professional','skills'], ['professional','college']) on the main schema)
so requests cannot include flat and nested fields simultaneously.
…, service, and tests
* Merge pull request #2576 from RealDevSquad/2569-refactor-test-for-group-idle fix: test expectations for idle user * feat: enhance application scoring and update validation (#2573) * feat: enhance application scoring and update validation - Added score handling in nudgeApplication logic to increment score on nudging. - Updated application creation to set an initial score of 50. - Enhanced application update validation to include optional fields: firstName, lastName, college, skills, city, state, country, and role. - Improved integration tests to verify score updates and application modifications. - Adjusted unit tests to reflect changes in application scoring logic. * feat: introduce application scoring system and update application queries * test: refactor application update test for invalid role handling * refactor: remove firstName and lastName from application update validation and tests * refactor: rename 'college' to 'institution' in application validation, service, and tests * feat: implement user picture upload handling for application type (#2564) --------- Co-authored-by: Vinit khandal <vinit224488@gmail.com>
Date: 17 feb 2026
Developer Name: @AnujChhikara
Issue Ticket Number
Description
Documentation Updated?
Under Feature Flag
Database Changes
Breaking Changes
Development Tested?
Screenshots
Screenshot 1
Screen.Recording.2026-02-17.at.11.19.58.PM.mov
Screen.Recording.2026-02-17.at.11.21.23.PM.mov
Screen.Recording.2026-02-17.at.11.23.24.PM.mov
Test Coverage
Screenshot 1
Additional Notes