Skip to content

Commit

Permalink
[ANDROAPP-5787] add test
Browse files Browse the repository at this point in the history
Signed-off-by: Pablo <[email protected]>
  • Loading branch information
Balcan committed Apr 25, 2024
1 parent 2a05d35 commit 6df390a
Showing 1 changed file with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,17 @@ import org.dhis2.form.ui.FieldViewModelFactory
import org.hisp.dhis.android.core.D2
import org.hisp.dhis.android.core.arch.repositories.scope.RepositoryScope.OrderByDirection.DESC
import org.hisp.dhis.android.core.event.Event
import org.hisp.dhis.android.core.organisationunit.OrganisationUnit
import org.hisp.dhis.android.core.program.ProgramStage
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import org.mockito.Mockito
import org.mockito.kotlin.any
import org.mockito.kotlin.doReturn
import org.mockito.kotlin.mock
import org.mockito.kotlin.times
import org.mockito.kotlin.verify
import org.mockito.kotlin.whenever
import java.util.Date

Expand Down Expand Up @@ -156,6 +160,48 @@ class EventDetailsRepositoryTest {
assertEquals(repository.getStageLastDate(ENROLLMENT_UID), date)
}

@Test
fun `should use search scope in referral`() {
whenever(
d2.organisationUnitModule().organisationUnits()
.byOrganisationUnitScope(any()),
) doReturn mock()
whenever(
d2.organisationUnitModule().organisationUnits()
.byOrganisationUnitScope(any())
.byProgramUids(any()),
) doReturn mock()
whenever(
d2.organisationUnitModule().organisationUnits()
.byOrganisationUnitScope(any())
.byProgramUids(any())
.blockingGet(),
) doReturn listOf()

EventCreationType.entries.forEach { eventCreationType ->
repository = EventDetailsRepository(
d2,
PROGRAM_UID,
EVENT_UID,
PROGRAM_STAGE_UID,
fieldViewModelFactory,
eventCreationType,
) { d2Error -> "" }

repository.getOrganisationUnits()
}

verify(
d2.organisationUnitModule().organisationUnits(),
times(1),
).byOrganisationUnitScope(OrganisationUnit.Scope.SCOPE_TEI_SEARCH)

verify(
d2.organisationUnitModule().organisationUnits(),
times(3),
).byOrganisationUnitScope(OrganisationUnit.Scope.SCOPE_DATA_CAPTURE)
}

companion object {
const val PROGRAM_UID = "programUid"
const val EVENT_UID = "eventUid"
Expand Down

0 comments on commit 6df390a

Please sign in to comment.