Skip to content

Commit b4a437b

Browse files
authored
Add ability to resend invitation (#307)
1 parent c9f5a1c commit b4a437b

File tree

2 files changed

+131
-0
lines changed

2 files changed

+131
-0
lines changed

lib/UserManagement.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,30 @@ public function revokeInvitation($invitationId)
617617
return Resource\Invitation::constructFromResponse($response);
618618
}
619619

620+
/**
621+
* Resend an Invitation
622+
*
623+
* @param string $invitationId ID of the Invitation
624+
*
625+
* @throws Exception\WorkOSException
626+
*
627+
* @return Resource\Invitation
628+
*/
629+
public function resendInvitation($invitationId)
630+
{
631+
$path = "user_management/invitations/{$invitationId}/resend";
632+
633+
$response = Client::request(
634+
Client::METHOD_POST,
635+
$path,
636+
null,
637+
null,
638+
true
639+
);
640+
641+
return Resource\Invitation::constructFromResponse($response);
642+
}
643+
620644
/**
621645
* Generates an OAuth 2.0 authorization URL used to initiate the SSO flow with WorkOS.
622646
*

tests/WorkOS/UserManagementTest.php

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,113 @@ public function testRevokeInvitation()
13141314
$this->assertSame($response->toArray(), $expected);
13151315
}
13161316

1317+
public function testResendInvitation()
1318+
{
1319+
$invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5";
1320+
$path = "user_management/invitations/{$invitationId}/resend";
1321+
1322+
$result = $this->invitationResponseFixture();
1323+
1324+
$this->mockRequest(
1325+
Client::METHOD_POST,
1326+
$path,
1327+
null,
1328+
null,
1329+
true,
1330+
$result
1331+
);
1332+
1333+
$response = $this->userManagement->resendInvitation($invitationId);
1334+
1335+
$expected = $this->invitationFixture();
1336+
1337+
$this->assertSame($response->toArray(), $expected);
1338+
}
1339+
1340+
public function testResendInvitation404()
1341+
{
1342+
$invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5";
1343+
$path = "user_management/invitations/{$invitationId}/resend";
1344+
1345+
$this->expectException(Exception\NotFoundException::class);
1346+
1347+
$this->mockRequest(
1348+
Client::METHOD_POST,
1349+
$path,
1350+
null,
1351+
null,
1352+
true,
1353+
null,
1354+
null,
1355+
404
1356+
);
1357+
1358+
$this->userManagement->resendInvitation($invitationId);
1359+
}
1360+
1361+
public function testResendInvitationExpired()
1362+
{
1363+
$invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5";
1364+
$path = "user_management/invitations/{$invitationId}/resend";
1365+
1366+
$this->expectException(Exception\BadRequestException::class);
1367+
1368+
$this->mockRequest(
1369+
Client::METHOD_POST,
1370+
$path,
1371+
null,
1372+
null,
1373+
true,
1374+
null,
1375+
null,
1376+
400
1377+
);
1378+
1379+
$this->userManagement->resendInvitation($invitationId);
1380+
}
1381+
1382+
public function testResendInvitationRevoked()
1383+
{
1384+
$invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5";
1385+
$path = "user_management/invitations/{$invitationId}/resend";
1386+
1387+
$this->expectException(Exception\BadRequestException::class);
1388+
1389+
$this->mockRequest(
1390+
Client::METHOD_POST,
1391+
$path,
1392+
null,
1393+
null,
1394+
true,
1395+
null,
1396+
null,
1397+
400
1398+
);
1399+
1400+
$this->userManagement->resendInvitation($invitationId);
1401+
}
1402+
1403+
public function testResendInvitationAccepted()
1404+
{
1405+
$invitationId = "invitation_01E4ZCR3C56J083X43JQXF3JK5";
1406+
$path = "user_management/invitations/{$invitationId}/resend";
1407+
1408+
$this->expectException(Exception\BadRequestException::class);
1409+
1410+
$this->mockRequest(
1411+
Client::METHOD_POST,
1412+
$path,
1413+
null,
1414+
null,
1415+
true,
1416+
null,
1417+
null,
1418+
400
1419+
);
1420+
1421+
$this->userManagement->resendInvitation($invitationId);
1422+
}
1423+
13171424
public function testGetJwksUrl()
13181425
{
13191426
$clientId = "12345";

0 commit comments

Comments
 (0)