Skip to content

fix: resolve issue #1403 - Validate Start and End Date Order for Hackathons#1404

Merged
Sachinchaurasiya360 merged 2 commits into
Sachinchaurasiya360:mainfrom
sonusharma6-dsa:fix-issue-1403
Jun 5, 2026
Merged

fix: resolve issue #1403 - Validate Start and End Date Order for Hackathons#1404
Sachinchaurasiya360 merged 2 commits into
Sachinchaurasiya360:mainfrom
sonusharma6-dsa:fix-issue-1403

Conversation

@sonusharma6-dsa
Copy link
Copy Markdown
Contributor

@sonusharma6-dsa sonusharma6-dsa commented Jun 4, 2026

Closes #1403

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced hackathon creation validation to prevent end dates from being set earlier than start dates, avoiding invalid scheduling configurations.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 4, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: caf6e649-1a0b-4d96-b03b-2bd4ce28a378

📥 Commits

Reviewing files that changed from the base of the PR and between e15a36c and 8313187.

📒 Files selected for processing (2)
  • server/src/module/admin/admin.validation.ts
  • server/src/module/ats/__tests__/ats.service.test.ts

📝 Walkthrough

Walkthrough

This PR adds date-ordering validation to hackathon creation and refactors test mock syntax in the ATS service tests. The first change enforces that event end dates cannot be earlier than start dates; the second updates mock implementations across three test cases to use explicit function syntax without altering test behavior.

Changes

Hackathon Date Validation

Layer / File(s) Summary
Date ordering validation in hackathon schema
server/src/module/admin/admin.validation.ts
createHackathonSchema now includes a Zod .refine() constraint that validates endDate >= startDate, with a custom error message targeted at the endDate field.

ATS Service Test Mock Refactoring

Layer / File(s) Summary
Mock implementation style updates
server/src/module/ats/__tests__/ats.service.test.ts
Three test cases (mockValidPdf helper, scoreResume, and applySuggestions) refactor PDFParse mock implementations from arrow-function return form to explicit function () { return {...} } style. No test assertions or behaviors change.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Poem

🐰 Dates now march in proper order,
Start before the end, no more disorder!
Mocks reshape their graceful stance,
Tests still pass their rightful dance. ✨

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete; it references the linked issue but lacks required sections like detailed description, testing information, and proper checklist completion. Expand the description to include a detailed explanation of changes, testing methodology, and ensure all checklist items are properly addressed.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding date order validation for hackathons, matching the primary objective of this PR.
Linked Issues check ✅ Passed The code changes directly implement the requirement from issue #1403: adding a .refine() validation to createHackathonSchema that ensures startDate is before or equal to endDate.
Out of Scope Changes check ✅ Passed Changes include the required date validation fix plus test mock refactoring for Vitest; the test changes are supportive and not out of scope for resolving the issue.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added gssoc quality:clean Clean and well-structured contribution gssoc:approved Approved for GSSoC scoring labels Jun 4, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jun 4, 2026

Hi @sonusharma6-dsa, thanks for contributing to InternHack! 🎉

I have automatically:

  • 👤 Assigned this PR to you.
  • 🏷️ Applied the gssoc:approved label.

Our workflows will now analyze your changes to classify:

  • 📈 PR Difficulty: level:*
  • 🧩 PR Type: type:*
  • 🌟 PR Quality: quality:*

Tip

Ensure your PR description references the issue it resolves (e.g. Closes #123). This allows the bot to inherit any additional labels from that issue!

Happy coding! 🚀

@github-actions github-actions Bot added scope:backend Changes to server-side / API code level:intermediate Requires moderate project understanding type:bug Bug fixes type:performance Performance optimization changes type:testing Adds or improves tests labels Jun 4, 2026
@github-actions github-actions Bot added level:beginner Good for first-time contributors and removed level:intermediate Requires moderate project understanding type:testing Adds or improves tests type:performance Performance optimization changes labels Jun 4, 2026
@github-actions github-actions Bot added type:testing Adds or improves tests quality:exceptional Exceptional implementation quality and removed quality:clean Clean and well-structured contribution labels Jun 4, 2026
@Sachinchaurasiya360
Copy link
Copy Markdown
Owner

Code Review — PR #1404: Validate hackathon start/end date order

Hi @sonusharma6-dsa, the validation logic is correct for the create path. Found one issue with how the partial schema inherits the refine.


🔴 updateHackathonSchema.partial() inherits the date refine — crashes when only one date field is provided

export const createHackathonSchema = z.object({
  startDate: z.string().datetime(),
  endDate: z.string().datetime(),
  ...
}).refine(
  (data) => new Date(data.startDate) <= new Date(data.endDate),
  { message: "End date cannot be before start date", path: ["endDate"] }
);

export const updateHackathonSchema = createHackathonSchema.partial();

When .partial() is applied to a ZodEffects (which is what .refine() returns), the refine function still runs on the parsed data — but now startDate and endDate can each be undefined. Inside the refine:

new Date(data.startDate)  // → new Date(undefined) → Invalid Date

Invalid Date <= Invalid Date evaluates to false, so the refine always fails for any PATCH request that doesn't include both dates. A recruiter trying to update only the hackathon title, location, or any other field will get "End date cannot be before start date" even though they never touched the dates.

Fix: Guard the refine for the undefined case:

export const createHackathonSchema = z.object({ ... }).refine(
  (data) => {
    if (!data.startDate || !data.endDate) return true;  // partial update — skip check
    return new Date(data.startDate) <= new Date(data.endDate);
  },
  { message: "End date cannot be before start date", path: ["endDate"] }
);

This makes the refine a no-op when either date is absent, which is the correct behavior for partial updates.

@sonusharma6-dsa
Copy link
Copy Markdown
Contributor Author

sonusharma6-dsa commented Jun 5, 2026

Code Review — PR #1404: Validate hackathon start/end date order

Hi @sonusharma6-dsa, the validation logic is correct for the create path. Found one issue with how the partial schema inherits the refine.

🔴 updateHackathonSchema.partial() inherits the date refine — crashes when only one date field is provided

export const createHackathonSchema = z.object({
  startDate: z.string().datetime(),
  endDate: z.string().datetime(),
  ...
}).refine(
  (data) => new Date(data.startDate) <= new Date(data.endDate),
  { message: "End date cannot be before start date", path: ["endDate"] }
);

export const updateHackathonSchema = createHackathonSchema.partial();

When .partial() is applied to a ZodEffects (which is what .refine() returns), the refine function still runs on the parsed data — but now startDate and endDate can each be undefined. Inside the refine:

new Date(data.startDate)  // → new Date(undefined) → Invalid Date

Invalid Date <= Invalid Date evaluates to false, so the refine always fails for any PATCH request that doesn't include both dates. A recruiter trying to update only the hackathon title, location, or any other field will get "End date cannot be before start date" even though they never touched the dates.

Fix: Guard the refine for the undefined case:

export const createHackathonSchema = z.object({ ... }).refine(
  (data) => {
    if (!data.startDate || !data.endDate) return true;  // partial update — skip check
    return new Date(data.startDate) <= new Date(data.endDate);
  },
  { message: "End date cannot be before start date", path: ["endDate"] }
);

This makes the refine a no-op when either date is absent, which is the correct behaviour for partial updates.

I resolved it. Thanks for the suggestion.

@Sachinchaurasiya360 Sachinchaurasiya360 merged commit 97a7129 into Sachinchaurasiya360:main Jun 5, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gssoc:approved Approved for GSSoC scoring gssoc level:beginner Good for first-time contributors quality:exceptional Exceptional implementation quality scope:backend Changes to server-side / API code type:bug Bug fixes type:testing Adds or improves tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: Validate Start and End Date Order for Hackathons

2 participants