Skip to content

Add JoinRequestsService unit tests - #288

Merged
shaply merged 2 commits into
mainfrom
ryan/188-join-request-service-tests
Sep 28, 2026
Merged

shaply merged 2 commits into
mainfrom
ryan/188-join-request-service-tests

Conversation

@RyanPCo

@RyanPCo RyanPCo commented Sep 28, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #188

Checklist:

  • I have mentioned a ticket above
  • My changes meet the acceptance criteria of said ticket
  • I have self-reviewed my changes
  • I have requested a review from the appropriate team member(s)
  • I have fixed all merge conflicts
  • I have ensured CI checks pass

Description


Adds unit tests for every function in JoinRequestsService, run against the real test Postgres like the other service tests.

Changes Made


  • New tests/unit/lib/services/JoinRequestService.test.ts and tests/unit/api/joinrequests/route.test.ts.

  • create, findById, findByUserAndOrganization, findByIdAndOrganization: return shape, not found, and a request in another organization.

  • listByOrganization: user fields, history, organization name, newest-first order, limit, offset, and tenant isolation.

  • listHistory / addHistoryEntry: order, resolver name, and scoping to one request.

  • updateStatus: approve (adds member, notifies, records history), deny with and without a reason, approved → pending (removes member, sends "Access Removed"), no notification when the status is unchanged, and no side effects on another organization's request.

  • deleteById: deletes the request and its history, and leaves other requests alone.

  • PATCH /api/joinRequests: updates a request in the admin's organization, and returns 404 for another organization's request without changing it.

One production fix: listByOrganization ignored the offset the join requests list route passes in, so page 2 returned page 1 again. It now applies the offset.

@netlify

netlify Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for servicestart ready!

Name Link
🔨 Latest commit b038d00
🔍 Latest deploy log https://app.netlify.com/projects/servicestart/deploys/6ab9b60f3db588000835bafa
😎 Deploy Preview https://deploy-preview-288--servicestart.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@RyanPCo
RyanPCo force-pushed the ryan/188-join-request-service-tests branch from bd1e8d3 to 46a32e9 Compare September 28, 2026 00:20
@RyanPCo
RyanPCo requested a review from shaply September 28, 2026 00:26
@RyanPCo
RyanPCo marked this pull request as ready for review September 28, 2026 00:26
@greptile-apps

greptile-apps Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Disclaimer: This comment was AI-generated and is not necessarily completely accurate. Please take code comments with a grain of salt.

RetriggerConfidence Score: 4/5

[Low risk] Adds unit tests for join request service.

The tests appear safe to merge, but targeted additions would better protect pagination and cross-organization review behavior.

Findings

  1. P2 Pagination offset remains untested ▶
  2. P2 Foreign request rejection untested ▶
  3. P2 History update reaches unrelated entries ▶

Summary

Adds database-backed unit tests for JoinRequestsService lookups, listings, history, status transitions, and deletion.

  • The main improvement needed is coverage of nonzero pagination offsets and the PATCH route’s cross-organization rejection.
  • Review score: 85/100.

Reviews (1) · Last reviewed commit: "Add JoinRequestsService unit tests"

Comment on lines +240 to +244
const result = await JoinRequestsService.listByOrganization(org.id, {
limit: 2,
});

expect(result).toHaveLength(2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Pagination offset remains untested The new test checks only limit. The API supplies an offset for later pages, but listByOrganization ignores it, so this test passes even when later pages repeat the first page. A second-page assertion would cover that gap.

Knowledge Base Used: Membership and join requests

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good catch. This was a real bug: listByOrganization ignored offset, so page 2 returned page 1. Fixed in b038d00, with a test that checks page 2.

Comment on lines +464 to +471
await JoinRequestsService.updateStatus(
idA,
JoinRequestStatus.Denied,
admin.user.id,
admin.headers,
undefined,
JoinRequestStatus.Pending,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 Foreign request rejection untested This test updates idA, which belongs to the administrator’s organization, then checks that unrelated idB was left alone. It cannot catch a regression in the PATCH route’s check that rejects a request from another organization. Testing that route with idB would cover the intended boundary.

Knowledge Base Used: Membership and join requests

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. I renamed this test to "only updates the given join request" and added tests/unit/api/joinrequests/route.test.ts, which checks that PATCH returns 404 for another organization's request and leaves it unchanged. Fixed in b038d00.

Comment on lines +269 to +272
await db
.update(joinRequestHistory)
.set({ resolvedAt: new Date("2025-01-01T00:00:00Z") })
.where(eq(joinRequestHistory.action, "approved"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

P2 History update reaches unrelated entries The timestamp update matches every approved history entry, not just the one created for this request. Current cleanup makes that harmless here, but adding another approved entry to the test would silently change its fixture data. Scope the update to this request.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Scoped the update to this join request's ID in b038d00.

- Pass the offset through in JoinRequestsService.listByOrganization so later pages no longer repeat the first page
- Test pagination offset
- Test that PATCH /api/joinRequests rejects a request from another organization
- Scope the history timestamp fixture to one join request
@shaply
shaply merged commit 7c7f5b1 into main Sep 28, 2026
25 checks passed

This branch was successfully deployed

1 active deployment
Preview — b038d005 Deployed Sep 28, 2026 by shaply via drop-db #253
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.

JoinRequestService Unit Tests

2 participants