Skip to content

🧪 testing improvement: add unit tests for upload-excel api and fix failing tests#7

Open
deitaur wants to merge 1 commit into
masterfrom
fix/testing-upload-excel-14958525485771934442
Open

🧪 testing improvement: add unit tests for upload-excel api and fix failing tests#7
deitaur wants to merge 1 commit into
masterfrom
fix/testing-upload-excel-14958525485771934442

Conversation

@deitaur
Copy link
Copy Markdown
Owner

@deitaur deitaur commented May 29, 2026

🎯 What:

  • The endpoint POST /api/upload-excel lacked any unit testing, leaving crucial logic regarding importing user inventories from Excel vulnerable to regressions.
  • Previous tests in api.test.js were completely broken due to the ensureAuthenticated checking req.user from Passport.js, which was undefined since we didn't mock Passport appropriately before importing app.

📊 Coverage:

  • Added robust mocks for pg connection pools/clients to intercept BEGIN, COMMIT, ROLLBACK and query execution.
  • Added tests for POST /api/upload-excel that dynamically create a real Excel document in buffer to test the exceljs loading logic properly.
  • Covered the missing file condition (returning 400).
  • Covered the database exception condition to test correct transaction rollback implementation (returning 500).
  • Globally mocked Express app.request.isAuthenticated and app.request.user to easily mock authenticated sessions for supertest.

Result:

  • Total tests in the suite successfully passes (5 out of 5 tests). Test coverage greatly improved for critical upload paths and no more tests failing out of the box due to passport and missing .env mock parameters.

PR created automatically by Jules for task 14958525485771934442 started by @deitaur

- Added comprehensive tests for `POST /api/upload-excel` to handle the Excel upload, parsing logic, and DB transactions handling.
- Covered happy path, missing file (400 code), and DB errors resulting in rollback (500 code).
- Fixed the previous failing tests in `__tests__/api.test.js` by globally intercepting Passport's `req.isAuthenticated()` and `req.user` through `Object.defineProperty` and fixing `pg` queries.

Co-authored-by: deitaur <113350206+deitaur@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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.

1 participant