-
got to config
-
uncomment lines 5-7.
-
comment lines 9-11.
-
Start your local docker deamon.
-
Open new terminal.
-
docker-compose up --build.
open client application.
Admin Login Credentials for the application: {email: admin@gmail.com, password: 1234}
-
got to config
-
uncomment lines 9-11.
-
comment lines 5-7.
-
Open the terminal
-
cd server
-
npm install
-
node init.js
-
nodemon server.js
-
Open new terminal
-
cd client
-
npm install
-
npm start
open client application.
Admin Login Credentials for the application: {email: admin@gmail.com, password: 1234}
- Ask questions :- Admins and users who have logged in are allowed to post a question. Admins, guest users and regular users can view the question page and the answers associated with each question. ask-questions
- Provide answers :- Admins and users are allowed to answer questions.provide-answers
- Search for posts :- Users are allowed to search for posts based on username, keyword in the post or tags associated with posts. search-posts
- Tag posts :- Users can tag the post with the appropriate tags based on the question. tag-posts
- Comment on questions and answers :- Users can comment on questions and answers. comments
- Create individual user profiles :- Users have individual profile set up, which can be accessed on the Profile page. user-profiles
- Vote on questions, answers, and comments :- Users can upvote and downvote on questions, answers and comments. votes
- Authenticate registered users :- The application provides signup and login forms, and auntenticates each user. Guest users get direct login, but are restricted form certain functionalities.authenticate-users
- Moderate posts :- Admin has the ability to delete questions, answers and tags. moderate-posts
- Implemented MaterialUI to beautify the webpage.
- Test coverage of above 90% in jest and over 88% in cypress tests.
- Additional security features
- Added a URL Parsing Middleware to prevent MongoDB injections.
- Encoded the token cookies with SHA-256.
- Rate-linited the users to 100 requests per minute to prevent DDOS and DOS attacks.
- Restricted the input size to 1 KB to prevent server overloading attacks.
- Secured endpoint with type checking.
- Guest User with restricted access.
- Allow search on tag page.
- Search page for users.
- Edit profile and update password feature for users.
End-Points-Related-Tests
User-Related Functions
-
Verify Users: verify-user tests
- Confirms user authentication with correct passwords.
- Returns an error for incorrect passwords.
- Handles user authentication failures due to no matching credentials.
- Manages exceptions during user authentication due to internal server errors.
-
Logout: logout tests
- Effectively logs out users by invalidating tokens.
-
Add User: addUser tests
- Successfully registers new users into the system.
- Checks for email uniqueness to prevent duplicate registrations.
- Validates email formats and password strength to ensure data integrity.
- Handles registration failures gracefully with appropriate error messages.
-
Login as Guest: loginAsGuest tests
- Facilitates guest user logins.
- Ensures only valid guest credentials are accepted.
- Provides clear feedback for login errors, including incorrect passwords and internal server issues.
-
Update Profile: updateProfile tests
- Allows users to successfully update their profiles.
- Requires authentication token for profile updates.
- Validates the correctness of the old password for security.
-
Get My User Details: getMyUserDetails tests
- Retrieves authenticated user details.
- Ensures that user details retrieval is secured with authentication.
- Suggests the need for additional testing in areas such as password correctness and user existence.
-
Get User Details: getUserDetails tests
- Provides detailed user information upon successful authentication.
- Manages not found errors when user IDs do not exist in the database.
-
Get Users By Username: getUsersByUsername tests
- Searches and retrieves user lists based on username queries.
- Handles errors effectively when user retrieval processes fail.
Tag-Related Functions
-
Get Tags With Question Number: getTagsWithQuestionNumber tests
- Retrieves tags along with associated question counts based on queries.
- Indicates the need for additional tests for robust error handling and authentication checks.
-
Update Tag Description: updateTagDescription tests
- Permits only administrators to update tag descriptions.
- Validates the presence of necessary parameters for tag updates.
- Ensures tag existence before permitting updates.
-
Delete Tag: deleteTag tests
- Allows tag deletion by administrators.
- Secures the tag deletion process against unauthorized user actions.
- Confirms tag existence prior to deletion, handling not found errors appropriately.
ANSWER- RELATED FUNCTION
-
Add Answer: addAnswer tests
- Successfully adds a new answer to a question when valid data is provided.
- Fails to add an answer and returns an error when incorrect input is provided.
-
Upvote Answer: upvoteAnswer tests
- Successfully adds an upvote to an answer when no previous upvote exists.
- Returns an error when the user is a guest and attempts to upvote.
- Returns an error when the answer does not exist.
-
Downvote Answer: downvoteAnswer tests
- Successfully adds a downvote to an answer when no previous downvote exists.
- Returns an error when the user is a guest and attempts to downvote.
- Returns an error when the answer does not exist.
-
Get Answer By ID: getAnswerById tests
- Successfully retrieves an answer when it exists.
- Returns an error when the answer does not exist.
-
Delete Answer: deleteAnswer tests
- Allows deletion of an answer by the user who posted it or by a moderator.
- Returns an error when the answer does not exist.
- Prevents deletion by users who are neither the original poster nor a moderator.
-
Get All Answers By UID: getAllAnswersByUid tests
- Returns all answers posted by a specific user when user ID is valid.
- Returns an empty array when the user ID is invalid or when no answers are found.
QUESTION- RELATED FUNCTION
-
Get Question: getQuestion tests
- Returns questions based on filter and order.
- Checks authorization and query parameter handling.
-
Get Question By ID: getQuestionById tests
- Successfully retrieves question details for a specific ID.
- Returns error when parameters are incorrect or the question ID does not exist.
-
Add Question: addQuestion tests
- Successfully adds a question when all parameters are correct.
- Returns status code 401 when a guest account tries to add a question.
- Returns status code 400 for missing or invalid question parameters.
-
Downvote Question: downvoteQuestion tests
- Successfully downvotes a question if the question exists.
- Returns an error if the question does not exist or if the user is a guest.
-
Delete Question: deleteQuestion tests
- Allows question deletion by the original poster or a moderator.
- Returns an error for unauthorized user or if the question does not exist.
-
Upvote Question: upvoteQuestion tests
- Successfully upvotes a question if the question exists.
- Returns an error if the question does not exist or if the user is a guest.
COMMENT- RELATED FUNCTION
-
Add Comment to Answer: addCommentToAnswer tests
- Successfully adds a comment to an answer when all parameters are correct.
- Displays an error when the user is a guest and attempts to add a comment.
- Throws an error when the user is not found.
-
Add Comment to Question: addCommentToQuestion tests
- Successfully adds a comment to a question when all parameters are correct.
- Displays an error when the user is a guest.
- Throws an error when the user is not found.
-
Downvote Comment: downvoteComment tests
- Successfully downvotes a comment when all parameters are correct.
- Returns an error when the comment does not exist.
- Prevents a guest from downvoting a comment.
-
Upvote Comment: upvoteComment tests
- Successfully upvotes a comment that hasn't been upvoted by the user.
- Returns an error when attempting to upvote a comment that has already been upvoted by the user.
- Returns an error when the comment does not exist or if the user is a guest.
-
Delete Comment: deleteComment tests
- Successfully deletes a comment when the user has permission.
- Returns an error when the comment is not found or when the user does not have permission to delete.
- Handles internal server errors effectively.
ADDITIONAL TESTS FOR MIDDLEWARE BEING USED.
- Token Validation and User Retrieval: getUserFromToken tests
- Sets
req.usercorrectly when a valid token is provided, verifying the token and retrieving user details. - Returns status code 401 if no token is provided, indicating the user is unauthorized due to missing token.
- Returns status code 401 if the token is invalid, either due to tampering or expiration, ensuring security.
- Returns status code 404 if no user corresponds to the decoded token, handling cases where the token's user might have been deleted or is invalid.
- Handles other errors by returning status code 500, covering unexpected issues like database failures or token parsing errors.
- Sets
ADDITIONAL TESTS FOR HELPER METHODS BEING USED.
-
User Authentication: getUserFromToken tests
- Returns the user when the token is valid and the user exists in the database.
- Throws an error when the token is invalid, ensuring security protocols are enforced.
- Throws an error when the token is expired, managing access control effectively.
- Handles internal server errors during the authentication process.
-
Tag Management: addTag tests
- Creates a new tag if it does not already exist, expanding the database of tags.
- Returns the ID of an existing tag when it is found in the database, avoiding duplicates.
- Handles errors during tag creation, ensuring robustness in tag management.
-
Question Ordering: getQuestionsByOrder tests
- Fetches questions ordered by newest, supporting timely content delivery.
- Fetches questions ordered by active status, highlighting ongoing discussions.
- Fetches questions with no answers, facilitating engagement on unresolved queries.
- Handles errors during question retrieval, maintaining system stability.
-
Question Filtering: filterQuestionsBySearch tests
- Filters questions based on tags, facilitating topic-specific searches.
- Filters questions based on keywords, enhancing content relevancy.
- Filters questions by username, personalizing user experience.
- Combines multiple search parameters (tags, keywords, username) for comprehensive filtering.
- Returns all questions when no search parameters are provided, ensuring complete data accessibility.
In Both cases before running tests for test coverage locally.
- got to config
- uncomment lines 9-11.
- comment lines 5-7.
Instuctions for Frontend Test Coverage
-
Open the terminal
-
cd server
-
npm install
-
nodemon server.js
-
Open new terminal
-
cd client
-
npm install
-
npm start
-
Open new Terminal
-
cd testing
-
npm install
-
npx cypress run
A coverage folder gets created in the testing folder. You can see an Icov-report/index.html, which can be opened on a web-browser to see the coverage.
Instuctions for Backend Test Coverage
- Open the terminal
- cd server
- npm install
- jest -w=1 --coverage --detectOpenHandles
This should give coverge of around 90.32% of functions, and 87.03% of lines in the server. server.js has calls to third party middleware which restricts testing to only 68.51% of the lines.