Skip to content
This repository has been archived by the owner on Jun 17, 2024. It is now read-only.

Commit

Permalink
[components] For mozilla-mobile/android-components#12184 - Stop refre…
Browse files Browse the repository at this point in the history
…shing sponsored stories if profile is deleted

This also allows to easily start a "new" Worker to download stories again when
`startPeriodicStoriesRefresh` whereas we'd just enqueue the existing one which
may be set to only refresh the stories after a few hours still.
  • Loading branch information
Mugurell authored and mergify[bot] committed May 26, 2022
1 parent 225545b commit be7c336
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ class PocketStoriesService(
* Delete all stored user data used for downloading personalized sponsored stories.
*/
suspend fun deleteProfile(): Boolean {
stopPeriodicSponsoredStoriesRefresh()
return spocsUseCases?.deleteProfile?.invoke() ?: false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.doReturn
import org.mockito.Mockito.never
import org.mockito.Mockito.spy
import org.mockito.Mockito.times
import org.mockito.Mockito.verify
import java.util.UUID
import kotlin.reflect.KVisibility
Expand Down Expand Up @@ -167,14 +169,16 @@ class PocketStoriesServiceTest {

@Test
fun `GIVEN PocketStoriesService WHEN deleteProfile THEN delegate to spocs useCases`() = runTest {
val noProfileResponse = service.deleteProfile()
val mockedService = spy(service)
val noProfileResponse = mockedService.deleteProfile()
assertFalse(noProfileResponse)

val deleteProfileUseCase: DeleteProfile = mock()
doReturn(deleteProfileUseCase).`when`(spocsUseCases).deleteProfile
doReturn(true).`when`(deleteProfileUseCase).invoke()
val existingProfileResponse = service.deleteProfile()
val existingProfileResponse = mockedService.deleteProfile()
assertTrue(existingProfileResponse)
verify(mockedService, times(2)).stopPeriodicSponsoredStoriesRefresh()
}

@Test
Expand Down

0 comments on commit be7c336

Please sign in to comment.