Use the clock in the Generator Repo (#1032)

This commit is contained in:
David Perez
2024-02-16 16:12:38 -06:00
committed by Álison Fernandes
parent 7558a29922
commit 32f9b1bde6
3 changed files with 17 additions and 29 deletions

View File

@@ -40,7 +40,7 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.onStart
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch
import java.time.Instant
import java.time.Clock
import javax.inject.Singleton
import kotlin.math.max
@@ -50,6 +50,7 @@ import kotlin.math.max
@Singleton
@Suppress("LongParameterList")
class GeneratorRepositoryImpl(
private val clock: Clock,
private val generatorSdkSource: GeneratorSdkSource,
private val generatorDiskSource: GeneratorDiskSource,
private val authDiskSource: AuthDiskSource,
@@ -119,7 +120,7 @@ class GeneratorRepositoryImpl(
onSuccess = { generatedPassword ->
val passwordHistoryView = PasswordHistoryView(
password = generatedPassword,
lastUsedDate = Instant.now(),
lastUsedDate = clock.instant(),
)
if (shouldSave) {
@@ -141,7 +142,7 @@ class GeneratorRepositoryImpl(
onSuccess = { generatedPassphrase ->
val passwordHistoryView = PasswordHistoryView(
password = generatedPassphrase,
lastUsedDate = Instant.now(),
lastUsedDate = clock.instant(),
)
scope.launch {
storePasswordHistory(passwordHistoryView)

View File

@@ -13,6 +13,7 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import java.time.Clock
import javax.inject.Singleton
/**
@@ -25,6 +26,7 @@ object GeneratorRepositoryModule {
@Provides
@Singleton
fun provideGeneratorRepository(
clock: Clock,
generatorSdkSource: GeneratorSdkSource,
generatorDiskSource: GeneratorDiskSource,
authDiskSource: AuthDiskSource,
@@ -33,6 +35,7 @@ object GeneratorRepositoryModule {
dispatcherManager: DispatcherManager,
policyManager: PolicyManager,
): GeneratorRepository = GeneratorRepositoryImpl(
clock = clock,
generatorSdkSource = generatorSdkSource,
generatorDiskSource = generatorDiskSource,
authDiskSource = authDiskSource,