Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can it also be null in some cases?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

authStore.signedInProjectId returns a non-null string.

else -> enrolmentRecordRepository.count(SubjectQuery(projectId))
}
val recordsToUpload = when {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventSyncState>(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<EventSyncState>(relaxed = true) {
Expand Down