diff --git a/ImageHaramBlur/src/main/java/com/london/imageharamblur/utils/BitmapBlur.kt b/ImageHaramBlur/src/main/java/com/london/imageharamblur/utils/bitmapBlur.kt similarity index 100% rename from ImageHaramBlur/src/main/java/com/london/imageharamblur/utils/BitmapBlur.kt rename to ImageHaramBlur/src/main/java/com/london/imageharamblur/utils/bitmapBlur.kt diff --git a/ImageHaramBlur/src/main/java/com/london/imageharamblur/utils/BitmapUtils.kt b/ImageHaramBlur/src/main/java/com/london/imageharamblur/utils/bitmapUtils.kt similarity index 100% rename from ImageHaramBlur/src/main/java/com/london/imageharamblur/utils/BitmapUtils.kt rename to ImageHaramBlur/src/main/java/com/london/imageharamblur/utils/bitmapUtils.kt diff --git a/data/src/main/java/com/london/data/local/preference/AppLanguage.kt b/data/src/main/java/com/london/data/local/preference/appLanguage.kt similarity index 100% rename from data/src/main/java/com/london/data/local/preference/AppLanguage.kt rename to data/src/main/java/com/london/data/local/preference/appLanguage.kt diff --git a/data/src/main/java/com/london/data/local/source/home/popular/PopularLocalDataSourceImpl.kt b/data/src/main/java/com/london/data/local/source/home/popular/PopularLocalDataSourceImpl.kt index b48453f35..030faf667 100644 --- a/data/src/main/java/com/london/data/local/source/home/popular/PopularLocalDataSourceImpl.kt +++ b/data/src/main/java/com/london/data/local/source/home/popular/PopularLocalDataSourceImpl.kt @@ -34,8 +34,8 @@ class PopularLocalDataSourceImpl @Inject constructor( private fun deleteExpiredData() { CoroutineScope(Dispatchers.IO).launch { - popularSectionDao.getAll().forEach { popularLocal -> - if (popularLocal.date.isDayExpired()) + popularSectionDao.getAll().forEach { _ -> + if (isDayExpired()) popularSectionDao.deleteAll() } } diff --git a/data/src/main/java/com/london/data/local/source/home/toprated/TopRatedDataSourceImpl.kt b/data/src/main/java/com/london/data/local/source/home/toprated/TopRatedDataSourceImpl.kt index 0c3aa4a00..f7cc235d3 100644 --- a/data/src/main/java/com/london/data/local/source/home/toprated/TopRatedDataSourceImpl.kt +++ b/data/src/main/java/com/london/data/local/source/home/toprated/TopRatedDataSourceImpl.kt @@ -36,7 +36,7 @@ class TopRatedDataSourceImpl @Inject constructor( private fun deleteExpiredData() { CoroutineScope(Dispatchers.IO).launch { topRatedDao.getAll().forEach { popularLocal -> - if (popularLocal.date.isDayExpired()) + if (isDayExpired()) topRatedDao.deleteAll() } } diff --git a/data/src/main/java/com/london/data/local/source/home/upcoming/UpComingLocalDataSourceImpl.kt b/data/src/main/java/com/london/data/local/source/home/upcoming/UpComingLocalDataSourceImpl.kt index 1e9902dce..98638e4d5 100644 --- a/data/src/main/java/com/london/data/local/source/home/upcoming/UpComingLocalDataSourceImpl.kt +++ b/data/src/main/java/com/london/data/local/source/home/upcoming/UpComingLocalDataSourceImpl.kt @@ -25,7 +25,7 @@ class UpComingLocalDataSourceImpl @Inject constructor( private fun deleteExpiredData() { CoroutineScope(Dispatchers.IO).launch { upcomingSectionDao.getAll().forEach { upcomingSectionLocal -> - if (upcomingSectionLocal.date.isDayExpired()) + if (isDayExpired()) upcomingSectionDao.deleteAll() } } diff --git a/data/src/main/java/com/london/data/local/utils/jsonList.kt b/data/src/main/java/com/london/data/local/utils/jsonList.kt deleted file mode 100644 index 630dd60cf..000000000 --- a/data/src/main/java/com/london/data/local/utils/jsonList.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.london.data.local.utils - -import com.google.gson.Gson -import com.google.gson.reflect.TypeToken - -inline fun Gson.jsonList(json: String): List = - fromJson(json, object : TypeToken>() {}.type) diff --git a/data/src/main/java/com/london/data/remote/model/ApiConstants.kt b/data/src/main/java/com/london/data/remote/model/ApiConstants.kt index c2e6af7bf..13d9e4385 100644 --- a/data/src/main/java/com/london/data/remote/model/ApiConstants.kt +++ b/data/src/main/java/com/london/data/remote/model/ApiConstants.kt @@ -1,7 +1,6 @@ package com.london.data.remote.model object ApiConstants { - const val SEARCH_PATH_MOVIES = "search/movie" const val SEARCH_PATH_TVS = "search/tv" const val SEARCH_PATH_ACTORS = "search/person" diff --git a/data/src/main/java/com/london/data/remote/model/toprated/TopRatedMovieRemote.kt b/data/src/main/java/com/london/data/remote/model/toprated/TopRatedMovieRemote.kt index 3b118e463..43de38c6c 100644 --- a/data/src/main/java/com/london/data/remote/model/toprated/TopRatedMovieRemote.kt +++ b/data/src/main/java/com/london/data/remote/model/toprated/TopRatedMovieRemote.kt @@ -1,6 +1,5 @@ package com.london.data.remote.model.toprated - import com.london.data.mapper.genre.GenreMapper import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/data/src/main/java/com/london/data/remote/model/toprated/TopRatedTvShowRemote.kt b/data/src/main/java/com/london/data/remote/model/toprated/TopRatedTvShowRemote.kt index bc2a7ac70..1cb57f357 100644 --- a/data/src/main/java/com/london/data/remote/model/toprated/TopRatedTvShowRemote.kt +++ b/data/src/main/java/com/london/data/remote/model/toprated/TopRatedTvShowRemote.kt @@ -1,6 +1,5 @@ package com.london.data.remote.model.toprated - import com.london.data.mapper.genre.GenreMapper import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable diff --git a/data/src/main/java/com/london/data/remote/service/account/AccountApiService.kt b/data/src/main/java/com/london/data/remote/service/account/AccountApiService.kt index d81fdb8e7..a6239d24a 100644 --- a/data/src/main/java/com/london/data/remote/service/account/AccountApiService.kt +++ b/data/src/main/java/com/london/data/remote/service/account/AccountApiService.kt @@ -9,7 +9,7 @@ import retrofit2.http.Query interface AccountApiService { @GET(ApiConstants.GET_ACCOUNT_DETAILS) - suspend fun getAccountDetails( + suspend fun getAccountInfo( @Query("session_id") sessionId: String ): Response diff --git a/data/src/main/java/com/london/data/remote/source/account/AccountRemoteDataSource.kt b/data/src/main/java/com/london/data/remote/source/account/AccountRemoteDataSource.kt index c960fd62b..4790a28d6 100644 --- a/data/src/main/java/com/london/data/remote/source/account/AccountRemoteDataSource.kt +++ b/data/src/main/java/com/london/data/remote/source/account/AccountRemoteDataSource.kt @@ -3,5 +3,5 @@ package com.london.data.remote.source.account import com.london.data.remote.model.account.AccountInfoResponse interface AccountRemoteDataSource { - suspend fun getAccountDetails(sessionId: String): Result + suspend fun getAccountInfo(sessionId: String): Result } diff --git a/data/src/main/java/com/london/data/remote/source/account/AccountRemoteDataSourceImpl.kt b/data/src/main/java/com/london/data/remote/source/account/AccountRemoteDataSourceImpl.kt index 31976419c..51ab69872 100644 --- a/data/src/main/java/com/london/data/remote/source/account/AccountRemoteDataSourceImpl.kt +++ b/data/src/main/java/com/london/data/remote/source/account/AccountRemoteDataSourceImpl.kt @@ -8,8 +8,8 @@ import javax.inject.Inject class AccountRemoteDataSourceImpl @Inject constructor( private val accountApiService: AccountApiService ) : AccountRemoteDataSource, BaseRemoteDatasource { - override suspend fun getAccountDetails(sessionId: String): Result = callApi( - apiCall = { accountApiService.getAccountDetails(sessionId) }, + override suspend fun getAccountInfo(sessionId: String): Result = callApi( + apiCall = { accountApiService.getAccountInfo(sessionId) }, mapper = { it } ) } diff --git a/data/src/main/java/com/london/data/repository/account/AccountRepositoryImpl.kt b/data/src/main/java/com/london/data/repository/account/AccountRepositoryImpl.kt index 875cc5d68..9db1ccedd 100644 --- a/data/src/main/java/com/london/data/repository/account/AccountRepositoryImpl.kt +++ b/data/src/main/java/com/london/data/repository/account/AccountRepositoryImpl.kt @@ -14,7 +14,7 @@ class AccountRepositoryImpl @Inject constructor( override suspend fun getAccountInfo(): AccountInfo = authenticationPreferences.getSessionId()?.let { sessionId -> - accountRemoteDataSource.getAccountDetails(sessionId) + accountRemoteDataSource.getAccountInfo(sessionId) .getOrThrow() .toEntity() } ?: AccountInfo(id = 0, userName = "", avatarPath = "") diff --git a/data/src/main/java/com/london/data/repository/authentication/AuthenticationRepositoryImpl.kt b/data/src/main/java/com/london/data/repository/authentication/AuthenticationRepositoryImpl.kt index 39b88f44b..fe17291dd 100644 --- a/data/src/main/java/com/london/data/repository/authentication/AuthenticationRepositoryImpl.kt +++ b/data/src/main/java/com/london/data/repository/authentication/AuthenticationRepositoryImpl.kt @@ -92,7 +92,7 @@ class AuthenticationRepositoryImpl @Inject constructor( } private suspend fun getUserAccount(session: SessionResponse) { - val accountResult = accountRemoteDataSource.getAccountDetails(session.sessionId.orEmpty()) + val accountResult = accountRemoteDataSource.getAccountInfo(session.sessionId.orEmpty()) val accountInfo = accountResult.getOrThrow().toEntity() val accountId = accountInfo.id saveUserAccount(id = accountId) diff --git a/data/src/main/java/com/london/data/repository/movie/MovieRepositoryImpl.kt b/data/src/main/java/com/london/data/repository/movie/MovieRepositoryImpl.kt index b9d08286b..8c13566f9 100644 --- a/data/src/main/java/com/london/data/repository/movie/MovieRepositoryImpl.kt +++ b/data/src/main/java/com/london/data/repository/movie/MovieRepositoryImpl.kt @@ -23,7 +23,7 @@ import com.london.data.mapper.search.toReviewEntity import com.london.data.remote.source.movie.MovieRemoteDataSource import com.london.data.utils.CrashReporter import com.london.data.utils.asYoutubeUrlOrEmpty -import com.london.data.utils.fetchAndSync +import com.london.data.utils.loadFromCacheOrFetch import com.london.domain.entity.actor.ActorMediaDetails import com.london.domain.entity.genre.MovieGenre import com.london.domain.entity.movie.Movie @@ -71,7 +71,7 @@ class MovieRepositoryImpl @Inject constructor( override suspend fun getMovieReviews( movieId: Int, pageNumber: Int - ): PagedFetchResponse = fetchAndSync( + ): PagedFetchResponse = loadFromCacheOrFetch( networkBlock = { getMovieReviewsFromRemote(movieId = movieId, pageNumber = pageNumber) } ).run { PagedFetchResponse( @@ -95,7 +95,7 @@ class MovieRepositoryImpl @Inject constructor( override suspend fun getUpcomingMoviesByGenre( genre: MovieGenre, pageNumber: Int - ): PagedFetchResponse = fetchAndSync( + ): PagedFetchResponse = loadFromCacheOrFetch( cacheBlock = { getUpComingCachedMovies(pageNumber = pageNumber, genre = genre) }, crashReporter = crashReporter, syncBlock = { upComingLocalDataSource.insert(it) }, @@ -110,7 +110,7 @@ class MovieRepositoryImpl @Inject constructor( } override suspend fun getTopRatedMovies(pageNumber: Int): PagedFetchResponse = - fetchAndSync( + loadFromCacheOrFetch( cacheBlock = { getTopRatedCashedMovies() }, networkBlock = { getTopRatedRemoteMovies(pageNumber) }, syncBlock = { topRatedMovies -> @@ -119,7 +119,7 @@ class MovieRepositoryImpl @Inject constructor( crashReporter = crashReporter ).run { getTopRatedPages(pageNumber) } - override suspend fun getFirstPageTopRatedMovies() = fetchAndSync( + override suspend fun getFirstPageTopRatedMovies() = loadFromCacheOrFetch( cacheBlock = { getTopRatedCashedMovies() }, networkBlock = { fetchFirstTopRatedPageMovies() }, syncBlock = { topRatedMovies -> @@ -156,7 +156,7 @@ class MovieRepositoryImpl @Inject constructor( ).isSuccess } - override suspend fun getPopularMovies(): List = fetchAndSync( + override suspend fun getPopularMovies(): List = loadFromCacheOrFetch( cacheBlock = { getCachedPopularMovies() }, networkBlock = { movieRemoteDataSource.getPopularMovies().getOrThrow().toPopularMovies() }, syncBlock = { popularList -> diff --git a/data/src/main/java/com/london/data/repository/tvshow/TvShowRepositoryImpl.kt b/data/src/main/java/com/london/data/repository/tvshow/TvShowRepositoryImpl.kt index 58c915269..a2759ce1a 100644 --- a/data/src/main/java/com/london/data/repository/tvshow/TvShowRepositoryImpl.kt +++ b/data/src/main/java/com/london/data/repository/tvshow/TvShowRepositoryImpl.kt @@ -22,7 +22,7 @@ import com.london.data.mapper.search.toReviewEntity import com.london.data.remote.source.tvshow.TvShowRemoteDataSource import com.london.data.utils.CrashReporter import com.london.data.utils.asYoutubeUrlOrEmpty -import com.london.data.utils.fetchAndSync +import com.london.data.utils.loadFromCacheOrFetch import com.london.domain.entity.actor.ActorMediaDetails import com.london.domain.entity.genre.TvShowGenre import com.london.domain.entity.popular.PopularMedia @@ -70,7 +70,7 @@ class TvShowRepositoryImpl @Inject constructor( override suspend fun getTopRatedTvShows( pageNumber: Int - ): PagedFetchResponse = fetchAndSync( + ): PagedFetchResponse = loadFromCacheOrFetch( cacheBlock = { getTopRatedCachedTvShows() }, networkBlock = { getTopRatedRemoteTvShows(pageNumber) }, syncBlock = { topRatedTvShows -> @@ -79,7 +79,7 @@ class TvShowRepositoryImpl @Inject constructor( crashReporter = crashReporter ).run { getTopRatedPages(pageNumber) } - override suspend fun getFirstPageTopRatedTvShows() = fetchAndSync( + override suspend fun getFirstPageTopRatedTvShows() = loadFromCacheOrFetch( cacheBlock = { getTopRatedCachedTvShows() }, networkBlock = { fetchFirstTopRatedPageTvShows() }, syncBlock = { topRatedTvShows -> @@ -114,7 +114,7 @@ class TvShowRepositoryImpl @Inject constructor( sessionId = authenticationPreferences.getSessionId() ).isSuccess - override suspend fun getPopularTvShows(): List = fetchAndSync( + override suspend fun getPopularTvShows(): List = loadFromCacheOrFetch( cacheBlock = { getCachedPopularTvShows() }, networkBlock = { tvShowRemoteDataSource.getPopularTvShows().getOrThrow().toPopularTvShows() }, syncBlock = { popularList -> @@ -181,7 +181,7 @@ class TvShowRepositoryImpl @Inject constructor( override suspend fun getTvShowReviews( tvShowId: Int, pageNumber: Int - ): PagedFetchResponse = fetchAndSync( + ): PagedFetchResponse = loadFromCacheOrFetch( networkBlock = { getTvShowReviewsFromRemote(tvShowId = tvShowId, pageNumber = pageNumber) } ).run { PagedFetchResponse( diff --git a/data/src/main/java/com/london/data/utils/constants.kt b/data/src/main/java/com/london/data/utils/appPreferences.kt similarity index 100% rename from data/src/main/java/com/london/data/utils/constants.kt rename to data/src/main/java/com/london/data/utils/appPreferences.kt diff --git a/data/src/main/java/com/london/data/utils/extensions.kt b/data/src/main/java/com/london/data/utils/extensions.kt index 8b221d17f..d03dd8559 100644 --- a/data/src/main/java/com/london/data/utils/extensions.kt +++ b/data/src/main/java/com/london/data/utils/extensions.kt @@ -35,7 +35,7 @@ fun String.extractYear() = fun Int.orDefault(default: Int = 1): Int = if (this != 0) this else default -fun Long.isDayExpired(): Boolean { +fun isDayExpired(): Boolean { val oneDayInMillis = 24 * 60 * 60 * 1000L val oneDayAgo = System.currentTimeMillis() - oneDayInMillis return System.currentTimeMillis() < oneDayAgo diff --git a/data/src/main/java/com/london/data/utils/fetchAndSync.kt b/data/src/main/java/com/london/data/utils/loadFromCacheOrFetch.kt similarity index 77% rename from data/src/main/java/com/london/data/utils/fetchAndSync.kt rename to data/src/main/java/com/london/data/utils/loadFromCacheOrFetch.kt index 70c2d9984..faefb72ef 100644 --- a/data/src/main/java/com/london/data/utils/fetchAndSync.kt +++ b/data/src/main/java/com/london/data/utils/loadFromCacheOrFetch.kt @@ -1,9 +1,6 @@ package com.london.data.utils -suspend fun Result.getNotNullOrElse(elseBlock: suspend () -> T): Result = - runCatching { getOrElse { elseBlock() } ?: elseBlock() } - -suspend fun fetchAndSync( +suspend fun loadFromCacheOrFetch( cacheBlock: (suspend () -> T?)? = null, networkBlock: suspend () -> T, syncBlock: (suspend (T) -> Unit)? = null, @@ -13,3 +10,6 @@ suspend fun fetchAndSync( syncBlock?.invoke(it) } }.onFailure { crashReporter?.logException(it) }.getOrThrow() + +private suspend fun Result.getNotNullOrElse(elseBlock: suspend () -> T): Result = + runCatching { getOrElse { elseBlock() } ?: elseBlock() } diff --git a/data/src/test/java/com/london/data/repository/AuthenticationRepositoryImplTest.kt b/data/src/test/java/com/london/data/repository/AuthenticationRepositoryImplTest.kt index db158de01..bc283d4ae 100644 --- a/data/src/test/java/com/london/data/repository/AuthenticationRepositoryImplTest.kt +++ b/data/src/test/java/com/london/data/repository/AuthenticationRepositoryImplTest.kt @@ -59,7 +59,7 @@ class AuthenticationRepositoryImplTest { coEvery { authRemoteDataSource.createSession(REQUEST_TOKEN) } returns Result.success( SessionResponse(true, SESSION_ID) ) - coEvery { accountRemoteDataSource.getAccountDetails(SESSION_ID) } returns Result.success( + coEvery { accountRemoteDataSource.getAccountInfo(SESSION_ID) } returns Result.success( AccountInfoResponse( id = ACCOUNT_ID, userName = USERNAME, @@ -78,7 +78,7 @@ class AuthenticationRepositoryImplTest { authenticationPreferences.setGuestMode(false) authenticationPreferences.saveAccountId(ACCOUNT_ID) } - coVerify { accountRemoteDataSource.getAccountDetails(SESSION_ID) } + coVerify { accountRemoteDataSource.getAccountInfo(SESSION_ID) } } @Test @@ -100,7 +100,7 @@ class AuthenticationRepositoryImplTest { assertFalse(result) coVerify(exactly = 0) { authenticationPreferences.saveSessionId(any()) } - coVerify(exactly = 0) { accountRemoteDataSource.getAccountDetails(any()) } + coVerify(exactly = 0) { accountRemoteDataSource.getAccountInfo(any()) } } @Test @@ -154,7 +154,7 @@ class AuthenticationRepositoryImplTest { coEvery { authRemoteDataSource.createSession(REQUEST_TOKEN) } returns Result.success( SessionResponse(true, SESSION_ID) ) - coEvery { accountRemoteDataSource.getAccountDetails(SESSION_ID) } returns Result.failure( + coEvery { accountRemoteDataSource.getAccountInfo(SESSION_ID) } returns Result.failure( accountError ) diff --git a/data/src/test/java/com/london/data/repository/SearchRepositoryImplTest.kt b/data/src/test/java/com/london/data/repository/SearchRepositoryImplTest.kt index 9402ca554..e9dd2cf8c 100644 --- a/data/src/test/java/com/london/data/repository/SearchRepositoryImplTest.kt +++ b/data/src/test/java/com/london/data/repository/SearchRepositoryImplTest.kt @@ -7,7 +7,7 @@ import com.london.data.remote.exception.ResponseException import com.london.data.remote.source.search.SearchRemoteDataSource import com.london.data.repository.search.SearchRepositoryImpl import com.london.data.utils.CrashReporter -import com.london.data.utils.fetchAndSync +import com.london.data.utils.loadFromCacheOrFetch import com.london.domain.entity.genre.MovieGenre import com.london.domain.entity.genre.TvShowGenre import io.mockk.coEvery @@ -52,7 +52,7 @@ class SearchRepositoryImplTest { val actualException = assertThrows( expectedException::class.java.simpleName ) { - fetchAndSync( + loadFromCacheOrFetch( cacheBlockAction, networkBlockAction, syncBlockAction, @@ -129,7 +129,7 @@ class SearchRepositoryImplTest { val actualException = assertThrows { - fetchAndSync( + loadFromCacheOrFetch( cacheBlock = { throw cacheException }, networkBlock = { throw networkException }, syncBlock = { /* Do nothing */ }, diff --git a/data/src/test/java/com/london/data/repository/account/AccountRepositoryImplTest.kt b/data/src/test/java/com/london/data/repository/account/AccountRepositoryImplTest.kt index bc2b81da7..c6dc74aee 100644 --- a/data/src/test/java/com/london/data/repository/account/AccountRepositoryImplTest.kt +++ b/data/src/test/java/com/london/data/repository/account/AccountRepositoryImplTest.kt @@ -43,7 +43,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -52,7 +52,7 @@ class AccountRepositoryImplTest { assertThat(result.userName).isEqualTo(expectedUsername) assertThat(result.id).isEqualTo(1) coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -68,7 +68,7 @@ class AccountRepositoryImplTest { assertThat(result.id).isEqualTo(0) assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify(exactly = 0) { remoteDataSource.getAccountDetails(any()) } + coVerify(exactly = 0) { remoteDataSource.getAccountInfo(any()) } } @Test @@ -78,7 +78,7 @@ class AccountRepositoryImplTest { val accountResponse = AccountInfoResponse(id = 1, userName = null, name = null, avatar = null) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -87,7 +87,7 @@ class AccountRepositoryImplTest { assertThat(result.userName).isEqualTo("") assertThat(result.id).isEqualTo(1) coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -97,7 +97,7 @@ class AccountRepositoryImplTest { val accountResponse = AccountInfoResponse(id = 1, userName = "", name = "", avatar = null) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -106,7 +106,7 @@ class AccountRepositoryImplTest { assertThat(result.userName).isEqualTo("") assertThat(result.id).isEqualTo(1) coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -116,7 +116,7 @@ class AccountRepositoryImplTest { val expectedException = RuntimeException("Network error") coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.failure(expectedException) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.failure(expectedException) // When & Then try { @@ -127,7 +127,7 @@ class AccountRepositoryImplTest { } coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -148,7 +148,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -159,7 +159,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("https://image.tmdb.org/t/p/w500/path/to/avatar.jpg") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -174,7 +174,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -185,7 +185,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -200,7 +200,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -211,7 +211,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -226,7 +226,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -237,7 +237,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -252,7 +252,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -263,7 +263,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -280,7 +280,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -291,7 +291,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -308,7 +308,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -319,7 +319,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("https://image.tmdb.org/t/p/w500") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -334,7 +334,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -345,7 +345,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -360,7 +360,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -371,7 +371,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -386,7 +386,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -397,7 +397,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -412,7 +412,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -423,7 +423,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -438,7 +438,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -449,7 +449,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -464,7 +464,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -476,7 +476,7 @@ class AccountRepositoryImplTest { // Verify coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } @Test @@ -493,7 +493,7 @@ class AccountRepositoryImplTest { assertThat(result.avatarPath).isEqualTo("") // Verify - coVerify(exactly = 0) { remoteDataSource.getAccountDetails(any()) } + coVerify(exactly = 0) { remoteDataSource.getAccountInfo(any()) } } @Test @@ -508,7 +508,7 @@ class AccountRepositoryImplTest { ) coEvery { authenticationPreferences.getSessionId() } returns sessionId - coEvery { remoteDataSource.getAccountDetails(sessionId) } returns Result.success(accountResponse) + coEvery { remoteDataSource.getAccountInfo(sessionId) } returns Result.success(accountResponse) // When val result = repository.getAccountInfo() @@ -520,7 +520,7 @@ class AccountRepositoryImplTest { // Verify coVerify { authenticationPreferences.getSessionId() } - coVerify { remoteDataSource.getAccountDetails(sessionId) } + coVerify { remoteDataSource.getAccountInfo(sessionId) } } // region: getAccountId() @@ -548,4 +548,4 @@ class AccountRepositoryImplTest { private companion object Account { const val ACCOUNT_ID = 12345 } -} \ No newline at end of file +} diff --git a/presentation/src/main/java/com/london/presentation/feature/account/AccountViewModel.kt b/presentation/src/main/java/com/london/presentation/feature/account/AccountViewModel.kt index 1b54f4d12..b273b4cb6 100644 --- a/presentation/src/main/java/com/london/presentation/feature/account/AccountViewModel.kt +++ b/presentation/src/main/java/com/london/presentation/feature/account/AccountViewModel.kt @@ -18,7 +18,7 @@ import javax.inject.Inject class AccountViewModel @Inject constructor( private val appPreferencesService: AppPreferencesService, private val authenticationUseCase: AuthenticationUseCase, - private val accountDetailsUseCase: GetAccountInfoUseCase + private val accountInfoUseCase: GetAccountInfoUseCase ) : BaseViewModel(AccountUiState()), AccountContract { @@ -194,7 +194,7 @@ class AccountViewModel @Inject constructor( private fun fetchAndSetUsername() { tryToExecute( - block = { accountDetailsUseCase.invoke() }, + block = { accountInfoUseCase.invoke() }, onSuccess = { accountInfo -> updateState { copy( diff --git a/presentation/src/main/java/com/london/presentation/utils/SearchUtils.kt b/presentation/src/main/java/com/london/presentation/utils/searchUtils.kt similarity index 100% rename from presentation/src/main/java/com/london/presentation/utils/SearchUtils.kt rename to presentation/src/main/java/com/london/presentation/utils/searchUtils.kt diff --git a/presentation/src/test/java/com/london/presentation/feature/account/account/AccountViewModelTest.kt b/presentation/src/test/java/com/london/presentation/feature/account/account/AccountViewModelTest.kt index 0afc4c54f..dd5ab4d0a 100644 --- a/presentation/src/test/java/com/london/presentation/feature/account/account/AccountViewModelTest.kt +++ b/presentation/src/test/java/com/london/presentation/feature/account/account/AccountViewModelTest.kt @@ -31,7 +31,7 @@ class AccountViewModelTest { private lateinit var appPreferencesService: AppPreferencesService private lateinit var authenticationUseCase: AuthenticationUseCase - private lateinit var accountDetailsUseCase: GetAccountInfoUseCase + private lateinit var accountInfoUseCase: GetAccountInfoUseCase private lateinit var viewModel: AccountViewModel private val testDispatcher = StandardTestDispatcher() @@ -39,7 +39,7 @@ class AccountViewModelTest { fun setUp() { appPreferencesService = mockk(relaxed = true) authenticationUseCase = mockk(relaxed = true) - accountDetailsUseCase = mockk(relaxed = true) + accountInfoUseCase = mockk(relaxed = true) Dispatchers.setMain(testDispatcher) @@ -59,11 +59,11 @@ class AccountViewModelTest { // Given every { appPreferencesService.isAppDarkMode } returns MutableStateFlow(true) coEvery { authenticationUseCase.isLoggedIn() } returns false - coEvery { accountDetailsUseCase.invoke() } returns AccountInfo(1, "", "") + coEvery { accountInfoUseCase.invoke() } returns AccountInfo(1, "", "") // When viewModel = - AccountViewModel(appPreferencesService, authenticationUseCase, accountDetailsUseCase) + AccountViewModel(appPreferencesService, authenticationUseCase, accountInfoUseCase) testDispatcher.scheduler.advanceUntilIdle() // Then @@ -75,11 +75,11 @@ class AccountViewModelTest { // Given every { appPreferencesService.appLanguage } returns MutableStateFlow(AppLanguage.ARABIC) coEvery { authenticationUseCase.isLoggedIn() } returns false - coEvery { accountDetailsUseCase.invoke() } returns AccountInfo(1, "", "") + coEvery { accountInfoUseCase.invoke() } returns AccountInfo(1, "", "") // When viewModel = - AccountViewModel(appPreferencesService, authenticationUseCase, accountDetailsUseCase) + AccountViewModel(appPreferencesService, authenticationUseCase, accountInfoUseCase) testDispatcher.scheduler.advanceUntilIdle() // Then @@ -259,11 +259,11 @@ class AccountViewModelTest { fun `should handle user not logged in during initialization`() = runTest { // Given coEvery { authenticationUseCase.isLoggedIn() } returns false - coEvery { accountDetailsUseCase.invoke() } returns AccountInfo(1, "", "") + coEvery { accountInfoUseCase.invoke() } returns AccountInfo(1, "", "") // When viewModel = - AccountViewModel(appPreferencesService, authenticationUseCase, accountDetailsUseCase) + AccountViewModel(appPreferencesService, authenticationUseCase, accountInfoUseCase) testDispatcher.scheduler.advanceUntilIdle() // Then @@ -277,11 +277,11 @@ class AccountViewModelTest { val contentRestrictionFlow = MutableStateFlow(ContentRestrictionLevel.MODERATE) every { appPreferencesService.contentRestrictionLevel } returns contentRestrictionFlow coEvery { authenticationUseCase.isLoggedIn() } returns false - coEvery { accountDetailsUseCase.invoke() } returns AccountInfo(1, "", "") + coEvery { accountInfoUseCase.invoke() } returns AccountInfo(1, "", "") // When viewModel = - AccountViewModel(appPreferencesService, authenticationUseCase, accountDetailsUseCase) + AccountViewModel(appPreferencesService, authenticationUseCase, accountInfoUseCase) testDispatcher.scheduler.advanceUntilIdle() contentRestrictionFlow.value = ContentRestrictionLevel.STRICT @@ -294,10 +294,10 @@ class AccountViewModelTest { private fun setupViewModel() { coEvery { authenticationUseCase.isLoggedIn() } returns true - coEvery { accountDetailsUseCase.invoke() } returns AccountInfo(1, "TestUser", "avatar.jpg") + coEvery { accountInfoUseCase.invoke() } returns AccountInfo(1, "TestUser", "avatar.jpg") viewModel = - AccountViewModel(appPreferencesService, authenticationUseCase, accountDetailsUseCase) + AccountViewModel(appPreferencesService, authenticationUseCase, accountInfoUseCase) testDispatcher.scheduler.advanceUntilIdle() } }