Files

4.1 KiB

API Endpoint Testing Guide

Start the server first:

cd backend && uvicorn main:app --reload

NOTE: Run the following steps in order


1. Create a task

curl -s -X POST http://localhost:8000/tasks \
  -H "Content-Type: application/json" \
  -d '{"title": "Finish pset 3", "subject": "Math", "estimated_minutes": 90}' | python3 -m json.tool

Expect: 201 with the full task doc including _id, status: "pending", actual_minutes: []. Copy the _id value, it will be needed. Call it TASK_ID.


2. Create a second task

curl -s -X POST http://localhost:8000/tasks \
  -H "Content-Type: application/json" \
  -d '{"title": "Read chapter 4", "subject": "Biology", "estimated_minutes": 45}' | python3 -m json.tool

3. List tasks

curl -s http://localhost:8000/tasks | python3 -m json.tool

Expect: array with both tasks, neither with status: "done".


4. Update a task field

curl -s -X PATCH http://localhost:8000/tasks/TASK_ID \
  -H "Content-Type: application/json" \
  -d '{"estimated_minutes": 120}' | python3 -m json.tool

Expect: task returned with estimated_minutes: 120.


5. Complete a task

curl -s -X PATCH http://localhost:8000/tasks/TASK_ID/complete \
  -H "Content-Type: application/json" \
  -d '{"actual_minutes": 105}' | python3 -m json.tool

Expect: status: "done", actual_minutes: [105].


6. Confirm completed task is excluded from list

curl -s http://localhost:8000/tasks | python3 -m json.tool

Expect: only the Biology task remains (the completed Math one is filtered out).


7. Delete a task

curl -s -X DELETE http://localhost:8000/tasks/BIOLOGY_TASK_ID -o /dev/null -w "%{http_code}\n"

Expect: 204.


8. Confirm deletion

curl -s http://localhost:8000/tasks | python3 -m json.tool

Expect: empty array [].


9. Run the scheduler

Requires Google Calendar credentials in backend/token.json.

# First add a pending task so it has something to schedule
curl -s -X POST http://localhost:8000/tasks \
  -H "Content-Type: application/json" \
  -d '{"title": "Study for exam", "subject": "Chemistry", "estimated_minutes": 60}' | python3 -m json.tool

# Then run the scheduler
curl -s -X POST http://localhost:8000/schedule/run | python3 -m json.tool

Expect: {"free_blocks": [...], "assignments": {}} — free_blocks populated from your real calendar. assignments should be empty because it's still a stub.

Skipping real Google login while testing

To see what the scheduler would do without going through Google OAuth or touching a real calendar, run the backend with DEV_MODE=true and log in via the fake dev endpoint instead of /auth/google/login:

DEV_MODE=true uvicorn main:app --reload   # start the server with dev mode on

curl -s -c cookies.txt http://localhost:8000/auth/dev-login   # GET, follows the redirect just like the real callback

curl -s -b cookies.txt -X POST http://localhost:8000/schedule/run | python3 -m json.tool

This logs in as a fixed fake user with no Google account attached, so free_blocks is computed against an empty (fully free) calendar instead of a real one, and no real Google Calendar events are created — assignments still shows exactly where each task would have landed. /auth/dev-login returns 404 unless DEV_MODE=true is set, so it's never reachable in a real deployment.

With DEV_MODE=true set on the backend, the frontend also shows a "Dev Login" button next to "Sign in with Google" wherever that button appears — click it to log in as the fake dev user directly in the browser, no OAuth required.


Error cases

# Bad ID → 404
curl -s -X PATCH http://localhost:8000/tasks/000000000000000000000000 \
  -H "Content-Type: application/json" \
  -d '{"estimated_minutes": 10}' | python3 -m json.tool

# Empty update body → 400
curl -s -X PATCH http://localhost:8000/tasks/TASK_ID \
  -H "Content-Type: application/json" \
  -d '{}' | python3 -m json.tool

# No pending tasks → 400 from /schedule/run
curl -s -X POST http://localhost:8000/schedule/run | python3 -m json.tool