Skip to content

Commit

Permalink
[ANDROAPP-6028] move test to correct module
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed May 10, 2024
1 parent e98462f commit 4ee56ad
Showing 1 changed file with 31 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package org.dhis2.data.forms
package org.dhis2.mobileProgramRules

import kotlinx.coroutines.runBlocking
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.android.core.organisationunit.OrganisationUnitGroup
import org.hisp.dhis.android.core.user.UserRole
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito
Expand All @@ -30,24 +32,23 @@ class RulesRepositoryTest {
.blockingGet(),
) doReturn getTestOrgUnit()
whenever(d2.userModule().userRoles().blockingGet()) doReturn getTestUserRoles()
val testObserver = repository.supplementaryData("org_unit_test")
.test()

testObserver.assertValueCount(1)
testObserver.assertValue { supplData ->

supplData.containsKey("USER")
supplData.containsKey("org_unit_group_test_code")
supplData.containsKey("org_unit_group_test")
supplData.getOrElse("USER") { arrayListOf() }
.contains("role1")
supplData.getOrElse("USER") { arrayListOf() }
.contains("role2")
val supplData = runBlocking {
repository.supplementaryData("org_unit_test")
}
assertTrue(supplData.isNotEmpty())
assertTrue(supplData.containsKey("USER"))
assertTrue(supplData.containsKey("org_unit_group_test_code"))
assertTrue(supplData.containsKey("org_unit_group_test"))
assertTrue(supplData.getOrElse("USER") { arrayListOf() }.contains("role1"))
assertTrue(supplData.getOrElse("USER") { arrayListOf() }.contains("role2"))
assertTrue(
supplData.getOrElse("org_unit_group_test") { arrayListOf() }
.contains("org_unit_test")
.contains("org_unit_test"),
)
assertTrue(
supplData.getOrElse("org_unit_group_test_code") { arrayListOf() }
.contains("org_unit_test")
}
.contains("org_unit_test"),
)
}

@Test
Expand All @@ -59,24 +60,22 @@ class RulesRepositoryTest {
.blockingGet(),
) doReturn getTestOrgUnitWithNullCodeGroup()
whenever(d2.userModule().userRoles().blockingGet()) doReturn getTestUserRoles()
val testObserver = repository.supplementaryData("org_unit_test")
.test()
val supplData = runBlocking {
repository.supplementaryData("org_unit_test")
}

testObserver.assertValueCount(1)
testObserver.assertValue { supplData ->
assertTrue(supplData.isNotEmpty())

supplData.containsKey("USER")
!supplData.containsKey("org_unit_group_test_code")
supplData.containsKey("org_unit_group_test")
supplData.getOrElse("USER") { arrayListOf() }
.contains("role1")
supplData.getOrElse("USER") { arrayListOf() }
.contains("role2")
assertTrue(supplData.containsKey("USER"))
assertTrue(!supplData.containsKey("org_unit_group_test_code"))
assertTrue(supplData.containsKey("org_unit_group_test"))
assertTrue(supplData.getOrElse("USER") { arrayListOf() }.contains("role1"))
assertTrue(supplData.getOrElse("USER") { arrayListOf() }.contains("role2"))
assertTrue(
supplData.getOrElse("org_unit_group_test") { arrayListOf() }
.contains("org_unit_test")
supplData.getOrElse("org_unit_group_test_code") { arrayListOf() }
.isEmpty()
}
.contains("org_unit_test"),
)
assertTrue(supplData.getOrElse("org_unit_group_test_code") { arrayListOf() }.isEmpty())
}

private fun getTestUserRoles(): List<UserRole> {
Expand Down

0 comments on commit 4ee56ad

Please sign in to comment.