Skip to content

Commit

Permalink
Merge branch 'e2e-tests-failing-in-firebase-due-to-rate-limiting-droi…
Browse files Browse the repository at this point in the history
…d-1261'
  • Loading branch information
albin-mullvad committed Aug 20, 2024
2 parents 71cd682 + 1954b87 commit 0f2ec13
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,21 @@ import org.junit.jupiter.api.extension.BeforeEachCallback
import org.junit.jupiter.api.extension.ExtensionContext

class AccountTestRule : BeforeEachCallback {

private val partnerAccount: String?
private val client =
SimpleMullvadHttpClient(InstrumentationRegistry.getInstrumentation().targetContext)
private val partnerAuth: String? =
InstrumentationRegistry.getArguments().getString(PARTNER_AUTH, null)
lateinit var validAccountNumber: String
lateinit var invalidAccountNumber: String

val validAccountNumber: String
val invalidAccountNumber: String

init {
override fun beforeEach(context: ExtensionContext) {
InstrumentationRegistry.getArguments().also { bundle ->
partnerAccount = bundle.getString(PARTNER_AUTH)

if (partnerAccount != null) {
if (partnerAuth != null) {
validAccountNumber = client.createAccount()
client.addTimeToAccountUsingPartnerAuth(
accountNumber = validAccountNumber,
daysToAdd = 1,
partnerAuth = partnerAccount
partnerAuth = partnerAuth
)
} else {
validAccountNumber =
Expand All @@ -38,6 +35,4 @@ class AccountTestRule : BeforeEachCallback {
bundle.getRequiredArgument(INVALID_TEST_ACCOUNT_NUMBER_ARGUMENT_KEY)
}
}

override fun beforeEach(context: ExtensionContext) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import androidx.test.services.events.TestEventException
import co.touchlab.kermit.Logger
import com.android.volley.Request
import com.android.volley.VolleyError
import com.android.volley.toolbox.JsonArrayRequest
import com.android.volley.toolbox.JsonObjectRequest
import com.android.volley.toolbox.RequestFuture
Expand Down Expand Up @@ -106,8 +107,9 @@ class SimpleMullvadHttpClient(context: Context) {
authorizationHeader: String? = null
): JSONObject? {
val future = RequestFuture.newFuture<JSONObject>()

val request =
object : JsonObjectRequest(method, url, body, future, future) {
object : JsonObjectRequest(method, url, body, future, onErrorResponse) {
override fun getHeaders(): MutableMap<String, String> {
val headers = HashMap<String, String>()
if (body != null) {
Expand Down Expand Up @@ -136,7 +138,7 @@ class SimpleMullvadHttpClient(context: Context) {
): String? {
val future = RequestFuture.newFuture<String>()
val request =
object : StringRequest(method, url, future, future) {
object : StringRequest(method, url, future, onErrorResponse) {
override fun getHeaders(): MutableMap<String, String> {
val headers = HashMap<String, String>()
if (body != null) {
Expand Down Expand Up @@ -165,7 +167,7 @@ class SimpleMullvadHttpClient(context: Context) {
): JSONArray? {
val future = RequestFuture.newFuture<JSONArray>()
val request =
object : JsonArrayRequest(method, url, null, future, future) {
object : JsonArrayRequest(method, url, null, future, onErrorResponse) {
override fun getHeaders(): MutableMap<String, String> {
val headers = HashMap<String, String>()
headers.put("Content-Type", "application/json")
Expand All @@ -190,5 +192,9 @@ class SimpleMullvadHttpClient(context: Context) {
companion object {
private const val REQUEST_ERROR_MESSAGE =
"Unable to verify account due to invalid account or connectivity issues."

private val onErrorResponse = { error: VolleyError ->
Logger.e("Response returned error status code: ${error.networkResponse.statusCode}")
}
}
}

0 comments on commit 0f2ec13

Please sign in to comment.