Skip to content

test: add automated test suite for backend and frontend (#820)#833

Open
Rudra-clrscr wants to merge 3 commits into
Userunknown84:mainfrom
Rudra-clrscr:feature/820-automated-test-suite
Open

test: add automated test suite for backend and frontend (#820)#833
Rudra-clrscr wants to merge 3 commits into
Userunknown84:mainfrom
Rudra-clrscr:feature/820-automated-test-suite

Conversation

@Rudra-clrscr

Copy link
Copy Markdown
Contributor

Summary

Closes #820.

  • Python: the existing pytest suite under backend/tests/ already covered
    /predict input validation, edge cases, and explanation responses, so no
    new Python tests were needed for that acceptance criterion.
  • Node/Express: added backend/tests/predictionRoutes.test.js (Jest +
    Supertest) covering the /predict proxy route — success, missing-text
    400, ML API timeout (504), connection-refused (503), and upstream 4xx/5xx
    handling (400 passthrough / 502).
  • Frontend: added Vitest + React Testing Library and a minimal test suite
    for the prediction form (App.predictionForm.test.jsx) covering the
    disabled-until-input state, a successful submission, and error+retry
    rendering.
  • CONTRIBUTING.md: documented how to run all three test suites.

Bugs found and fixed while writing these tests

  • routes/predictionRoutes.js called
    require("./middleware/cacheMiddleware") with a wrong relative path
    (missing ..). This threw on every real /predict request right
    before contacting Flask, meaning the endpoint always failed with a 503
    in production. redisClient is already imported correctly at the top of
    the file, so the broken duplicate require was just deleted.
  • frontend/src/pages/App.jsx did not compile at all:
    • a duplicate function App() { declaration and an unclosed
      handlePredict function/try-catch, left over from a bad merge
    • a missing closing </div> for the main card wrapper
    • a call to an undefined analyzeEmojis function (the real function is
      analyzeEmojiSentiment) that would throw on every rendered prediction
      result
    • invalid <button> nested inside <button> in the tab bar (React
      hydration warning / invalid HTML)
    • a dead import of a nonexistent ./components/ResultBadge path
  • frontend/src/components/ManipulationIndex.jsx had a stray
    non-JS line (#Manipulation) at the top of the file that also broke the
    production build.

All of the above were pre-existing bugs on main, not introduced by this
branch — vite build and the new/existing test suites now pass.

Test plan

  • cd backend && pytest tests/ — existing suite passes (a couple of
    pre-existing, unrelated failures in other suites due to an undefined
    internal_endpoint_required name elsewhere in api.py; not touched by
    this PR)
  • cd backend && npm test — 22 Jest tests pass; node --test suites for
    keywordRules/rateLimiter pass. (avatarUpload/fileValidation node:test
    suites fail due to a pre-existing unrelated syntax error in
    middleware/fileValidation.js on main — not touched by this PR)
  • cd frontend && npm run build — succeeds
  • cd frontend && npm test — 3/3 pass

…4#820)

- Add Jest+Supertest coverage for the Express /predict proxy route
  (success, timeout, connection-refused, and upstream 4xx/5xx cases).
  Uncovered a real bug in the process: routes/predictionRoutes.js used
  require("./middleware/cacheMiddleware") with a wrong relative path,
  throwing on every real /predict call right before contacting Flask
  and making the endpoint always fail with a 503 in production.
- Fix frontend/src/pages/App.jsx, which did not compile: a duplicate
  `function App() {` declaration left over from a bad merge, an
  unclosed div, a reference to an undefined `analyzeEmojis` (should be
  `analyzeEmojiSentiment`) that would crash on every rendered result,
  invalid <button> nested inside <button> in the tab bar, and a dead
  import of a nonexistent module path.
- Fix a stray non-JS line at the top of ManipulationIndex.jsx that also
  broke the production build.
- Add Vitest + React Testing Library and a minimal test for the
  prediction form (disabled-until-input state, successful submission,
  and error-with-retry rendering).
- Document how to run the Python, Node, and frontend test suites in
  CONTRIBUTING.md.

The existing Python pytest suite under backend/tests/ already covered
/predict input validation, edge cases, and explanations, so no new
Python tests were needed for that acceptance criterion.
Copilot AI review requested due to automatic review settings July 13, 2026 18:04
@vercel

vercel Bot commented Jul 13, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Aditya Sharma's projects Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds automated test coverage across the Node/Express backend and React frontend (closing #820), and includes a few targeted fixes to unblock production builds and make the /predict flow testable/reliable.

Changes:

  • Added Jest + Supertest coverage for the Node /predict proxy route (success + error mapping scenarios).
  • Added Vitest + React Testing Library with a minimal prediction-form test suite and shared test setup.
  • Fixed several pre-existing frontend build/runtime issues (App.jsx merge fallout, invalid imports/markup) and removed a broken duplicate require in the backend route.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
frontend/vite.config.js Configures Vitest (jsdom env, setup file, globals).
frontend/src/test/setup.js Adds RTL cleanup and a jsdom matchMedia polyfill for tests.
frontend/src/pages/App.predictionForm.test.jsx Adds RTL tests for the prediction form behavior (success + retryable error UI).
frontend/src/pages/App.jsx Fixes build/runtime issues and corrects emoji sentiment helper usage.
frontend/src/components/ManipulationIndex.jsx Removes a stray non-JS line that broke builds.
frontend/package.json Adds vitest/RTL deps and a npm test script for the frontend.
frontend/package-lock.json Locks new frontend test dependencies.
CONTRIBUTING.md Documents how to run Python, Node, and frontend test suites.
backend/tests/predictionRoutes.test.js Adds Jest/Supertest tests for backend /predict proxy behavior.
backend/routes/predictionRoutes.js Removes a broken redundant require so /predict can reach Flask/Redis correctly.
Files not reviewed (1)
  • frontend/package-lock.json: Generated file

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +44 to +49
api.get.mockImplementation((url) => {
if (url === '/api/wordcloud') {
return Promise.resolve({ data: { success: true, data: [] } });
}
return Promise.resolve({ data: { success: false } });
});
Comment on lines +50 to +54
vi.stubGlobal(
'fetch',
vi.fn(() => Promise.resolve({ ok: true, json: () => Promise.resolve({ top_features: [] }) })),
);
});
Comment on lines +905 to 909
{result && result !== "Error" && text && analyzeEmojiSentiment(text).count > 0 && (
<div className="mt-4 pt-3 border-t border-slate-700/20">
<p className="text-xs font-semibold opacity-70 mb-2 flex items-center gap-1">
<span>😊</span> Emoji Sentiment
</p>
Rudra-clrscr added 2 commits July 14, 2026 03:12
…rors

This branch's App.jsx/ManipulationIndex.jsx fix (duplicate function App(),
unclosed div, stray non-JS line) was an earlier, less complete pass than
the one later done in fix/frontend-eslint-errors (which also removed dead
state/functions and fixed the emoji regex 'u' flag). Since several other
PRs from this same batch (issues Userunknown84#822/Userunknown84#823/Userunknown84#824) already build on that
later, more complete version, this branch's divergent App.jsx would
conflict with all of them on merge for no reason - this branch never
added anything unique to App.jsx beyond the structural parse fix.

Replacing with the identical, more complete version so this branch's
diff against main is a strict subset of what the other branches already
carry, and merging in any order produces no conflict here.

Verified: App.predictionForm.test.jsx still passes (3/3), vite build
still succeeds.
The container's Flask process defaults to FLASK_HOST=127.0.0.1 (a
deliberate secure default for bare-metal runs), so inside the CI
container it never listens on an interface reachable through the
-p 5000:5000 port mapping, and the smoke test's curl always times out.
docker-compose.yml already sets FLASK_HOST=0.0.0.0 for the same reason;
the CI workflow's docker run step needs the same override.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add automated test suite (backend + ML API)

2 participants