Skip to content

Implement new tests and fix validation code. Also some coverage information and details. #46

Closed
R-aidla wants to merge 1 commit into
tanjaq:mainfrom
R-aidla:main
Closed

Implement new tests and fix validation code. Also some coverage information and details. #46
R-aidla wants to merge 1 commit into
tanjaq:mainfrom
R-aidla:main

Conversation

@R-aidla
Copy link
Copy Markdown

@R-aidla R-aidla commented Apr 27, 2026

Summarized commits:

  • Add missing password param check
  • Add missing username param check
  • Update app.mock.test.js to match app.test.js tests
  • Update app.test.js tests to test for business requirements
  • Clean up comments from test files
  • Perform coverage tests

Coverage

Statements: 100%
Branches: 100%
Functions: 100%
Lines: 100%

All files are fully covered, including:

  • app.js
  • validateUsername.js
  • validatePassword.js
  • validateEmail.js

Observations

There is a significant performance gap between mocked and non-mocked tests due to non-mocked running validateEmail.js that has a 2 second delay built-in the non-mocked validateEmail.js script calling out to a (simulated) external service to check emails. The mocked test is giving an expected response back to the test without calling out to the external service, removing any potential delays.
Integration tests currently take ~2 seconds per request, which may indicate:

  • Artificial delays in validation (a simple 2 second delay simulating high demand services)
  • Inefficiencies worth investigating separately

Detailed tests and time

Tests were ran at 20:00 27.04.2026

PASS validation/validateUsername.test.js (0.014 s)

√ return false for empty username (9 ms)
√ return false for username < 6 characters
√ return false for username > 30 characters (1 ms)
√ return true for username > 6 and < 30 characters (1 ms)
√ return false for username that contains unauthorized characters
√ return true for username with authorized characters (1 ms)

PASS validation/validatePassword.test.js (0.019 s)

√ return false for empty password (9 ms)
√ return false for password < 8 characters
√ return false for password = 7 characters (1 ms)
√ return true for password = 8 characters
√ return true for password => 8 characters (1 ms)
√ return false for password => 8 characters, no numbers
√ return false for password => 8 characters, no lowercase (1 ms)
√ return false for password => 8 characters, no uppercase
√ return false for password => 8 characters, no letters (1 ms)
√ return false for password with special characters (1 ms)
√ return false for password with special characters and underscore

PASS ./app.mock.test.js (0.684 s)

given correct username and password
√ return status 200 (31 ms)
√ return status 200 on email with subdomain (4 ms)
√ return correct content type (4 ms)
√ returns userId (4 ms)
√ returns success message (4 ms)
given incorrect or missing username and password
√ returns 400 for short username (5 ms)
√ returns 400 for invalid char username (3 ms)
√ returns 400 for invalid length username (4 ms)
√ returns 400 for invalid length password (6 ms)
√ returns 400 for missing number in password (4 ms)
√ returns 400 for special char in password (3 ms)
√ returns 400 for invalid UPPERCASE only password (2 ms)
√ returns 400 for invalid lowercase only password (2 ms)
√ returns 400 for invalid email (3 ms)
√ returns 400 for invalid with no extension email (2 ms)
√ returns 400 for invalid with invalid extension email (2 ms)
√ returns error message (2 ms)
√ does not return userId (2 ms)
√ missing username (2 ms)
√ missing password (2 ms)
√ missing email (2 ms)

PASS validation/validateEmail.test.js (10.589 s)

√ return false for empty email (2010 ms)
√ return false for missing @ (2000 ms)
√ return false for missing domain (2000 ms)
√ return true for simple valid email (2000 ms)
√ return true for email with subdomain (2000 ms)

PASS ./app.test.js (42.968 s)

given correct username and password
√ return status 200 (2034 ms)
√ return status 200 on email with subdomain (2006 ms)
√ return correct content type (2005 ms)
√ returns userId (2004 ms)
√ returns success message (2004 ms)
given incorrect or missing username and password
√ returns 400 for short username (2003 ms)
√ returns 400 for invalid char username (2002 ms)
√ returns 400 for invalid length username (2003 ms)
√ returns 400 for invalid length password (2004 ms)
√ returns 400 for missing number in password (2003 ms)
√ returns 400 for special char in password (2003 ms)
√ returns 400 for invalid UPPERCASE only password (2003 ms)
√ returns 400 for invalid lowercase only password (2003 ms)
√ returns 400 for invalid email (2003 ms)
√ returns 400 for invalid with no extension email (2003 ms)
√ returns 400 for invalid with invalid extension email (2003 ms)
√ returns error message (2003 ms)
√ does not return userId (2003 ms)
√ missing username (2003 ms)
√ missing password (2003 ms)
√ missing email (2004 ms)

Test Suites: 5 passed, 5 total
Tests: 64 passed, 64 total
Snapshots: 0 total
Time:43.279 s, estimated 44 s
Ran all test suites.

- Add missing password param check
- Add missing username param check
- Update app.mock.test.js to match app.test.js tests
- Update app.test.js tests to test for business requirements
- Clean up comments from test files
- Perform coverage tests
@github-actions
Copy link
Copy Markdown

API & Mocked Tests and Coverage

Purpose: Validate README requirements for regular tests, mocked email tests, coverage, and runtime comparison.
Status: ✅ PASS
Regular tests (app.test.js): ✅ PASS (43551ms)
Mocked tests (app.mock.test.js): ✅ PASS (1253ms)
Coverage gate (both runs at 100%): ✅ PASS
Runtime gate (regular ≥ mocked + 1500ms): ✅ PASS
Regular coverage (app.js): lines=100% | statements=100% | functions=100% | branches=100%
Mocked coverage (app.js only): lines=100% | statements=100% | functions=100% | branches=100%
Run details: https://github.com/tanjaq/User-Register/actions/runs/25012427600
PR checks: https://github.com/tanjaq/User-Register/pull/46/checks

@R-aidla
Copy link
Copy Markdown
Author

R-aidla commented Apr 27, 2026

Additional Context

Bug Fix Identified During Testing

While running the test suite, an issue was discovered where the username and password validation logic did not handle undefined inputs.

This resulted in runtime errors such as:

TypeError: Cannot read properties of undefined (reading 'length')

This also caused some tests to hang longer than expected, since the request would fail without returning a proper response.

Fix implemented:

  • Added guards for undefined inputs in:

    • validateUsername
    • validatePassword
  • Aligned behavior with existing validateEmail validation

This fix should (in theory) prevent server crashes on malformed requests and ensure consistent validation across all input fields.

@tanjaq tanjaq closed this May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants