Skip to content

Commit

Permalink
Close autofill survey (#4576)
Browse files Browse the repository at this point in the history
Task/Issue URL:
https://app.asana.com/0/608920331025315/1207370057643957/f

### Description
Closes the autofill survey.

The PR has two commits (might help to view them separately):
1. a small refactor to make it easier to remove the active survey
without having to delete useful tests
2. the actual removal of the survey

### Steps to test this PR

- [ ] Clean app install
- [ ] Visit Password management screen; verify the survey prompt is
**not shown**
  • Loading branch information
CDRussell authored May 22, 2024
1 parent a8dc394 commit 77fcbb6
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsVie
import com.duckduckgo.autofill.impl.ui.credential.management.neversaved.NeverSavedSitesViewState
import com.duckduckgo.autofill.impl.ui.credential.management.searching.CredentialListFilter
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurvey
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurvey.SurveyDetails
import com.duckduckgo.autofill.impl.ui.credential.management.survey.SurveyDetails
import com.duckduckgo.autofill.impl.ui.credential.management.viewing.duckaddress.DuckAddressIdentifier
import com.duckduckgo.autofill.impl.ui.credential.repository.DuckAddressStatusRepository
import com.duckduckgo.autofill.impl.ui.credential.repository.DuckAddressStatusRepository.ActivationStatusResult
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.duckduckgo.app.statistics.store.StatisticsDataStore
import com.duckduckgo.app.usage.app.AppDaysUsedRepository
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.autofill.impl.store.InternalAutofillStore
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurvey.SurveyDetails
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurveyImpl.Companion.SurveyParams.IN_APP
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurveyImpl.Companion.SurveyParams.NUMBER_PASSWORD_BUCKET_LOTS
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurveyImpl.Companion.SurveyParams.NUMBER_PASSWORD_BUCKET_MANY
Expand All @@ -39,11 +38,6 @@ import kotlinx.coroutines.withContext
interface AutofillSurvey {
suspend fun firstUnusedSurvey(): SurveyDetails?
suspend fun recordSurveyAsUsed(id: String)

data class SurveyDetails(
val id: String,
val url: String,
)
}

@ContributesBinding(AppScope::class)
Expand All @@ -58,9 +52,11 @@ class AutofillSurveyImpl @Inject constructor(
) : AutofillSurvey {

override suspend fun firstUnusedSurvey(): SurveyDetails? {
if (!canShowSurvey()) return null
val survey = availableSurveys.firstOrNull { !surveyTakenPreviously(it.id) } ?: return null
return survey.copy(url = survey.url.addSurveyParameters())
return withContext(dispatchers.io()) {
if (!canShowSurvey()) return@withContext null
val survey = autofillSurveyStore.availableSurveys().firstOrNull { !surveyTakenPreviously(it.id) } ?: return@withContext null
return@withContext survey.copy(url = survey.url.addSurveyParameters())
}
}

private fun canShowSurvey(): Boolean {
Expand Down Expand Up @@ -109,12 +105,6 @@ class AutofillSurveyImpl @Inject constructor(
}

companion object {
private val availableSurveys = listOf(
SurveyDetails(
id = "autofill-2024-04-26",
url = "https://selfserve.decipherinc.com/survey/selfserve/32ab/240308",
),
)

private object SurveyParams {
const val ATB = "atb"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ interface AutofillSurveyStore {
suspend fun hasSurveyBeenTaken(id: String): Boolean
suspend fun recordSurveyWasShown(id: String)
suspend fun resetPreviousSurveys()
suspend fun availableSurveys(): List<SurveyDetails>
}

@ContributesBinding(AppScope::class)
Expand Down Expand Up @@ -69,6 +70,10 @@ class AutofillSurveyStoreImpl @Inject constructor(
}
}

override suspend fun availableSurveys(): List<SurveyDetails> {
return emptyList()
}

companion object {
private const val PREFS_FILE_NAME = "autofill_survey_store"
private const val SURVEY_IDS = "survey_ids"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Copyright (c) 2024 DuckDuckGo
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.duckduckgo.autofill.impl.ui.credential.management.survey

data class SurveyDetails(
val id: String,
val url: String,
)
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ import com.duckduckgo.autofill.impl.ui.credential.management.sorting.CredentialG
import com.duckduckgo.autofill.impl.ui.credential.management.sorting.InitialExtractor
import com.duckduckgo.autofill.impl.ui.credential.management.suggestion.SuggestionListBuilder
import com.duckduckgo.autofill.impl.ui.credential.management.suggestion.SuggestionMatcher
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurvey.SurveyDetails
import com.duckduckgo.autofill.impl.ui.credential.management.survey.SurveyDetails
import com.duckduckgo.common.ui.DuckDuckGoFragment
import com.duckduckgo.common.ui.view.MessageCta.Message
import com.duckduckgo.common.ui.view.SearchBar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsVie
import com.duckduckgo.autofill.impl.ui.credential.management.AutofillSettingsViewModel.ListModeCommand.PromptUserToAuthenticateMassDeletion
import com.duckduckgo.autofill.impl.ui.credential.management.searching.CredentialListFilter
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurvey
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurvey.SurveyDetails
import com.duckduckgo.autofill.impl.ui.credential.management.survey.SurveyDetails
import com.duckduckgo.autofill.impl.ui.credential.management.viewing.duckaddress.DuckAddressIdentifier
import com.duckduckgo.autofill.impl.ui.credential.management.viewing.duckaddress.RealDuckAddressIdentifier
import com.duckduckgo.autofill.impl.ui.credential.repository.DuckAddressStatusRepository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.core.net.toUri
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.duckduckgo.appbuildconfig.api.AppBuildConfig
import com.duckduckgo.autofill.impl.store.InternalAutofillStore
import com.duckduckgo.autofill.impl.ui.credential.management.survey.AutofillSurvey.SurveyDetails
import com.duckduckgo.common.test.CoroutineTestRule
import java.util.*
import kotlinx.coroutines.flow.flowOf
Expand Down Expand Up @@ -42,10 +41,21 @@ class AutofillSurveyImplTest {
whenever(appBuildConfig.deviceLocale).thenReturn(Locale("en"))

coroutineTestRule.testScope.runTest {
whenever(autofillSurveyStore.availableSurveys()).thenReturn(
listOf(
SurveyDetails("autofill-2024-04-26", "https://example.com/survey"),
),
)
configureCredentialCount(0)
}
}

@Test
fun whenNoSurveyAvailableThenFirstUnusedSurveyReturnsNull() = runTest {
whenever(autofillSurveyStore.availableSurveys()).thenReturn(emptyList())
assertNull(testee.firstUnusedSurvey())
}

@Test
fun whenSurveyHasNotBeenShownBeforeThenFirstUnusedSurveyReturnsIt() = runTest {
whenever(autofillSurveyStore.hasSurveyBeenTaken("autofill-2024-04-26")).thenReturn(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ class AutofillSurveyStoreImplTest {
testee.recordSurveyWasShown("surveyId-3")
assertTrue(testee.hasSurveyBeenTaken("surveyId-2"))
}

@Test
fun whenAvailableSurveysCalledThenOneSurveyReturned() = runTest {
assertEquals(0, testee.availableSurveys().size)
}
}

0 comments on commit 77fcbb6

Please sign in to comment.