Making Test Suites
We have improved the validation functions validateUsername
and validatePassword
adding the following rules for the username and password respectively:
- The username should be between 3 and 20 characters in length and it can only contain alphanumeric characters.
- The password should be at least 8 characters long and it should contain a combination of lower and uppercase letters along with at least one number or symbol;
Your task is to:
- Organize the test cases present in
validation.js
Test Script, into appropriate describe blocks. - Write test cases to test case code in
auth.js
. Make sure to enclose the test cases in properdescribe
blocks;
Following are the test cases you have to write in the __test__/auth.js
file:
Test ID: 1
- Title: Hash a valid password;
- Precondition: The hashPassword function is available;
- Test Steps:
- Pass the string 'examplePassword123' to the hashPassword function;
- Expected Result: The function should return a string that is different from the input password;
Test ID: 2
- Title: Hash an empty password;
- Precondition: The hashPassword function is available;
- Test Steps:
- Pass an empty string '' to the hashPassword function;
- Expected Result: The function should return a non-empty string;
Test ID: 3
- Title: Compare a valid password with its correct hash;
- Precondition: The comparePassword and hashPassword functions are available;
- Test Steps:
- Hash the string 'examplePassword123' using the hashPassword function;
- Pass the original password 'examplePassword123' and the generated hash to the comparePassword function;
- Expected Result: The function should return true, indicating the password matches the hash;
Test ID: 4
- Title: Compare a valid password with an incorrect hash;
- Precondition: The comparePassword and hashPassword functions are available;
- Test Steps:
- Hash the string 'examplePassword123' using the hashPassword function;
- Pass a different password 'wrongPassword456' and the generated hash to the comparePassword function;
- Expected Result: The function should return false, indicating the password does not match the hash;
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 2. Capítulo 8
Pergunte à IA
Pergunte à IA
Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo
Awesome!
Completion rate improved to 3.85
Making Test Suites
Deslize para mostrar o menu
We have improved the validation functions validateUsername
and validatePassword
adding the following rules for the username and password respectively:
- The username should be between 3 and 20 characters in length and it can only contain alphanumeric characters.
- The password should be at least 8 characters long and it should contain a combination of lower and uppercase letters along with at least one number or symbol;
Your task is to:
- Organize the test cases present in
validation.js
Test Script, into appropriate describe blocks. - Write test cases to test case code in
auth.js
. Make sure to enclose the test cases in properdescribe
blocks;
Following are the test cases you have to write in the __test__/auth.js
file:
Test ID: 1
- Title: Hash a valid password;
- Precondition: The hashPassword function is available;
- Test Steps:
- Pass the string 'examplePassword123' to the hashPassword function;
- Expected Result: The function should return a string that is different from the input password;
Test ID: 2
- Title: Hash an empty password;
- Precondition: The hashPassword function is available;
- Test Steps:
- Pass an empty string '' to the hashPassword function;
- Expected Result: The function should return a non-empty string;
Test ID: 3
- Title: Compare a valid password with its correct hash;
- Precondition: The comparePassword and hashPassword functions are available;
- Test Steps:
- Hash the string 'examplePassword123' using the hashPassword function;
- Pass the original password 'examplePassword123' and the generated hash to the comparePassword function;
- Expected Result: The function should return true, indicating the password matches the hash;
Test ID: 4
- Title: Compare a valid password with an incorrect hash;
- Precondition: The comparePassword and hashPassword functions are available;
- Test Steps:
- Hash the string 'examplePassword123' using the hashPassword function;
- Pass a different password 'wrongPassword456' and the generated hash to the comparePassword function;
- Expected Result: The function should return false, indicating the password does not match the hash;
Tudo estava claro?
Obrigado pelo seu feedback!
Seção 2. Capítulo 8