# Testspecifikation [TOC] ## Teststrategi ### Beskrivning Eftersom projektet främst kommer bestå utav en API kommer en stor mängd utav testing ske i form av enhetstester med verktyget Postman. Med verktyget kommer vi testa att API:ets olika endpoints skickar tillbaka förväntat data, HTTP status koder, samt bekräfta att felhantering fungerar när felaktig data skickas med till vårat API. Vi kommer även att skapa automatiska enhetstester med verktyget Jest för att testa våran kod. Testerna kommer att bekräfta att våran kod fungerar och ge oss mer trygghet i våran kod. Där vi inte kommer att kunna skapa automatiska tester så kommer vi att utföra manuella tester samt köra exploratory testing. ### Verktyg - [Postman - API-test](https://www.postman.com/) ### Tillvägagångssätt 1. Någon i gruppen blir tilldelad ett delkrav 2. Personen i fråga implementerar delkravet 3. Delkravet testas med hjälp av Postman (om det är en del av APIet) 4. Delkravet testas mot de tester som skapas 5. Refaktorera tills kravet är uppfyllt/testat ### Lokalisera buggar - Automatisk testning - Manuella tester - Automatiska Postman-tester - Kodgranskning ### Testansvarig 1. Testansvarig 2. Testförfattare 3. Kodgranskare ## Test Case Mall ### TCX.X Test_Case_Title Use Case: UCX Use_Case_Title | optional ? #### Description [Should include: What are we testing and Why. Technical words should also be described?] #### Precondition [Here we should describe what needs to be prepared for the test to able to be run] [Could be multiple steps] #### Scenario [Describe how we know that the scenario of the use case is tested] #### Input [Well described instructions that describe how to perform the test] [Could be multiple steps] [The user performing the test should not be able to misinterpret the input steps] #### Output [Description that describes how the output of the test should look when the test is successful or the test has “Passed”. Could be a text description or an image or a combination.] ## Test Case Example ### TC4.2 Answer To Life Use Case: UC4.2 Finding out the answer to life #### Description Making sure that Google can give us the answer to life. We are doing this to be sure that Google will provide the correct answer to life. #### Precondition The user has a stable internet connection The user has opened a web browser #### Scenario The main scenario of UC4.2 is tested when we find out the correct answer to life. #### Input - By using your keyboard, enter the address www.google.com in the web browser’s address bar and press the enter key. - By using your mouse or touchpad, select the search area that is located under the text that says “Google” - By using your keyboard, enter the text “answer to life the universe and everything” in the selected search area and press the enter key. #### Output ## Postman Test Case 1. ### PTC1.1 Register user success Requirement: Req-1 User should be able to create an account with an email and password #### Description A registration of a user is being tested with a valid email and password. #### Precondition The service needs to be up and running. #### Scenario A user attempts to register by sending an unused email and a valid password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3@hotmail.com". - Body contains a JSON object where "password" is set to "securepassword1". - Run test. #### Output ```javascript 201 Created ``` ```json { "message": "User created" } ``` ### PTC1.2 Register already existing email Requirement: Req-1 #### Description A registration of a user is being tested with an already existing email. #### Precondition The service needs to be up and running. #### Scenario A user attempts to register by sending a used email and a valid password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3@hotmail.com". - Body contains a JSON object where "password" is set to "securepassword1". - Run test. #### Output ```javascript 409 Conflict ``` ```json { "name": "ConflictError", "status": 409, "message": { "detail": "This email is already registered.", "email": "ravenraskar3@hotmail.com" } } ``` ### PTC1.3 Register missing email Requirement: Req-1 #### Description A registration of a user is being tested without an email entered. #### Precondition The service needs to be up and running. #### Scenario A user attempts to register by sending a valid password but no email. #### Input - Body contains a JSON object where "password" is set to "securepassword1". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Please provide an email" } } ``` ### PTC1.4 Register missing password Requirement: Req-1 #### Description A registration of a user is being tested without a password. #### Precondition The service needs to be up and running. #### Scenario A user attempts to register by sending a valid email but no password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3@hotmail.com". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Please provide a password" } } ``` ### PTC1.5 Register invalid email Requirement: Req-1 #### Description A registration of a user is being tested with an invalid email. #### Precondition The service needs to be up and running. #### Scenario A user attempts to register by sending an invalid email and a valid password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3!hotmail.com". - Body contains a JSON object where "password" is set to "securepassword1". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "User validation failed: email: ravenraskar3!hotmail.com is not a valid email address.", "email": "ravenraskar3!hotmail.com" } } ``` ### PTC1.6 Register too short password Requirement: Req-1 #### Description A registration of a user is being tested with a too short password. #### Precondition The service needs to be up and running. #### Scenario A user attempts to register by sending an unused email and a valid password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3@hotmail.com". - Body contains a JSON object where "password" is set to "secure". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "User validation failed: password: The password must be of minimum length 10 characters." } } ``` ## Postman Test Case 3. ### PTC3.1 Login user success Requirement: Req-3 #### Description A user logs in successfully #### Precondition The service needs to be up and running. The user must be registered. #### Scenario A user attempts to login by sending an valid email and a valid password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3@hotmail.com". - Body contains a JSON object where "password" is set to "securepassword1". - Run test. #### Output ```javascript 200 OK ``` ```json { "token": "<exampleJWT>" } ``` ### PTC3.2 Login user wrong password Requirement: Req-3 #### Description A user submits the wrong password #### Precondition The service needs to be up and running. The user must be registered. #### Scenario A user attempts to login by sending an valid email and an invalid password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3@hotmail.com". - Body contains a JSON object where "password" is set to "on7iyuh23cr98pby23498i7oyb". - Run test. #### Output ```javascript 401 Unauthorized ``` ```json { "name": "UnauthorizedError", "status": 401, "message": { "detail": "Invalid email or password" } } ``` ### PTC3.3 Login user wrong email Requirement: Req-3 #### Description A user submits the wrong email #### Precondition The service needs to be up and running. The user must be registered. #### Scenario A user attempts to login by sending an invalid email and a valid password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3!hotmail.com". - Body contains a JSON object where "password" is set to "securepassword1". - Run test. #### Output ```javascript 401 Unauthorized ``` ```json { "name": "UnauthorizedError", "status": 401, "message": { "detail": "Invalid email or password" } } ``` ### PTC3.4 Login user missing email Requirement: Req-3 #### Description A user does not submit an email #### Precondition The service needs to be up and running. The user must be registered. #### Scenario A user attempts to login by sending a valid password and no email. #### Input - Body contains a JSON object where "password" is set to "securepassword1". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Email needs to be provided" } } ``` ### PTC3.5 Login user missing password Requirement: Req-3 #### Description A user does not submit a password #### Precondition The service needs to be up and running. The user must be registered. #### Scenario A user attempts to login by sending a valid email and no password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3@hotmail.com". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Password needs to be provided" } } ``` ### PTC3.6 Login user missing email and password Requirement: Req-3 #### Description A user does not submit an email or a password #### Precondition The service needs to be up and running. The user must be registered. #### Scenario A user attempts to login by not sending either email or password. #### Input - Body contains a JSON object where "email" is set to "ravenraskar3@hotmail.com". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Email needs to be provided" } } ``` ### PTC3.7 Logged in user should be authenticated Requirement: Req-3 #### Description The correct user is authenticated by verifying the token #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario The user sends an a valid token to authenticate themselves #### Input - Request contains the JWT - Run test. #### Output ```javascript 200 OK ``` ```json { "authenticatedUser": "ravenraskar3@hotmail.com" } ``` ## Postman Test Case 5. ### PTC5.1 Add web page success Requirement: Req-5 #### Description Adding a web page with a valid address. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to add a web page with a valid address. #### Input - Body contains the JSON object "address" which is set to "http://hitta.se". - - Body contains the JSON object "testInterval" which is set to "Daily". - Run test. #### Output ```javascript 201 Created ``` ```json { "page": { "_id": "<exampleID>", "address": "http://hitta.se/", "domain": "hitta.se", "path": "/", "createdAt": "2021-06-02T07:30:52.915Z" }, "measureAt": "Daily" } ``` ### PTC5.2 Add already existing web page Requirement: Req-5 #### Description Adding an already existing web. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to add an already added web page. #### Input - Body contains the JSON object "address" which is set to "http://hitta.se". - Body contains the JSON object "testInterval" which is set to "Daily". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Page already added" } } ``` ### PTC5.3 Add web page invalid address Requirement: Req-5 #### Description Trying to add a web page with an invalid address. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to add a web page with a invalid address. #### Input - Body contains the JSON object "address" which is set to "google.se". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "google.se is not a valid URL", "address": "google.se" } } ``` ### PTC5.4 Add web page invalid test interval Requirement: Req-5 #### Description Trying to add a web page with an invalid testInterval. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to add a web page with a invalid testInterval. #### Input - Body contains the JSON object "address" which is set to "http://hitta.se". - - Body contains the JSON object "testInterval" which is set to "Baily". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Baily is not a valid testInterval.", "testInterval": "Baily" } } ``` ### PTC5.5 Add web page missing address Requirement: Req-5 #### Description Trying to add a web page without an address. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to add a web page without an address. #### Input - Body contains the JSON object "testInterval" which is set to "Daily". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Required parameter is missing.", "parameter": "address" } } ``` ### PTC5.6 Add web page missing testInterval Requirement: Req-5 #### Description Trying to add a web page without a testInterval. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to add a web page without a testInterval. #### Input - Body contains the JSON object "address" which is set to "http://hitta.se". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Required parameter is missing.", "parameter": "testInterval" } } ``` ## Postman Test Case 6 ### PTC6.1 Update registered web page success Requirement: REQ-6 #### Description A user successfully updates a registered web page. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to update a registered web page by using the PUT /pages/:id endpoint with a new url. #### Input - PUT request containing the id of the registered web page in [PTC2.1 Add web page success](#PTC2.1-Add-web-page-success). - Body contains a JSON object where "address" is set to "https://eniro.se". ```javascript PUT pages/:id ``` #### Output ```javascript 204 No Content ``` ### PTC6.2 Update registered web page missing address Requirement: REQ-6 #### Description A user fails at updating a registered web page. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to update a registered web page by using the PUT /pages/:id endpoint while missing the "address" in the body. #### Input - PUT request containing the id of the registered web page in [PTC2.1 Add web page success](#PTC2.1-Add-web-page-success). ```javascript PUT /pages/:id ``` #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Required parameter is missing.", "parameter": "address" } } ``` ### PTC6.3 Update registered web page bad id Requirement: REQ-6 #### Description A user failes at updating a registered web page. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to update a registered web page by using the PUT /pages/:id endpoint while using a invalid id. #### Input - PUT request where id is invalid. - Body is empty ```javascript PUT /pages/bad-id ``` #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Required parameter is not a valid page ID.", "parameter": "id" } } ``` ### PTC6.4 Update registered web page invalid address Requirement: REQ-6 #### Description A user failes at updating a registered web page. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to update a registered web page by using the PUT /pages/:id endpoint while using a invalid address. #### Input - PUT request where id is invalid. - Body contains the JSON object "address" which is set to "google.se". ```javascript PUT /pages/:id ``` #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "google.se is not a valid URL", "address": "google.se" } } ``` ## Postman Test Case 7. ### PTC7.1 Delete web page Requirement: REQ-7 #### Description A user removes an existing web page. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to remove a registered web page by using the DELETE /pages/:id endpoint with a valid id. #### Input - Query parameter contains a valid ID. ```javascript DELETE /pages/:id ``` #### Output ```javascript 200 OK ``` ```json { "message": "Page deleted from user" } ``` ### PTC7.2 Delete web page invalid id Requirement: REQ-7 #### Description A user attempts to remove an existing web page. #### Precondition The service needs to be up and running. The user needs to be logged in. #### Scenario A user attempts to remove a registered web page by using the DELETE /pages/:id endpoint with a invalid id. #### Input - Query parameter contains an invalid ID. ```javascript DELETE /pages/:bad-id ``` #### Output ```javascript 403 Forbidden ``` ```json { "name": "ForbiddenError", "status": 403, "message": "Forbidden" } ``` ## Postman Test Case 8 ### PTC8.1 Get user single domain paths Requirement: Req-8 #### Description A successful request to get a single domains every address. #### Precondition The service needs to be up and running. User must be logged in. #### Scenario A user attempts to get a list of all of their specified domain and paths on that domain. #### Input - Query contains a parameter "domain" and is set to "hitta.se". - Run test. #### Output ```javascript 200 OK ``` ```json [ { "page": { "_id": "<exampelID>", "address": "http://hitta.se/", "domain": "hitta.se", "path": "/", "createdAt": "2021-06-02T07:30:52.915Z" }, "measureAt": "Daily" }, ... ] ``` ### PTC8.2 Find all user web pages Requirement: Req-8 #### Description A successful request to get the user's every address. #### Precondition The service needs to be up and running. User must be logged in. #### Scenario A user attempts to get a list of all of their specified domain and paths on that domain. #### Input - Run test. #### Output ```javascript 200 OK ``` ```json [ { "page": { "_id": "<exampelID>", "address": "http://hitta.se/", "domain": "hitta.se", "path": "/", "createdAt": "2021-06-02T07:30:52.915Z" }, "measureAt": "Daily" }, ... ] ``` ## Postman Test Case 11 ### PTC11.1 Get measurement success Requirement: Req-11 #### Description A successful request to get a UX measurement on an address. #### Precondition The service needs to be up and running. User must be logged in. #### Scenario A user tries to request a UX measurement on their address. #### Input - Body contains the JSON object "addresses" and is set to "["http://hitta.se"]". - Run test. #### Output ```javascript 200 OK ``` ```json [ { "totalScore": <score>, "categories": [ { "id": "first-contentful-paint", ... }, { "id": "speed-index", ... }, { "id": "largest-contentful-paint", ... }, { "id": "interactive", ... }, { "id": "total-blocking-time", ... }, { "id": "cumulative-layout-shift", ... } ] } ] ``` ### PTC11.2 Get measurement not in array Requirement: Req-11 #### Description An unsuccessful request to get a UX measurement on an address. #### Precondition The service needs to be up and running. User must be logged in. #### Scenario A user tries to request a UX measurement on their address. #### Input - Body contains the JSON object "addresses" and is set to "http://hitta.se". - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Invalid parameters, Adresses should be sent as an array" } } ``` ### PTC11.3 Get measurement empty body Requirement: Req-11 #### Description A unsuccessful request to get a UX measurement on an address. #### Precondition The service needs to be up and running. User must be logged in. #### Scenario A user tries to request a UX measurement on their address. #### Input - Run test. #### Output ```javascript 400 Bad Request ``` ```json { "name": "BadRequestError", "status": 400, "message": { "detail": "Invalid parameters, Adresses should be sent as an array" } } ``` ###### tags: `Testning`