Skip to content

test: add e2e test suite#127

Closed
amitb0ra wants to merge 2 commits intoRocketChat:masterfrom
amitb0ra:add-tests
Closed

test: add e2e test suite#127
amitb0ra wants to merge 2 commits intoRocketChat:masterfrom
amitb0ra:add-tests

Conversation

@amitb0ra
Copy link
Copy Markdown
Contributor

@amitb0ra amitb0ra commented Mar 24, 2026

Summary

Adds a comprehensive end-to-end test suite that spins up the actual app.js server with the real GSoC 2025 dataset (251 contributors) and validates every HTTP endpoint with real HTTP requests.

49 test cases, 0 fail, 0 skip.

Test isolation

Tests run against fixture files in tests/e2e/fixtures/ — copied to a temp directory per run and pointed to via LEADERBOARD_* env vars. No production files are ever touched. Temp directory is cleaned up automatically after each run.

What's tested

Endpoint Tests
GET /data Full dataset returned, known contributor stats, zero-contribution users, required fields
GET /config Organization metadata, no secret leakage (authToken, adminPassword)
GET /log Returns log object with start/end times
GET /stats Aggregate stats match pre-computed values, match manual sum over /data
GET /rank Default + parameterized sorting (mergedprs, openprs, issues), username lookup, case-insensitive, non-existent user
GET /contributor By username, by rank, by rank+parameter, case-sensitive lookup, non-existent user
POST /login Rejects GET, wrong password, correct password returns contributor list
POST /setStartDate Rejects GET, wrong password, accepts correct password
POST /setInterval Rejects GET, wrong password, accepts correct password
POST /setIncludedRepositories Rejects GET, wrong password, accepts correct password
POST /remove Rejects GET, wrong password, removes contributor + verifies /data and /stats update
Invalid JSON body Malformed JSON → 400, empty body → 400
Unknown routes Returns "Permission denied"
Cross-endpoint consistency Stats match data sums, rank length matches data keys, rank→contributor lookup matches data

Server changes

Other changes

  • Removed dead tests/access.sh and tests/api-call-tests.sh (brute-force stress scripts hitting a dead external URL)
  • Removed stale .dockerignore (Docker support was removed in a previous PR)
  • Added npm test script → node --test 'tests/**/*.test.js'

How to run

npm test

Requires Node.js 18+.

image

Copy link
Copy Markdown
Member

@Sing-Li Sing-Li left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't work on a fresh checkout / clone.

  1. clone the directory at the PR level
  2. cd to directory
  3. npm i
  4. npm test

Fails with

[server stderr] node:internal/modules/cjs/loader:1404
  throw err;
  ^

Error: Cannot find module 'socket.io'

Please fix problem.

@Sing-Li
Copy link
Copy Markdown
Member

Sing-Li commented Mar 25, 2026

It is extremely bad practice to change the source code being tested when adding tests. EVEN if it has very good intention, in this case - adding .dotenv support.

Therefore please make sure you move and separate any base code changes to another PR with the appropriate title.

- app.js: env-var path overrides (LEADERBOARD_CONFIG_PATH, LEADERBOARD_DATA_PATH,
  LEADERBOARD_LOG_PATH, LEADERBOARD_ADMINDATA_PATH, LEADERBOARD_CONFIG_BACKUP_PATH,
  LEADERBOARD_PORT), LEADERBOARD_SKIP_REFRESH to disable child process, pass res
  to Util.post calls, fix hardcoded ./admindata.json in login handler, export server
- Util.js: post(req, res, callback) — respond 400 on malformed JSON instead of
  silently hanging, move findContributor from app.js
- API.js: remove process.exit() on bad credentials — log error and return instead,
  support LEADERBOARD_CONFIG_PATH env var
- Remove dead .dockerignore (Docker support removed previously)
- Remove stale tests/access.sh and tests/api-call-tests.sh (brute-force scripts
  hitting dead external URLs)
- Add comprehensive e2e tests against real GSoC 2025 dataset (251 contributors)
- Add unit tests for API, Util, and refresh modules
- Test all HTTP endpoints: /data, /config, /log, /stats, /rank, /contributor,
  /login, /setStartDate, /setInterval, /setIncludedRepositories, /remove
- Validate cross-endpoint consistency, invalid JSON handling, unknown routes
- Fixture-based test isolation using temp directories and env-var overrides
- Add npm test script (installs server deps before running tests)
- Requires Node.js 18+
@amitb0ra
Copy link
Copy Markdown
Contributor Author

amitb0ra commented Mar 25, 2026

done! i've moved base code changes into #130 . also fixed the fresh-clone issue, now auto-installs server deps before running.

@Sing-Li
Copy link
Copy Markdown
Member

Sing-Li commented Mar 30, 2026

This is another YOLO disaster that's probably not worth your time to even fix.

Please make sure you know what the agent proposed before you allow it to generate the test next time. And please make sure your description conforms to CONTRIBUTING guidelines re: AI generation.

I'll do both of us a favor and close this.

@Sing-Li Sing-Li closed this Mar 30, 2026
@amitb0ra amitb0ra deleted the add-tests branch April 1, 2026 17:55
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