Repository navigation
test: add category API route tests - #34
Merged
Merged
Conversation
Add GET/POST /api/categories and PATCH/DELETE /api/categories/[id], backed by a category store selected with TASK_STORE (shared with tasks so both always use the same backend). Store results map to HTTP statuses in the routes: name-taken → 409, not-found → 404, invalid input → 400. Rename failures use an exhaustive switch so a new failure reason won't compile until handled. Also mark lib/firestore.ts server-only.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Puts the category store behind HTTP (Phase 3, step 4). Requests are validated with the category Zod schemas at the boundary. The store's results become HTTP status codes in the routes, so the store stays free of HTTP.
GET /api/categoriesPOST /api/categoriesPATCH /api/categories/[id]DELETE /api/categories/[id]Error bodies use the same
{ error }shape as the task routes, and validation errors also listissues.Notes
lib/categories/store.tspicks the memory or Firestore store fromTASK_STORE, the same variable as tasks. A shared variable means tasks and categories can't end up on different backends. Deleting a category will later move its tasks in one Firestore transaction, which needs both in the same database.PATCHswitches on the failure reason, with anevercheck indefault. If the store gains a new failure reason, this route won't compile until it handles it.server-only:lib/firestore.ts(the Firestore SDK helpers) is now markedserver-only, like the stores.Testing
Not in this PR
categoryIdon tasks (step 5), the category UI (step 6), and moving a deleted category's tasks to Uncategorised (step 8).