Repository navigation
Testing
Enes Duman edited this page Dec 20, 2024
·
1 revision
I have tested functionality of my web app using Postman requests to localhost. Here is a feature table for those tests:
| API Feature | Endpoint | Request Type | Request Parameters | Expected Response | Test Cases |
|---|---|---|---|---|---|
| User Signup | /api/users/signup |
POST |
{ "username": "testUser", "email": "test@example.com", "password": "password123" } |
200 OK with { "message": "User registered successfully", "userId": "<UUID>" }. 400 Bad Request for duplicate username/email. |
- Create a new user and verify response. - Use duplicate email/username and verify it fails. |
| User Login | /api/users/login |
POST |
{ "username": "testUser", "password": "password123" } |
200 OK with { "token": "<JWT>", "id": "<userId>", "username": "testUser" }. 401 Unauthorized for invalid credentials. |
- Login with valid credentials and verify token in response. - Login with invalid credentials and verify error response. |
| Get All Users | /api/users |
GET |
None |
200 OK with list of users in EntityModel. |
- Verify all users are retrieved. |
| Get User by ID | /api/users/{id} |
GET |
{id} |
200 OK with user details in EntityModel. 404 Not Found if user does not exist. |
- Fetch a valid user by ID and verify the response. - Try an invalid ID and check for 404 error. |
| Update User Details | /api/users/{id} |
PUT |
{ "username": "newName", "email": "new@example.com" } |
200 OK with updated user details. | - Update user details and verify they are saved. - Test with an invalid ID and check for 404 error. |
| Delete User | /api/users/{id} |
DELETE |
{id} |
204 No Content on success. 404 Not Found if user does not exist. |
- Delete an existing user and verify response. - Attempt to delete an invalid user and check for error. |
| Upload Profile Picture | /api/users/{id}/profile-picture |
POST |
MultipartFile (image) |
200 OK with { "profilePictureUrl": "<URL>", "message": "Profile updated successfully" }. 400 Bad Request for invalid file format. |
- Upload a valid image and verify URL is returned. - Attempt with an unsupported file and check for error. |
| View Profile Picture | /uploads/{fileName} |
GET |
{fileName} |
200 OK with file content (inline). 404 Not Found if file does not exist. |
- Access a valid file and ensure it loads correctly. - Try to access a non-existent file and verify the 404 response. |
| CORS Configuration Testing | Any API endpoint | Varies | Test with different origins. | Requests from allowed origins are processed, others return 403 Forbidden. | - Send requests from an allowed origin and verify success. - Send requests from an unallowed origin and verify CORS rejection. |
| API Feature | Endpoint | Request Type | Request Parameters | Expected Response | Test Cases |
|---|---|---|---|---|---|
| Get All Posts | /api/posts |
GET |
None | 200 OK with paginated posts list. | - Fetch the paginated list of posts. - Verify pagination and sorting (e.g., newest, most voted). |
| Get Post by ID | /api/posts/{id} |
GET |
{id} |
200 OK with post details. 404 Not Found if post does not exist. |
- Fetch a post by a valid ID and verify response. - Try an invalid ID and check for a 404 error. |
| Create New Post | /api/posts |
POST |
{ "title": "Test", "description": "Details", "tags": ["tag1", "tag2"], "userId": 1 } |
201 Created with created post details. | - Create a new post and verify response. - Ensure the post is listed in /api/posts. |
| Update Existing Post | /api/posts/{id} |
PUT |
{id} and updated post data |
200 OK with updated post details. 404 Not Found if post does not exist. |
- Update an existing post and verify the response. - Try updating a non-existent post and check for a 404 error. |
| Get Comments for Post | /api/posts/{postId}/comments |
GET |
{postId} |
200 OK with list of comments. | - Fetch comments for a valid post and verify response. - Try a post without comments and verify empty response. |
| Get Tag Suggestions | /api/posts/tags |
GET |
query parameter |
200 OK with a list of tag suggestions. | - Search tags with a query and verify results. - Use an invalid or empty query and verify the response. |
| Upvote Post | /api/posts/{id}/upvote |
POST |
{ "userId": 1 } |
200 OK with updated post details. 400 Bad Request for invalid data. |
- Upvote a post and verify votes increment. - Attempt multiple upvotes by the same user and ensure no duplicate votes. |
| Downvote Post | /api/posts/{id}/downvote |
POST |
{ "userId": 1 } |
200 OK with updated post details. 400 Bad Request for invalid data. |
- Downvote a post and verify votes decrement. - Test multiple downvotes by the same user and ensure no duplicate votes. |
| Get Posts by User | /api/posts/user/{userId} |
GET |
{userId} |
200 OK with list of posts created by the user. | - Fetch posts for a valid user and verify response. - Attempt with an invalid user ID and check for appropriate error response. |
| Mark as Solution | /api/posts/{postId}/solution/{commentId} |
POST |
{postId}, {commentId}
|
200 OK with updated post details. 403 Forbidden if unauthorized. 404 Not Found for invalid post/comment. |
- Mark a valid comment as the solution and verify the post updates. - Test unauthorized and invalid scenarios. |
| Check User Vote | /api/posts/{postId}/vote/{userId} |
GET |
{postId}, {userId}
|
200 OK with vote type (upvote, downvote, or ""). |
- Check vote status for a user and verify response. |
| Search Posts | /api/posts/search |
GET |
query parameters |
200 OK with list of posts matching search criteria. | - Perform a search with valid criteria and verify results. - Use invalid or empty search parameters and check for no results. |
| Get Paginated Posts | /api/posts/paginated |
GET |
page, size, and sort parameters |
200 OK with paginated post data. | - Fetch paginated posts with various sort options (e.g., newest, solved, unsolved). |
| API Feature | Endpoint | Request Type | Request Parameters | Expected Response | Test Cases |
|---|---|---|---|---|---|
| Create New Comment | /api/comments |
POST |
{ "postId": 1, "userId": 1, "text": "Comment text" } |
201 Created with created comment details. | - Create a comment on an existing post and verify response. - Attempt to create a comment on a non-existent post and check for appropriate errors. |
| Get Comment by ID | /api/comments/{id} |
GET |
{id} |
200 OK with comment details. 404 Not Found if comment does not exist. |
- Fetch a valid comment and verify response. - Attempt with an invalid ID and check for a 404 error. |
| Get Comments by Post | /api/comments/posts/{postId}/comments |
GET |
{postId} |
200 OK with list of comments for the post. | - Fetch comments for a post and verify the response. - Attempt with an invalid post ID and check for appropriate errors. |
| Delete Comment | /api/comments/{id} |
DELETE |
{id} |
204 No Content on successful deletion. 404 Not Found if comment does not exist. |
- Delete a valid comment and verify the response. - Attempt to delete a non-existent comment and check for a 404 error. |
| Upvote Comment | /api/comments/{id}/upvote |
POST |
{id} |
200 OK with updated comment details. 400 Bad Request if comment cannot be upvoted. |
- Upvote a comment and verify votes increment. - Ensure that multiple upvotes by the same user are not allowed. |
| Downvote Comment | /api/comments/{id}/downvote |
POST |
{id} |
200 OK with updated comment details. 400 Bad Request if comment cannot be downvoted. |
- Downvote a comment and verify votes decrement. - Test multiple downvotes by the same user and ensure no duplicate votes. |
| Get Comments by User | /api/comments/user/{userId} |
GET |
{userId} |
200 OK with list of comments by the user. | - Fetch comments made by a specific user and verify response. - Attempt with an invalid user ID and check for appropriate errors. |