Skip to content
Open
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 @@ -22,6 +22,7 @@ import com.duckduckgo.di.scopes.ActivityScope
import com.duckduckgo.pir.impl.dashboard.state.PirDashboardInitialScanStateProvider.DashboardBrokerWithStatus
import com.duckduckgo.pir.impl.dashboard.state.PirDashboardInitialScanStateProvider.DashboardBrokerWithStatus.Status.COMPLETED
import com.duckduckgo.pir.impl.dashboard.state.PirDashboardInitialScanStateProvider.DashboardBrokerWithStatus.Status.IN_PROGRESS
import com.duckduckgo.pir.impl.dashboard.state.PirDashboardInitialScanStateProvider.DashboardBrokerWithStatus.Status.NOT_STARTED
import com.duckduckgo.pir.impl.store.PirRepository
import com.duckduckgo.pir.impl.store.PirSchedulingRepository
import com.squareup.anvil.annotations.ContributesBinding
Expand Down Expand Up @@ -110,6 +111,6 @@ class RealPirDashboardInitialScanStateProvider @Inject constructor(
}

override suspend fun getScanResults(): List<DashboardExtractedProfileResult> {
return getAllExtractedProfileResults()
return getAllExtractedProfileResults(includeResultsForDeprecatedProfileQueries = false)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,13 @@ class RealPirDashboardMaintenanceScanDataProvider @Inject constructor(
private val pirSchedulingRepository: PirSchedulingRepository,
) : PirDashboardStateProvider(currentTimeProvider, pirRepository, pirSchedulingRepository), PirDashboardMaintenanceScanDataProvider {
override suspend fun getInProgressOptOuts(): List<DashboardExtractedProfileResult> = withContext(dispatcherProvider.io()) {
return@withContext getAllExtractedProfileResults().filter {
return@withContext getAllExtractedProfileResults(includeResultsForDeprecatedProfileQueries = false).filter {
it.optOutRemovedDateInMillis == null || it.optOutRemovedDateInMillis == 0L
}
}

override suspend fun getRemovedOptOuts(): List<DashboardRemovedExtractedProfileResult> = withContext(dispatcherProvider.io()) {
val allRemovedExtractedProfiles = getAllExtractedProfileResults().filter {
val allRemovedExtractedProfiles = getAllExtractedProfileResults(includeResultsForDeprecatedProfileQueries = true).filter {
it.optOutRemovedDateInMillis != null && it.optOutRemovedDateInMillis != 0L
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@ abstract class PirDashboardStateProvider(
private val pirRepository: PirRepository,
private val pirSchedulingRepository: PirSchedulingRepository,
) {
suspend fun getAllExtractedProfileResults(): List<DashboardExtractedProfileResult> {
suspend fun getAllExtractedProfileResults(includeResultsForDeprecatedProfileQueries: Boolean): List<DashboardExtractedProfileResult> {
val nonDeprecatedProfileQueries = pirRepository.getValidUserProfileQueries().map { it.id }.toSet()
val extractedProfiles = pirRepository.getAllExtractedProfiles().filter {
!it.deprecated
!it.deprecated && (includeResultsForDeprecatedProfileQueries || it.profileQueryId in nonDeprecatedProfileQueries)
}
val extractedProfilesFromBrokers = getAllExtractedProfileResultForBrokers(extractedProfiles)
val extractedProfilesFromMirrorSites = extractedProfilesFromBrokers.getMirrorSites(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import com.duckduckgo.pir.impl.models.AddressCityState
import com.duckduckgo.pir.impl.models.Broker
import com.duckduckgo.pir.impl.models.ExtractedProfile
import com.duckduckgo.pir.impl.models.MirrorSite
import com.duckduckgo.pir.impl.models.ProfileQuery
import com.duckduckgo.pir.impl.models.scheduling.JobRecord.OptOutJobRecord
import com.duckduckgo.pir.impl.models.scheduling.JobRecord.OptOutJobRecord.OptOutJobStatus
import com.duckduckgo.pir.impl.models.scheduling.JobRecord.ScanJobRecord
Expand Down Expand Up @@ -338,6 +339,7 @@ class RealPirDashboardInitialScanStateProviderTest {
whenever(mockPirRepository.getAllBrokerOptOutUrls()).thenReturn(emptyMap())
whenever(mockPirSchedulingRepository.getAllValidOptOutJobRecords()).thenReturn(emptyList())
whenever(mockPirRepository.getAllMirrorSites()).thenReturn(emptyList())
whenever(mockPirRepository.getValidUserProfileQueries()).thenReturn(emptyList())

// When
val result = testee.getScanResults()
Expand Down Expand Up @@ -396,11 +398,14 @@ class RealPirDashboardInitialScanStateProviderTest {
)
val brokerOptOutUrls = mapOf("broker1" to "https://broker1.com/optout")

val validProfileQueries = listOf(createProfileQuery(id = 1L))

whenever(mockPirRepository.getAllExtractedProfiles()).thenReturn(extractedProfiles)
whenever(mockPirRepository.getAllActiveBrokerObjects()).thenReturn(activeBrokers)
whenever(mockPirRepository.getAllBrokerOptOutUrls()).thenReturn(brokerOptOutUrls)
whenever(mockPirSchedulingRepository.getAllValidOptOutJobRecords()).thenReturn(optOutJobs)
whenever(mockPirRepository.getAllMirrorSites()).thenReturn(emptyList())
whenever(mockPirRepository.getValidUserProfileQueries()).thenReturn(validProfileQueries)

// When
val result = testee.getScanResults()
Expand Down Expand Up @@ -441,11 +446,14 @@ class RealPirDashboardInitialScanStateProviderTest {
),
)

val validProfileQueries = listOf(createProfileQuery(id = 1L))

whenever(mockPirRepository.getAllExtractedProfiles()).thenReturn(extractedProfiles)
whenever(mockPirRepository.getAllActiveBrokerObjects()).thenReturn(activeBrokers)
whenever(mockPirRepository.getAllBrokerOptOutUrls()).thenReturn(emptyMap())
whenever(mockPirSchedulingRepository.getAllValidOptOutJobRecords()).thenReturn(optOutJobs)
whenever(mockPirRepository.getAllMirrorSites()).thenReturn(emptyList())
whenever(mockPirRepository.getValidUserProfileQueries()).thenReturn(validProfileQueries)

// When
val result = testee.getScanResults()
Expand Down Expand Up @@ -494,11 +502,14 @@ class RealPirDashboardInitialScanStateProviderTest {
createBroker("broker3", parent = "broker1"), // broker2 is child of broker1
)

val validProfileQueries = listOf(createProfileQuery(id = 1L))

whenever(mockPirRepository.getAllExtractedProfiles()).thenReturn(extractedProfiles)
whenever(mockPirRepository.getAllActiveBrokerObjects()).thenReturn(activeBrokers)
whenever(mockPirRepository.getAllBrokerOptOutUrls()).thenReturn(emptyMap())
whenever(mockPirSchedulingRepository.getAllValidOptOutJobRecords()).thenReturn(emptyList())
whenever(mockPirRepository.getAllMirrorSites()).thenReturn(emptyList())
whenever(mockPirRepository.getValidUserProfileQueries()).thenReturn(validProfileQueries)

// When
val result = testee.getScanResults()
Expand Down Expand Up @@ -532,11 +543,14 @@ class RealPirDashboardInitialScanStateProviderTest {
),
)

val validProfileQueries = listOf(createProfileQuery(id = 1L))

whenever(mockPirRepository.getAllExtractedProfiles()).thenReturn(extractedProfiles)
whenever(mockPirRepository.getAllActiveBrokerObjects()).thenReturn(activeBrokers)
whenever(mockPirRepository.getAllBrokerOptOutUrls()).thenReturn(emptyMap())
whenever(mockPirSchedulingRepository.getAllValidOptOutJobRecords()).thenReturn(emptyList())
whenever(mockPirRepository.getAllMirrorSites()).thenReturn(mirrorSites)
whenever(mockPirRepository.getValidUserProfileQueries()).thenReturn(validProfileQueries)

// When
val result = testee.getScanResults()
Expand All @@ -553,6 +567,37 @@ class RealPirDashboardInitialScanStateProviderTest {
assertEquals("https://mirror1.com/optout", mirrorResult.broker.optOutUrl)
}

@Test
fun whenProfileQueryIsDeprecatedThenGetScanResultsFiltersItOut() = runTest {
// Given
val extractedProfiles = listOf(
createExtractedProfile(dbId = 1L, brokerName = "broker1", name = "John Doe", profileQueryId = 1L),
createExtractedProfile(dbId = 2L, brokerName = "broker1", name = "Jane Smith", profileQueryId = 2L),
createExtractedProfile(dbId = 3L, brokerName = "broker1", name = "Joe Smith", profileQueryId = 3L),
)
val activeBrokers = listOf(createBroker("broker1"))
// Only profile queries 1 and 3 are valid (non-deprecated), profile query 2 is deprecated
val validProfileQueries = listOf(
createProfileQuery(id = 1L),
createProfileQuery(id = 3L),
)

whenever(mockPirRepository.getAllExtractedProfiles()).thenReturn(extractedProfiles)
whenever(mockPirRepository.getAllActiveBrokerObjects()).thenReturn(activeBrokers)
whenever(mockPirRepository.getAllBrokerOptOutUrls()).thenReturn(emptyMap())
whenever(mockPirSchedulingRepository.getAllValidOptOutJobRecords()).thenReturn(emptyList())
whenever(mockPirRepository.getAllMirrorSites()).thenReturn(emptyList())
whenever(mockPirRepository.getValidUserProfileQueries()).thenReturn(validProfileQueries)

// When
val result = testee.getScanResults()

// Then - profile 2 (Jane Smith) should be filtered out because its profile query is deprecated
assertEquals(2, result.size)
assertEquals("John Doe", result[0].extractedProfile.name)
assertEquals("Joe Smith", result[1].extractedProfile.name)
}

private suspend fun setupForEmptyBrokersAndJobs() {
whenever(mockPirRepository.getAllActiveBrokerObjects()).thenReturn(emptyList())
whenever(mockPirRepository.getAllBrokerOptOutUrls()).thenReturn(emptyMap())
Expand Down Expand Up @@ -614,6 +659,7 @@ class RealPirDashboardInitialScanStateProviderTest {
dbId: Long,
brokerName: String,
name: String,
profileQueryId: Long = 1L,
age: String = "30",
addresses: List<AddressCityState> = emptyList(),
alternativeNames: List<String> = emptyList(),
Expand All @@ -623,7 +669,7 @@ class RealPirDashboardInitialScanStateProviderTest {
): ExtractedProfile {
return ExtractedProfile(
dbId = dbId,
profileQueryId = 1L,
profileQueryId = profileQueryId,
brokerName = brokerName,
name = name,
alternativeNames = alternativeNames,
Expand Down Expand Up @@ -652,4 +698,23 @@ class RealPirDashboardInitialScanStateProviderTest {
removedAt = removedAt,
)
}

private fun createProfileQuery(
id: Long,
firstName: String = "John",
lastName: String = "Doe",
): ProfileQuery {
return ProfileQuery(
id = id,
firstName = firstName,
lastName = lastName,
city = "New York",
state = "NY",
addresses = emptyList(),
birthYear = 1990,
fullName = "$firstName $lastName",
age = 34,
deprecated = false,
)
}
}
Loading
Loading