Testing Category Route API #45
Closed
manojtsx
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Here are all the routes of the category controller:
POST /api/category/add
- Add a category to the db• On sending the title, it shows a 'Category Successfully Added' message (200).
• If the user is not an admin or editor, it shows a 'Not authorized for this action.' message (401).
• If the title field is empty, it shows a 'Title is required.' message (400).
• If the title field is less than 3 characters, it shows an error indicating it must be at least 3 characters long (400).
• If the title field is more than 255 characters long, it shows an error indicating it must be at most 255 characters long (400).
• If the category already exisits then, it shows ‘Category already exists’ (400)
• Any other error occurs, it shows a server error (500).
PUT /api/category/edit/:id
- Edit the category• On successful update of the category, it shows the updated category with message ‘Updated Category Successfully’ (200).
• If the user is not an admin or editor, it shows a 'Not authorized for this action.' message (401).
• If a category with the same title already exists and is not the same category being edited, it shows a 'Category title already exists' message (400).
• If the category to be updated is not found, it shows a 'Category not found' message (404).
• If the title field is empty, it shows a 'Title is required.' message (400).
• If the title field is less than 3 characters, it shows an error indicating it must be at least 3 characters long (400).
• If the title field is more than 255 characters long, it shows an error indicating it must be at most 255 characters long (400).
• Any other error occurs, it shows a server error (500).
DELETE /api/category/delete/:id
- Delete the category• On successful deletion of the category, it shows a 'Category deleted successfully' message (200).
• If the user is not an admin or editor, it shows a 'Not authorized for this action.' message (401).
• If the category to be deleted is not found, it shows a 'Category not found' message (404).
• Any other error occurs, it shows a server error (500).
GET /api/category/:id
- Get the individual category by id• On successfully finding the category, it shows the category details (200).
• If the category is not found, it shows a 'Category not found' message (404).
• Any other error occurs, it shows a server error (500).
GET /api/category/
- Get all categories• On successfully finding all categories, it shows the list of categories (200).
• Any error occurs, it shows a server error (500).
Note: After calling every route API, don't forget to check changes in db too.
Beta Was this translation helpful? Give feedback.
All reactions