diff --git a/lib/UserManagement.php b/lib/UserManagement.php index d6f04877..a277fb1f 100644 --- a/lib/UserManagement.php +++ b/lib/UserManagement.php @@ -617,6 +617,30 @@ public function revokeInvitation($invitationId) return Resource\Invitation::constructFromResponse($response); } + /** + * Resend an Invitation + * + * @param string $invitationId ID of the Invitation + * + * @throws Exception\WorkOSException + * + * @return Resource\Invitation + */ + public function resendInvitation($invitationId) + { + $path = "user_management/invitations/{$invitationId}/resend"; + + $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 288f3603..cb527135 100644 --- a/tests/WorkOS/UserManagementTest.php +++ b/tests/WorkOS/UserManagementTest.php @@ -1314,6 +1314,113 @@ public function testRevokeInvitation() $this->assertSame($response->toArray(), $expected); } + public function testResendInvitation() + { + $invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5"; + $path = "user_management/invitations/{$invitationId}/resend"; + + $result = $this->invitationResponseFixture(); + + $this->mockRequest( + Client::METHOD_POST, + $path, + null, + null, + true, + $result + ); + + $response = $this->userManagement->resendInvitation($invitationId); + + $expected = $this->invitationFixture(); + + $this->assertSame($response->toArray(), $expected); + } + + public function testResendInvitation404() + { + $invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5"; + $path = "user_management/invitations/{$invitationId}/resend"; + + $this->expectException(Exception\NotFoundException::class); + + $this->mockRequest( + Client::METHOD_POST, + $path, + null, + null, + true, + null, + null, + 404 + ); + + $this->userManagement->resendInvitation($invitationId); + } + + public function testResendInvitationExpired() + { + $invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5"; + $path = "user_management/invitations/{$invitationId}/resend"; + + $this->expectException(Exception\BadRequestException::class); + + $this->mockRequest( + Client::METHOD_POST, + $path, + null, + null, + true, + null, + null, + 400 + ); + + $this->userManagement->resendInvitation($invitationId); + } + + public function testResendInvitationRevoked() + { + $invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5"; + $path = "user_management/invitations/{$invitationId}/resend"; + + $this->expectException(Exception\BadRequestException::class); + + $this->mockRequest( + Client::METHOD_POST, + $path, + null, + null, + true, + null, + null, + 400 + ); + + $this->userManagement->resendInvitation($invitationId); + } + + public function testResendInvitationAccepted() + { + $invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5"; + $path = "user_management/invitations/{$invitationId}/resend"; + + $this->expectException(Exception\BadRequestException::class); + + $this->mockRequest( + Client::METHOD_POST, + $path, + null, + null, + true, + null, + null, + 400 + ); + + $this->userManagement->resendInvitation($invitationId); + } + public function testGetJwksUrl() { $clientId = "12345";