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

Commit ea39de9b authored by Hasib Prince's avatar Hasib Prince
Browse files

Unit test added for privacy score

parent 485f0044
Loading
Loading
Loading
Loading
Loading
+23 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import org.mockito.Mock
import org.mockito.Mockito
import org.mockito.MockitoAnnotations
import org.mockito.kotlin.any
import org.mockito.kotlin.eq

class PrivacyScoreRepositoryImplTest {

@@ -50,7 +51,7 @@ class PrivacyScoreRepositoryImplTest {
            _id = "113",
            status = Status.UNAVAILABLE,
            name = "Demo Three",
            package_name = "a.b.c",
            package_name = "com.test.fakePackage",
            latest_version_code = 123,
            is_pwa = true,
            permsFromExodus = listOf(),
@@ -67,7 +68,7 @@ class PrivacyScoreRepositoryImplTest {
            _id = "113",
            status = Status.UNAVAILABLE,
            name = "Demo Three",
            package_name = "a.b.c",
            package_name = "com.test.fakePackage",
            latest_version_code = 123,
            is_pwa = true,
            perms = listOf(),
@@ -83,7 +84,7 @@ class PrivacyScoreRepositoryImplTest {
            _id = "113",
            status = Status.UNAVAILABLE,
            name = "Demo Three",
            package_name = "a.b.c",
            package_name = "com.test.fakePackage",
            latest_version_code = 123,
            is_pwa = true,
            permsFromExodus = listOf(),
@@ -93,4 +94,23 @@ class PrivacyScoreRepositoryImplTest {
        val privacyScore = privacyScoreRepository.calculatePrivacyScore(application)
        Assert.assertEquals("failed to retrieve valid privacy score", 9, privacyScore)
    }

    @Test
    fun `test calculate privacyScore for the app are available in privacyScoreZero applist`() {
        val application = Application(
            _id = "113",
            status = Status.UNAVAILABLE,
            name = "Demo Three",
            package_name = "com.test.fakePackage.privacyZero",
            latest_version_code = 123,
            is_pwa = true,
            permsFromExodus = listOf(),
            perms = listOf(),
            trackers = CommonUtilsModule.LIST_OF_NULL
        )
        Mockito.`when`(blockedAppRepository.isPrivacyScoreZero(eq("com.test.fakePackage.privacyZero"))).thenReturn(true)

        val privacyScore = privacyScoreRepository.calculatePrivacyScore(application)
        Assert.assertEquals("privacy score zero", 0, privacyScore)
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -115,7 +115,7 @@ class GplyHttpClientTest {
    @Test
    fun testPostAuthFailedWhenStatus401() = runTest {
        initMocksForStatus401()
        val response = gPlayHttpClient.postAuth("http://abc.abc", "".toByteArray())
        val response = gPlayHttpClient.postAuth(FakeCall.FAKE_URL, "".toByteArray())
        assertResponse(response)
    }

@@ -123,7 +123,7 @@ class GplyHttpClientTest {
    fun testPostAuthFailedWhenStatus429() = runTest {
        initMocksForStatus429()
        try {
            gPlayHttpClient.postAuth("http://abc.abc", "".toByteArray())
            gPlayHttpClient.postAuth(FakeCall.FAKE_URL, "".toByteArray())
        } catch (e: Exception) {
            assert429(e)
        }
+3 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ class FakeCall : Call {
    var willThrow429 = false

    companion object {
        const val FAKE_URL = "https://abc.abc"
        const val FAKE_URL = "https://murena.test"
    }

    private val fakeRequest = Request.Builder().url(FAKE_URL).build()
@@ -55,11 +55,13 @@ class FakeCall : Call {
            .message("")
            .code(401)
            .body("".toResponseBody())

        if (willThrow401) {
            builder.code(401)
        } else if (willThrow429) {
            builder.code(429)
        }

        return builder.build()
    }