This repository contains a test suite for the Task Manager API. The tests are written in JavaScript using Jest framework.
Before running the tests, ensure you have the following installed:
- Node.js (at least version 12 or higher)
- npm (Node Package Manager)
Follow these steps to set up and run the tests:
-
Clone this repository to your local machine:
git clone <repository_url>
-
Navigate to the project directory:
cd task-manager-api-tests -
Install dependencies:
npm install
Before running the tests, you need to obtain a valid cookie. Follow these instructions to acquire it:
Note: The cookie must be obtained by authenticating through the /api/v1/auth/google endpoint of the API. There are 4 different APIs set up to get the cookie and test. They are found at the following URLs:
s1: https://s1.cf-itc210.net s2: https://s2.cf-itc210.net s3: https://s3.cf-itc210.net s4: https://s4.cf-itc210.net
- Navigate to the the API in your browser.
- Authenticate using the Google authentication method.
- Once authenticated, inspect the cookies associated with the session. Right click > Inspect Element > Application > Storage > Cookies > it210_session
- Look for a cookie named
it210_session. - Copy the value of this cookie (a long string of random characters).
To configure the tests to use the obtained cookie, you need to modify the api.js file. Locate the cookie variable declaration and paste the copied cookie value as its assigned string.
const cookie = 'YOUR_COPIED_COOKIE_VALUE';After configuring the cookie, you can run the tests using the following command:
npm test-
CREATE Test:
- Purpose: Tests the functionality to create a new task through the API.
- Steps:
- Generates random text and a random date for the task.
- Calls the
createTaskmethod of the API with the generated text and date. - Verifies that the response is successful (HTTP status 200).
- Checks if the created task matches the provided text and date.
- Cleans up by deleting the created task.
-
READ ONE Test:
- Purpose: Tests the functionality to read a single task by its ID.
- Steps:
- Creates a new task.
- Reads the created task using its ID.
- Verifies that the response is successful (HTTP status 200).
- Checks if the retrieved task matches the created task.
-
READ ALL Test:
- Purpose: Tests the functionality to retrieve all tasks.
- Steps:
- Creates a new task.
- Retrieves all tasks.
- Verifies that the response is successful (HTTP status 200).
- Checks if all retrieved tasks belong to the same user as the created task.
-
UPDATE Test:
- Purpose: Tests the functionality to update the status of a task.
- Steps:
- Creates a new task.
- Updates the status of the created task.
- Verifies that the response is successful (HTTP status 200).
-
DELETE Test:
- Purpose: Tests the functionality to delete a task.
- Steps:
- Creates a new task.
- Deletes the created task.
- Verifies that the response is successful (HTTP status 200).
- Attempts to read the deleted task again to ensure it's not retrievable (should return HTTP status 404).
-
READ USER Test:
- Purpose: Tests the functionality to retrieve information about the current user.
- Steps:
- Retrieves information about the current user.
- Verifies that the response is successful (HTTP status 200).
- Checks if the retrieved user object contains essential properties like Id, UserName, and Email.
-
READ ONE NONEXISTENT Test:
- Purpose: Tests the behavior when attempting to read a task that doesn't exist.
- Steps:
- Calls the
readTaskmethod of the API with a fake task ID. - Verifies that the response status is 404 (Not Found).
- Calls the
-
DELETE NONEXISTENT Test:
- Purpose: Tests the behavior when attempting to delete a task that doesn't exist.
- Steps:
- Calls the
deleteTaskmethod of the API with a fake task ID. - Verifies that the response status is 404 (Not Found).
- Calls the
-
UPDATE NONEXISTENT Test:
- Purpose: Tests the behavior when attempting to update a task that doesn't exist.
- Steps:
- Calls the
updateTaskmethod of the API with a fake task ID. - Verifies that the response status is 404 (Not Found).
- Calls the
-
DELETE INVALID ID Test:
- Purpose: Tests the behavior when attempting to delete a task with an invalid ID format.
- Steps:
- Calls the
deleteTaskmethod of the API with an invalid task ID. - Verifies that the response status is 500 (Internal Server Error).
- Calls the
-
READ ALL NO COOKIE Test:
- Purpose: Tests the behavior when attempting to retrieve all tasks without providing a cookie.
- Steps:
- Calls the
readAllTasksmethod of the API without providing a cookie. - Verifies that the response status is 401 (Unauthorized).
- Calls the
-
CREATE NOT ENOUGH DATA PROVIDED Test:
- Purpose: Tests the behavior when attempting to create a task without providing enough data.
- Steps:
- Calls the
createTaskmethod of the API with empty text and date. - Verifies that the response status is 500 (Internal Server Error).
- Calls the
These tests cover various scenarios to ensure the functionality of the Task Manager API is working as expected under different conditions.