Skip to content

Commit

Permalink
Refactored code.| #2162
Browse files Browse the repository at this point in the history
  • Loading branch information
DenBond7 committed Mar 8, 2023
1 parent 07084e3 commit 0786af1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ import com.flowcrypt.email.rules.ScreenshotTestRule
import com.flowcrypt.email.ui.base.BaseFesDuringSetupFlowTest
import com.flowcrypt.email.util.TestGeneralUtil
import com.flowcrypt.email.util.exception.ApiException
import com.google.api.client.json.gson.GsonFactory
import com.google.api.services.gmail.model.ListMessagesResponse
import com.google.gson.Gson
import okhttp3.mockwebserver.MockResponse
import okhttp3.mockwebserver.RecordedRequest
Expand Down Expand Up @@ -58,24 +56,6 @@ class FesDuringSetupConsumerFlowTest : BaseFesDuringSetupFlowTest() {
override fun handleAPI(request: RecordedRequest, gson: Gson): MockResponse {
return when {
request.path?.startsWith("/ekm") == true -> handleEkmAPI(request, gson)

request.requestUrl?.encodedPath == "/gmail/v1/users/me/messages"
&& request.requestUrl?.queryParameterNames?.contains("q") == true -> {
val q = requireNotNull(request.requestUrl?.queryParameter("q"))
return when {
q.startsWith("from:${EMAIL_FES_ENFORCE_ATTESTER_SUBMIT}") -> MockResponse()
.setResponseCode(HttpURLConnection.HTTP_OK)
.setBody(
ListMessagesResponse().apply {
factory = GsonFactory.getDefaultInstance()
messages = emptyList()
resultSizeEstimate = 0
}.toString()
)

else -> MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
}
}
else -> MockResponse().setResponseCode(HttpURLConnection.HTTP_NOT_FOUND)
}
}
Expand Down Expand Up @@ -118,16 +98,12 @@ class FesDuringSetupConsumerFlowTest : BaseFesDuringSetupFlowTest() {

override fun handleClientConfigurationAPI(gson: Gson): MockResponse {
val responseCode = when (testNameRule.methodName) {
"testFesServerAvailableGetClientConfigurationFailed" -> HttpURLConnection.HTTP_FORBIDDEN
"testFesAvailableWrongServiceName" -> HttpURLConnection.HTTP_NOT_ACCEPTABLE
"testCallFesUrlToGetClientConfigurationForEnterpriseUser" -> HttpURLConnection.HTTP_UNAUTHORIZED
else -> HttpURLConnection.HTTP_OK
}

val body = when (testNameRule.methodName) {
"testFesServerAvailableGetClientConfigurationFailed",
"testFesAvailableWrongServiceName",
"testCallFesUrlToGetClientConfigurationForEnterpriseUser" -> null
"testFesAvailableWrongServiceName" -> null
else -> gson.toJson(
ClientConfigurationResponse(
clientConfiguration = ClientConfiguration(
Expand Down Expand Up @@ -224,6 +200,7 @@ class FesDuringSetupConsumerFlowTest : BaseFesDuringSetupFlowTest() {
@Test
fun testFesAvailableSuccess() {
setupAndClickSignInButton(genMockGoogleSignInAccountJson(EMAIL_FES_SUCCESS))
Thread.sleep(2000)
onView(withText(R.string.set_pass_phrase))
.check(matches(isDisplayed()))
}
Expand Down Expand Up @@ -261,7 +238,6 @@ class FesDuringSetupConsumerFlowTest : BaseFesDuringSetupFlowTest() {
private const val EMAIL_FES_HTTP_404 = "[email protected]"
private const val EMAIL_FES_HTTP_NOT_404_NOT_SUCCESS = "[email protected]"
private const val EMAIL_FES_NOT_ALLOWED_SERVER = "[email protected]"
private const val EMAIL_FES_ENFORCE_ATTESTER_SUBMIT = "[email protected]"
private const val EMAIL_FES_SUCCESS = "[email protected]"
private const val EMAIL_FES_SSL_ERROR = "[email protected]"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import okhttp3.mockwebserver.RecordedRequest
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.`is`
import org.hamcrest.Matchers.not
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
Expand All @@ -48,6 +49,7 @@ import java.util.concurrent.TimeUnit
*/
@MediumTest
@RunWith(AndroidJUnit4::class)
@Ignore("not completed")
class FesDuringSetupEnterpriseFlowTest : BaseFesDuringSetupFlowTest() {
@get:Rule
var ruleChain: TestRule = RuleChain
Expand Down

0 comments on commit 0786af1

Please sign in to comment.