PM-10956: Add support for leave organization API (#3754)

This commit is contained in:
David Perez 2024-08-16 08:37:07 -05:00 committed by GitHub
parent 8094b3fd22
commit d4600c5c83
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 28 additions and 0 deletions

View file

@ -5,6 +5,7 @@ import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationKeysRe
import com.x8bit.bitwarden.data.auth.datasource.network.model.OrganizationResetPasswordEnrollRequestJson
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
@ -37,4 +38,12 @@ interface AuthenticatedOrganizationApi {
suspend fun getOrganizationKeys(
@Path("id") organizationId: String,
): Result<OrganizationKeysResponseJson>
/**
* Leaves the this organization.
*/
@POST("/organizations/{id}/leave")
suspend fun leaveOrganization(
@Path("id") organizationId: String,
): Result<Unit>
}

View file

@ -38,4 +38,11 @@ interface OrganizationService {
suspend fun getOrganizationKeys(
organizationId: String,
): Result<OrganizationKeysResponseJson>
/**
* Leaves this organization.
*/
suspend fun leaveOrganization(
organizationId: String,
): Result<Unit>
}

View file

@ -52,4 +52,9 @@ class OrganizationServiceImpl(
.getOrganizationKeys(
organizationId = organizationId,
)
override suspend fun leaveOrganization(
organizationId: String,
): Result<Unit> =
authenticatedOrganizationApi.leaveOrganization(organizationId = organizationId)
}

View file

@ -104,6 +104,13 @@ class OrganizationServiceTest : BaseServiceTest() {
val result = organizationService.getOrganizationKeys("orgId")
assertTrue(result.isFailure)
}
@Test
fun `leaveOrganization when response is success should return success`() = runTest {
server.enqueue(MockResponse())
val result = organizationService.leaveOrganization(organizationId = "orgId")
assertTrue(result.isSuccess)
}
}
private const val ORGANIZATION_AUTO_ENROLL_STATUS_JSON = """