Coverage Summary for Class: AnonymousLoginUseCase (com.georgeci.moneysurfer.domain.usecase)

Class Method, % Branch, % Line, % Instruction, %
AnonymousLoginUseCase 100% (2/2) 100% (22/22) 100% (380/380)
AnonymousLoginUseCase$invoke$1
Total 100% (2/2) 100% (22/22) 100% (380/380)


 package com.georgeci.moneysurfer.domain.usecase
 
 import arrow.core.Either
 import arrow.core.raise.either
 import com.georgeci.moneysurfer.domain.auth.AuthError
 import com.georgeci.moneysurfer.domain.auth.AuthLocalRepository
 import com.georgeci.moneysurfer.domain.auth.SessionMutator
 import com.georgeci.moneysurfer.domain.repositories.AuthRemoteRepository
 import org.koin.core.annotation.Single
 
 @Single
 class AnonymousLoginUseCase(
     private val authRemoteRepository: AuthRemoteRepository,
     private val authLocalRepository: AuthLocalRepository,
     private val sessionMutator: SessionMutator,
     private val wipeDemoDataUseCase: WipeDemoDataUseCase,
     private val postAuthBootstrap: PostAuthBootstrapUseCase,
     private val abandonAuthSession: AbandonAuthSessionUseCase,
 ) {
     suspend operator fun invoke(): Either<AuthError, PostAuthBootstrapUseCase.Result> = either {
         val uid = authRemoteRepository.signInAnonymously().bind()
 
         // Drop any demo data BEFORE pinning the real session (sync.md §2.11).
         wipeDemoDataUseCase()
 
         authLocalRepository.createLocalUser(
             uid = uid,
             email = null,
             displayName = null,
             isAnon = true,
         )
         sessionMutator.setFirebaseUid(uid)
 
         // Roll the pointers back when the bootstrap fails — see [LoginUseCase] for why the
         // pins cannot simply be deferred until after it (issue #342).
         postAuthBootstrap(
             uid = uid,
             email = null,
             displayName = null,
             isAnon = true,
         ).onLeft { abandonAuthSession(isAnon = true) }.bind()
     }
 }