cognovi-ai / the-cdj

The Cognitive Distortion Journal (CDJ) is a smart journaling tool that helps remedy distorted thinking. It can feel impossible to follow the CBT technique of labeling and reframing distorted thinking when you've been thinking this way your whole life. The CDJ can help with that 🧠✨ -- v2 is in development!
https://thecdj.app
3 stars 0 forks source link

Issue testing API with passport middleware #16

Open hiyaryan opened 11 months ago

hiyaryan commented 11 months ago

There are some issues around testing the API and passport. Currently determining if the issue is due to a bug in the controller and middleware code or in the setup of the tests itself. It seemingly is due to the test setup. Working through this issue with ChatGPT in two conversations.

CDJ Troubleshoot Test Setup Issues CDJ TDD

Some things to look into is how passport is being used in the controllers and middleware. Incorrect usage may be causing these errors. Another thing is that passport may be trying to use the development test base which is not active in a testing environment (the test version of the database is) to authenticate/authorize a user so another passport strategy may be required to be setup.

Tests are being made to replicate the following curl commands that were used to manually test the API that verifies the the endpoints are working as expected. See API docs in backend for more details.

Testing Entries API

  1. Attempt to Retrieve All Journal Entries
curl -X GET http://localhost:3000/journals/65619e89bba77f3e6cff9580/entries

Attempts to retrieve all entries from the specified journal without authentication.

  1. Attempt to Add a New Journal Entry
curl -X POST http://localhost:3000/journals/65619e89bba77f3e6cff9580/entries \
-H "Content-Type: application/json" \
-d '{"title": "Test Entry", "content": "This is a test entry."}'

Tries to add a new entry to the specified journal without authentication.

  1. Attempt to Retrieve a Specific Journal Entry
curl -X GET http://localhost:3000/journals/65619e89bba77f3e6cff9580/entries/65619e89bba77f3e6cff9582

Attempts to retrieve the specified journal entry without authentication.

  1. Attempt to Update a Journal Entry
    curl -X PUT http://localhost:3000/journals/65619e89bba77f3e6cff9580/entries/65619e89bba77f3e6cff9582 \
    -H "Content-Type: application/json" \
    -d '{"title": "Updated Title", "content": "Updated content."}'

Tries to update the specified journal entry without authentication.

  1. Attempt to Delete a Journal Entry
    curl -X DELETE http://localhost:3000/journals/65619e89bba77f3e6cff9580/entries/65619e89bba77f3e6cff9582

    Attempts to delete the specified journal entry without authentication.

Testing Access API

  1. Valid User Registration
    curl -X POST http://192.168.50.157:3000/access/register \
    -H "Content-Type: application/json" \
    -d '{"fname": "Alice", "lname": "Johnson", "email": "alicej92@berkeley.edu", "password": "gobears!2014"}'

Registers a new user with valid credentials.

  1. Valid User Login
    curl -X POST http://192.168.50.157:3000/access/login \
    -H "Content-Type: application/json" \
    -d '{"email": "alicej92@berkeley.edu", "password": "gobears!2014"}'

Attempts to log in with valid credentials.

  1. Invalid User Login (Incorrect Password)
curl -X POST http://192.168.50.157:3000/access/login \
-H "Content-Type: application/json" \
-d '{"email": "alicej92@berkeley.edu", "password": "wrongpassword"}'

Attempts to log in with a valid email but incorrect password.

  1. Invalid User Login (Incorrect Email)
curl -X POST http://192.168.50.157:3000/access/login \
-H "Content-Type: application/json" \
-d '{"email": "wrongemail@berkeley.edu", "password": "gobears!2014"}'

Attempts to log in with an incorrect email and valid password.

  1. Valid User Logout
    curl -X GET http://192.168.50.157:3000/access/logout

Logs out the currently authenticated user.

  1. Invalid User Registration (Existing Email)
    curl -X POST http://192.168.50.157:3000/access/register \
    -H "Content-Type: application/json" \
    -d '{"fname": "Alice", "lname": "Johnson", "email": "alicej92@berkeley.edu", "password": "gobears!2014"}'

Attempts to register a user with an already existing email.

  1. Attempt Logout When Not Logged In
    curl -X GET http://192.168.50.157:3000/access/logout

    Attempts to log out when no user is logged in.