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 @@ -23,10 +23,15 @@ internal class ResetLocalRecordsIfConfigChangedUseCase @Inject constructor(
}
}

//
private fun hasPartitionTypeChanged(
oldConfig: ProjectConfiguration,
newConfig: ProjectConfiguration,
) = (oldConfig.synchronization.down.commCare != newConfig.synchronization.down.commCare) ||
(oldConfig.synchronization.down.simprints != newConfig.synchronization.down.simprints) ||
(oldConfig.synchronization.down.simprints?.partitionType != newConfig.synchronization.down.simprints?.partitionType)
// This also covers simprints changing from/to null since the partition will always be present if simprints is
(
oldConfig.synchronization.down.simprints
?.partitionType != newConfig.synchronization.down.simprints
?.partitionType
)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.simprints.infra.sync.config.usecase

import com.simprints.core.domain.tokenization.asTokenizableEncrypted
import com.simprints.infra.config.store.models.DownSynchronizationConfiguration
import com.simprints.infra.config.store.models.Frequency
import com.simprints.infra.enrolment.records.repository.EnrolmentRecordRepository
import com.simprints.infra.eventsync.EventSyncManager
import com.simprints.infra.sync.SyncOrchestrator
Expand Down Expand Up @@ -106,14 +108,15 @@ class ResetLocalRecordsIfConfigChangedUseCaseTest {
simprints = synchronizationConfiguration.down.simprints?.copy(
partitionType = DownSynchronizationConfiguration.PartitionType.PROJECT,
),
commCare = null,
),
),
),
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = null,
commCare = DownSynchronizationConfiguration.CommCareDownSynchronizationConfiguration
commCare = DownSynchronizationConfiguration.CommCareDownSynchronizationConfiguration,
),
),
),
Expand All @@ -134,7 +137,7 @@ class ResetLocalRecordsIfConfigChangedUseCaseTest {
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = null,
commCare = DownSynchronizationConfiguration.CommCareDownSynchronizationConfiguration
commCare = DownSynchronizationConfiguration.CommCareDownSynchronizationConfiguration,
),
),
),
Expand All @@ -144,6 +147,7 @@ class ResetLocalRecordsIfConfigChangedUseCaseTest {
simprints = synchronizationConfiguration.down.simprints?.copy(
partitionType = DownSynchronizationConfiguration.PartitionType.PROJECT,
),
commCare = null,
),
),
),
Expand All @@ -156,4 +160,128 @@ class ResetLocalRecordsIfConfigChangedUseCaseTest {
enrolmentRecordRepository.deleteAll()
}
}

@Test
fun `should not reset local records when sync frequency changes`() = runTest {
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.

Maybe we can add tests (or update this one) to check that other fields inside simprints don't cause a reset, just in case.

useCase(
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = synchronizationConfiguration.down.simprints?.copy(
frequency = Frequency.ONLY_PERIODICALLY_UP_SYNC,
),
),
),
),
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = synchronizationConfiguration.down.simprints?.copy(
frequency = Frequency.PERIODICALLY,
),
),
),
),
)

coVerify(exactly = 0) {
syncOrchestrator.cancelEventSync()
syncOrchestrator.rescheduleEventSync()
eventSyncManager.resetDownSyncInfo()
enrolmentRecordRepository.deleteAll()
}
}

@Test
fun `should not reset local records when sync modules changes`() = runTest {
useCase(
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = synchronizationConfiguration.down.simprints?.copy(
moduleOptions = listOf("One".asTokenizableEncrypted(), "Two".asTokenizableEncrypted()),
),
),
),
),
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = synchronizationConfiguration.down.simprints?.copy(
moduleOptions = listOf("Three".asTokenizableEncrypted()),
),
),
),
),
)

coVerify(exactly = 0) {
syncOrchestrator.cancelEventSync()
syncOrchestrator.rescheduleEventSync()
eventSyncManager.resetDownSyncInfo()
enrolmentRecordRepository.deleteAll()
}
}

@Test
fun `should not reset local records when sync max age changes`() = runTest {
useCase(
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = synchronizationConfiguration.down.simprints?.copy(
maxAge = "PT24H",
),
),
),
),
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = synchronizationConfiguration.down.simprints?.copy(
maxAge = "PT12H",
),
),
),
),
)

coVerify(exactly = 0) {
syncOrchestrator.cancelEventSync()
syncOrchestrator.rescheduleEventSync()
eventSyncManager.resetDownSyncInfo()
enrolmentRecordRepository.deleteAll()
}
}

@Test
fun `should not reset local records when sync module count changes`() = runTest {
useCase(
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = synchronizationConfiguration.down.simprints?.copy(
maxNbOfModules = 2,
),
),
),
),
projectConfiguration.copy(
synchronization = synchronizationConfiguration.copy(
down = synchronizationConfiguration.down.copy(
simprints = synchronizationConfiguration.down.simprints?.copy(
maxNbOfModules = 5,
),
),
),
),
)

coVerify(exactly = 0) {
syncOrchestrator.cancelEventSync()
syncOrchestrator.rescheduleEventSync()
eventSyncManager.resetDownSyncInfo()
enrolmentRecordRepository.deleteAll()
}
}
}