Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 144ba93d authored by Hasib Prince's avatar Hasib Prince
Browse files

added unit test for loginviewmodel

parent aa651fe0
Loading
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@

package foundation.e.apps.data.gplay.utils

import androidx.annotation.VisibleForTesting
import com.aurora.gplayapi.data.models.PlayResponse
import com.aurora.gplayapi.network.IHttpClient
import foundation.e.apps.data.login.AuthObject
@@ -61,6 +62,7 @@ class GPlayHttpClient @Inject constructor(
        const val STATUS_CODE_TIMEOUT = 408
    }

    @VisibleForTesting
    var okHttpClient = OkHttpClient().newBuilder()
        .retryOnConnectionFailure(false)
        .callTimeout(HTTP_TIMEOUT_IN_SECOND, TimeUnit.SECONDS)
+0 −9
Original line number Diff line number Diff line
package foundation.e.apps

import foundation.e.apps.data.handleNetworkResult

class NetworkHandlerTest {

    fun testHandleNetworkResultWhenStatus401() {
    }
}
 No newline at end of file
+3 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps
package foundation.e.apps.fused

import android.content.Context
import android.text.format.Formatter
@@ -25,6 +25,8 @@ import com.aurora.gplayapi.data.models.App
import com.aurora.gplayapi.data.models.AuthData
import com.aurora.gplayapi.data.models.Category
import com.aurora.gplayapi.data.models.SearchBundle
import foundation.e.apps.FakePreferenceModule
import foundation.e.apps.R
import foundation.e.apps.data.cleanapk.data.categories.Categories
import foundation.e.apps.data.cleanapk.data.search.Search
import foundation.e.apps.data.cleanapk.repositories.CleanApkRepository
+1 −1
Original line number Diff line number Diff line
@@ -15,7 +15,7 @@
 *   along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps
package foundation.e.apps.fused

import foundation.e.apps.data.fused.FusedAPIRepository
import foundation.e.apps.data.fused.FusedApiImpl
+13 −10
Original line number Diff line number Diff line
@@ -16,10 +16,11 @@
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package foundation.e.apps
package foundation.e.apps.gplay

import com.aurora.gplayapi.data.models.PlayResponse
import foundation.e.apps.data.gplay.utils.GPlayHttpClient
import foundation.e.apps.data.login.AuthObject
import foundation.e.apps.util.FakeCall
import foundation.e.apps.util.MainCoroutineRule
import foundation.e.apps.utils.SystemInfoProvider
@@ -69,49 +70,49 @@ class GplyHttpClientTest {
    }

    @Test
    fun testPostMapFailWhenStatus401() = runTest {
    fun testPostWithMapFailedWhenStatus401() = runTest {
        initMocks()
        val response = gPlayHttpClient.post("http://abc.abc", mapOf(), mapOf())
        assertResponse(response)
    }

    @Test
    fun testPostRequestBodyFailWhenStatus401() = runTest {
    fun testPostWithRequestBodyFailedWhenStatus401() = runTest {
        initMocks()
        val response = gPlayHttpClient.post("http://abc.abc", mapOf(), "".toRequestBody())
        assertResponse(response)
    }

    @Test
    fun testPostByteArrayRequestBodyFailWhenStatus401() = runTest {
    fun testPostWithByteArrayFailedWhenStatus401() = runTest {
        initMocks()
        val response = gPlayHttpClient.post("http://abc.abc", mapOf(), "".toByteArray())
        assertResponse(response)
    }

    @Test
    fun testGetFailWhenStatus401() = runTest {
    fun testGetWithoutParamsFailedWhenStatus401() = runTest {
        initMocks()
        val response = gPlayHttpClient.get(FakeCall.FAKE_URL, mapOf())
        assertResponse(response)
    }

    @Test
    fun testGetParamStringFailWhenStatus401() = runTest {
    fun testGetWithStringParamsFailedWhenStatus401() = runTest {
        initMocks()
        val response = gPlayHttpClient.get(FakeCall.FAKE_URL, mapOf(), "")
        assertResponse(response)
    }

    @Test
    fun testGetMapFailWhenStatus401() = runTest {
    fun testGetWithMapParamsFailedWhenStatus401() = runTest {
        initMocks()
        val response = gPlayHttpClient.get(FakeCall.FAKE_URL, mapOf(), mapOf())
        assertResponse(response)
    }

    @Test
    fun testPostAuthFailWhenStatus401() = runTest {
    fun testPostAuthFailedWhenStatus401() = runTest {
        initMocks()
        val response = gPlayHttpClient.postAuth("http://abc.abc", "".toByteArray())
        assertResponse(response)
@@ -126,7 +127,9 @@ class GplyHttpClientTest {
    private suspend fun assertResponse(response: PlayResponse) {
        assertFalse(response.isSuccessful)
        assertTrue(response.code == 401)
        assertTrue(EventBus.events.first() is AppEvent.InvalidAuthEvent)
        val event = EventBus.events.first()
        assertTrue(event is AppEvent.InvalidAuthEvent)
        assertTrue(event.data is String)
        assertTrue(event.data == AuthObject.GPlayAuth::class.java.simpleName)
    }

}
Loading