diff --git a/lib/UserManagement.php b/lib/UserManagement.php index be42bbd9..581650ed 100644 --- a/lib/UserManagement.php +++ b/lib/UserManagement.php @@ -643,6 +643,29 @@ public function resendInvitation($invitationId) return Resource\Invitation::constructFromResponse($response); } + /** + * Accept an Invitation + * + * @param string $invitationId ID of the Invitation + * @return Resource\Invitation + * + * @throws Exception\WorkOSException + */ + public function acceptInvitation($invitationId) + { + $path = "user_management/invitations/{$invitationId}/accept"; + + $response = Client::request( + Client::METHOD_POST, + $path, + null, + null, + true + ); + + return Resource\Invitation::constructFromResponse($response); + } + /** * Generates an OAuth 2.0 authorization URL used to initiate the SSO flow with WorkOS. * diff --git a/tests/WorkOS/UserManagementTest.php b/tests/WorkOS/UserManagementTest.php index 5b64d834..cd8b74d8 100644 --- a/tests/WorkOS/UserManagementTest.php +++ b/tests/WorkOS/UserManagementTest.php @@ -1678,6 +1678,50 @@ public function testResendInvitationAccepted() $this->userManagement->resendInvitation($invitationId); } + public function testAcceptInvitation() + { + $invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5"; + $path = "user_management/invitations/{$invitationId}/accept"; + + $result = $this->invitationResponseFixture(); + + $this->mockRequest( + Client::METHOD_POST, + $path, + null, + null, + true, + $result + ); + + $response = $this->userManagement->acceptInvitation($invitationId); + + $expected = $this->invitationFixture(); + + $this->assertSame($response->toArray(), $expected); + } + + 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); + } + public function testGetJwksUrl() { $clientId = "12345";