Skip to content

Add input validation to POST /tasks - #12

Merged
aj-enns merged 1 commit into
mainfrom
aj-enns-add-post-tasks-validation
Jun 26, 2026
Merged

Add input validation to POST /tasks#12
aj-enns merged 1 commit into
mainfrom
aj-enns-add-post-tasks-validation

Conversation

@aj-enns

@aj-enns aj-enns commented Jun 26, 2026

Copy link
Copy Markdown
Owner

Why

POST /tasks previously created a task even when title was missing or blank, allowing empty/garbage records into the store. This adds proper input validation so invalid requests are rejected up front.

What changed

  • sample-app/src/tasks/routes.ts — the POST / handler now validates title before calling store.create. A missing, non-string, or whitespace-only title returns HTTP 400 with { error: "title is required and must be a non-empty string" } and no task is created.
  • sample-app/src/app.test.ts — added three tests covering the invalid cases (missing, non-string, whitespace-only title), each asserting a 400 response and that the store stays empty. The existing happy-path test is unchanged.

Verification

  • npm test -> 11 passed (was 8)
  • npm run build -> clean type-check

Fixes: #1

Reject a missing, non-string, or whitespace-only title with HTTP 400 and a clear JSON error instead of creating an invalid task. Add tests covering the invalid cases and that no task is created.

Fixes: #1

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@aj-enns
aj-enns merged commit feea8d8 into main Jun 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add input validation to POST /tasks

1 participant