Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions lib/UserManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
107 changes: 107 additions & 0 deletions tests/WorkOS/UserManagementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down