diff --git a/feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCase.kt b/feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCase.kt index 082901a8b8..e1db51b63a 100644 --- a/feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCase.kt +++ b/feature/dashboard/src/main/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCase.kt @@ -210,6 +210,7 @@ internal class ObserveSyncInfoUseCase @Inject constructor( val recordsTotal = when { isEventSyncInProgress -> null + projectId.isBlank() -> null // without project ID, repository access attempts will throw an exception else -> enrolmentRecordRepository.count(SubjectQuery(projectId)) } val recordsToUpload = when { diff --git a/feature/dashboard/src/test/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCaseTest.kt b/feature/dashboard/src/test/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCaseTest.kt index 9c2c7a59e4..fa63f700d7 100644 --- a/feature/dashboard/src/test/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCaseTest.kt +++ b/feature/dashboard/src/test/java/com/simprints/feature/dashboard/settings/syncinfo/usecase/ObserveSyncInfoUseCaseTest.kt @@ -575,6 +575,24 @@ class ObserveSyncInfoUseCaseTest { assertThat(result.syncInfoSectionRecords.counterRecordsToDownload).isEqualTo("8") } + @Test + fun `should not count records when project id blank`() = runTest { + every { authStore.signedInProjectId } returns "" + every { authStore.observeSignedInProjectId() } returns MutableStateFlow("") + val mockIdleEventSyncState = mockk(relaxed = true) { + every { isSyncInProgress() } returns false + every { isSyncRunning() } returns false + } + every { eventSyncManager.getLastSyncState(any()) } returns MutableLiveData(mockIdleEventSyncState) + coEvery { enrolmentRecordRepository.count(any()) } returns 123 + createUseCase() + + val result = useCase().first() + + assertThat(result.syncInfoSectionRecords.counterTotalRecords).isEmpty() + coVerify(exactly = 0) { enrolmentRecordRepository.count(any()) } + } + @Test fun `should emit SyncInfo with empty record counters when sync in progress`() = runTest { val mockInProgressEventSyncState = mockk(relaxed = true) {