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
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,11 @@ class UserManagementApi(private val workos: WorkOS) {
return workos.post("/user_management/invitations/$id/revoke", Invitation::class.java)
}

/** Resends an existing invitation. */
fun resendInvitation(id: String): Invitation {
return workos.post("/user_management/invitations/$id/resend", Invitation::class.java)
}

/** End a user's session. The user's browser should be redirected to this URL. */
fun getLogoutUrl(sessionId: String, returnTo: String? = null): String {
return URIBuilder(workos.baseUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1877,6 +1877,122 @@ class UserManagementApiTest : TestBase() {
)
}

@Test
fun resendInvitationShouldReturnValidInvitation() {
stubResponse(
"/user_management/invitations/invitation_123/resend",
"""{
"id": "invitation_123",
"email": "test01@example.com",
"state": "pending",
"accepted_at": null,
"revoked_at": null,
"expires_at": "2021-07-01T19:07:33.155Z",
"token": "Z1uX3RbwcIl5fIGJJJCXXisdI",
"accept_invitation_url": "https://your-app.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
"inviter_user_id": "user_789",
"organization_id": "org_456",
"created_at": "2021-06-25T19:07:33.155Z",
"updated_at": "2021-06-25T19:07:33.155Z"
}"""
)

val invitation = workos.userManagement.resendInvitation("invitation_123")

assertEquals(
Invitation(
"invitation_123",
"test01@example.com",
InvitationStateEnumType.Pending,
null,
null,
"2021-07-01T19:07:33.155Z",
"Z1uX3RbwcIl5fIGJJJCXXisdI",
"https://your-app.com/invite?invitation_token=Z1uX3RbwcIl5fIGJJJCXXisdI",
"org_456",
"user_789",
"2021-06-25T19:07:33.155Z",
"2021-06-25T19:07:33.155Z"
),
invitation
)
}

@Test
fun resendInvitationShouldHandleExpiredInvitation() {
stubResponse(
"/user_management/invitations/invitation_123/resend",
"""{
"code": "invite_expired",
"message": "Invite has expired."
}""",
responseStatus = 400
)

val exception = assertThrows(BadRequestException::class.java) {
workos.userManagement.resendInvitation("invitation_123")
}

assertEquals("Invite has expired.", exception.message)
assertEquals("invite_expired", exception.code)
}

@Test
fun resendInvitationShouldHandleRevokedInvitation() {
stubResponse(
"/user_management/invitations/invitation_123/resend",
"""{
"code": "invite_revoked",
"message": "Invite has been revoked."
}""",
responseStatus = 400
)

val exception = assertThrows(BadRequestException::class.java) {
workos.userManagement.resendInvitation("invitation_123")
}

assertEquals("Invite has been revoked.", exception.message)
assertEquals("invite_revoked", exception.code)
}

@Test
fun resendInvitationShouldHandleAcceptedInvitation() {
stubResponse(
"/user_management/invitations/invitation_123/resend",
"""{
"code": "invite_accepted",
"message": "Invite has already been accepted."
}""",
responseStatus = 400
)

val exception = assertThrows(BadRequestException::class.java) {
workos.userManagement.resendInvitation("invitation_123")
}

assertEquals("Invite has already been accepted.", exception.message)
assertEquals("invite_accepted", exception.code)
}

@Test
fun resendInvitationShouldHandleNotFoundError() {
stubResponse(
"/user_management/invitations/invitation_invalid/resend",
"""{
"message": "Invitation not found.",
"code": "not_found"
}""",
responseStatus = 404
)

val exception = assertThrows(com.workos.common.exceptions.NotFoundException::class.java) {
workos.userManagement.resendInvitation("invitation_invalid")
}

assertEquals("NotFoundException", exception.message)
}

@Test
fun getLogoutUrlShouldReturnValidUrlResponse() {
val url = workos.userManagement.getLogoutUrl("session_123")
Expand Down