Skip to content

test: Add unit tests for grantpermission router (Vitest/ESM) - #2203

Open
trillium wants to merge 2 commits into
hackforla:developmentfrom
trillium:fix/grantpermission-tests-esm
Open

test: Add unit tests for grantpermission router (Vitest/ESM)#2203
trillium wants to merge 2 commits into
hackforla:developmentfrom
trillium:fix/grantpermission-tests-esm

Conversation

@trillium

@trillium trillium commented Sep 1, 2026

Copy link
Copy Markdown
Member

Closes #2091

Adds unit tests for all three routes in backend/routers/grantpermission.router.js.

Changes from jng34's original PR (#2091):

  • Restructure test setup to use beforeAll + vi.resetModules() + dynamic imports so the router's transitive dependencies (googleapis, node-fetch, fs) are intercepted through the mock registry rather than the real modules
  • Switch OAuth2.mockReturnValueOAuth2.mockImplementation (Vitest v4 forbids mockReturnValue on constructor calls)
  • Fix fetch assertions for checkPublicMembership and check2FA helpers (they call fetch with 1 arg, not 2)
  • Document existing router bugs via comments: check2FA never parses the response JSON so twoFAenabled always returns true; grantPermission reject path returns 500, not 400

Result: 23/23 tests pass in ~300ms

jng34 and others added 2 commits August 31, 2026 18:56
- Use beforeAll + vi.resetModules() + dynamic imports so the router's
  transitive deps (googleapis, node-fetch, fs) load through the mock
  registry rather than the real modules
- Replace mockReturnValue on OAuth2 constructor with mockImplementation
  per Vitest v4 class-support requirements
- Fix fetch assertions for checkPublicMembership and check2FA (those
  helpers call fetch with 1 arg, not 2)
- Document existing router bugs: check2FA never parses JSON so
  twoFAenabled always returns true; grantPermission reject path
  returns 500, not 400
@trillium
trillium requested a review from geolunalg September 1, 2026 02:30
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