Skip to content

Commit

Permalink
fix: unit test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
farhan-arshad-dev committed Dec 20, 2024
1 parent febbf22 commit bd7283d
Showing 1 changed file with 25 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ import org.openedx.core.domain.model.DashboardCourseList
import org.openedx.core.domain.model.IAPConfig
import org.openedx.core.domain.model.Pagination
import org.openedx.core.presentation.IAPAnalytics
import org.openedx.core.system.PushNotifier
import org.openedx.core.system.ResourceManager
import org.openedx.core.system.connection.NetworkConnection
import org.openedx.core.system.notifier.CourseDashboardUpdate
import org.openedx.core.system.notifier.CourseDataUpdated
import org.openedx.core.system.notifier.DiscoveryNotifier
import org.openedx.core.system.notifier.IAPNotifier
import org.openedx.core.system.notifier.PushEvent
import org.openedx.core.system.notifier.app.AppNotifier
import org.openedx.dashboard.domain.interactor.DashboardInteractor
import java.net.UnknownHostException
Expand All @@ -61,6 +63,7 @@ class DashboardViewModelTest {
private val networkConnection = mockk<NetworkConnection>()
private val discoveryNotifier = mockk<DiscoveryNotifier>()
private val iapNotifier = mockk<IAPNotifier>()
private val pushNotifier = mockk<PushNotifier>()
private val analytics = mockk<DashboardAnalytics>()
private val appNotifier = mockk<AppNotifier>()
private val iapAnalytics = mockk<IAPAnalytics>()
Expand Down Expand Up @@ -112,11 +115,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)
coEvery { interactor.getEnrolledCourses(any()) } throws UnknownHostException()
advanceUntilIdle()
Expand All @@ -143,11 +147,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

coEvery { interactor.getEnrolledCourses(any()) } throws Exception()
Expand Down Expand Up @@ -175,11 +180,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

coEvery { interactor.getEnrolledCourses(any()) } returns dashboardCourseList
Expand Down Expand Up @@ -207,11 +213,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

coEvery { interactor.getEnrolledCourses(any()) } returns dashboardCourseList.copy(
Expand Down Expand Up @@ -248,11 +255,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

advanceUntilIdle()
Expand All @@ -278,11 +286,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

coEvery { interactor.getEnrolledCourses(any()) } throws UnknownHostException()
Expand Down Expand Up @@ -312,11 +321,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

coEvery { interactor.getEnrolledCourses(any()) } throws Exception()
Expand All @@ -340,6 +350,7 @@ class DashboardViewModelTest {
coEvery { interactor.getEnrolledCourses(any()) } returns dashboardCourseList
coEvery { iapNotifier.notifier } returns flow { emit(CourseDataUpdated()) }
coEvery { iapNotifier.send(any<CourseDataUpdated>()) } returns Unit
coEvery { pushNotifier.send(any<PushEvent.RefreshPushEvent>()) } returns Unit

val viewModel = DashboardListViewModel(
context,
Expand All @@ -349,11 +360,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

viewModel.updateCourses()
Expand Down Expand Up @@ -383,6 +395,7 @@ class DashboardViewModelTest {
)
coEvery { iapNotifier.notifier } returns flow { emit(CourseDataUpdated()) }
coEvery { iapNotifier.send(any<CourseDataUpdated>()) } returns Unit
coEvery { pushNotifier.send(any<PushEvent.RefreshPushEvent>()) } returns Unit

val viewModel = DashboardListViewModel(
context,
Expand All @@ -392,11 +405,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

viewModel.updateCourses()
Expand Down Expand Up @@ -425,11 +439,12 @@ class DashboardViewModelTest {
resourceManager,
discoveryNotifier,
iapNotifier,
pushNotifier,
analytics,
appNotifier,
corePreferences,
iapInteractor,
iapAnalytics,
iapInteractor
)

val mockLifeCycleOwner: LifecycleOwner = mockk()
Expand Down

0 comments on commit bd7283d

Please sign in to comment.