Skip to content

feat: Add accept invitation endpoint#343

Merged
gjtorikian merged 1 commit intomainfrom
accept-invites
Mar 9, 2026
Merged

feat: Add accept invitation endpoint#343
gjtorikian merged 1 commit intomainfrom
accept-invites

Conversation

@workos-sdk-automation
Copy link
Contributor

Summary

  • Adds acceptInvitation($invitationId) method to UserManagement class
  • Sends POST /user_management/invitations/{id}/accept to accept a pending invitation
  • Includes tests for the happy path and 404 error case

Test plan

  • testAcceptInvitation — verifies successful acceptance returns Invitation resource
  • testAcceptInvitation404 — verifies 404 throws NotFoundException
  • All existing tests continue to pass

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@workos-sdk-automation workos-sdk-automation bot requested review from a team as code owners March 9, 2026 16:59
@gjtorikian gjtorikian merged commit 36e9322 into main Mar 9, 2026
8 checks passed
@gjtorikian gjtorikian deleted the accept-invites branch March 9, 2026 17:00
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Mar 9, 2026

Greptile Summary

This PR adds an acceptInvitation($invitationId) method to UserManagement, implementing the POST /user_management/invitations/{id}/accept endpoint. The implementation cleanly follows the exact same pattern as the pre-existing revokeInvitation and resendInvitation methods.

  • lib/UserManagement.php: New acceptInvitation method correctly constructs the path, calls Client::request with METHOD_POST and auth enabled, and returns a Resource\Invitation — consistent with surrounding codebase.
  • tests/WorkOS/UserManagementTest.php: Happy-path test (testAcceptInvitation) and 404 test (testAcceptInvitation404) are properly added. However, the test suite for resendInvitation includes tests for 400-level error scenarios (already-accepted, revoked, expired); similar coverage is absent for acceptInvitation.

Confidence Score: 5/5

  • This PR is safe to merge; the implementation is minimal, correct, and follows established patterns.
  • The new acceptInvitation method is a direct structural copy of revokeInvitation and resendInvitation with only the path segment changed. No new dependencies, no security implications, and existing tests pass. The implementation has zero functional defects. The only item flagged is missing 400-level test cases, which is a test-coverage concern rather than a functional defect.
  • No files require special attention for safety.

Last reviewed commit: 76a8c75

Comment on lines +1704 to +1723
public function testAcceptInvitation404()
{
$invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5";
$path = "user_management/invitations/{$invitationId}/accept";

$this->expectException(Exception\NotFoundException::class);

$this->mockRequest(
Client::METHOD_POST,
$path,
null,
null,
true,
null,
null,
404
);

$this->userManagement->acceptInvitation($invitationId);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing 400-level error test cases

The comparable resendInvitation tests cover several 400 error scenarios (testResendInvitationExpired, testResendInvitationRevoked, testResendInvitationAccepted), but acceptInvitation only tests 404. In practice, the accept endpoint can also return a 400 when the invitation is in an invalid state (e.g. already accepted, revoked, or expired). Consider adding at least one BadRequestException test, mirroring the pattern used for the resend tests:

public function testAcceptInvitationAlreadyAccepted()
{
    $invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5";
    $path = "user_management/invitations/{$invitationId}/accept";

    $this->expectException(Exception\BadRequestException::class);

    $this->mockRequest(
        Client::METHOD_POST,
        $path,
        null,
        null,
        true,
        null,
        null,
        400
    );

    $this->userManagement->acceptInvitation($invitationId);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant