Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing CountryLocalDataSource #334

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package com.toquete.boxbox.data.countries.repository

import com.toquete.boxbox.core.common.annotation.IoDispatcher
import com.toquete.boxbox.core.database.dao.CountryDao
import com.toquete.boxbox.core.network.model.CountryResponse
import com.toquete.boxbox.data.countries.model.toEntity
import com.toquete.boxbox.data.countries.source.local.CountryLocalDataSource
import com.toquete.boxbox.data.countries.source.remote.CountryRemoteDataSource
import kotlinx.coroutines.withContext
import javax.inject.Inject
import kotlin.coroutines.CoroutineContext

internal class DefaultCountryRepository @Inject constructor(
private val remoteDataSource: CountryRemoteDataSource,
private val localDataSource: CountryLocalDataSource,
private val countryDao: CountryDao,
@IoDispatcher private val dispatcher: CoroutineContext
) : CountryRepository {

override suspend fun sync() {
withContext(dispatcher) {
val list = remoteDataSource.getCountries()
localDataSource.insertAll(list.map(CountryResponse::toEntity))
countryDao.upsertAll(list.map(CountryResponse::toEntity))
}
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.toquete.boxbox.data.countries.repository

import com.toquete.boxbox.core.database.dao.CountryDao
import com.toquete.boxbox.core.testing.data.countryEntities
import com.toquete.boxbox.core.testing.data.countryResponses
import com.toquete.boxbox.data.countries.source.local.CountryLocalDataSource
import com.toquete.boxbox.data.countries.source.remote.CountryRemoteDataSource
import io.mockk.coEvery
import io.mockk.coVerify
Expand All @@ -15,20 +15,20 @@ import java.io.IOException
class DefaultCountryRepositoryTest {

private val remoteDataSource: CountryRemoteDataSource = mockk(relaxed = true)
private val localDataSource: CountryLocalDataSource = mockk(relaxed = true)
private val countryDao: CountryDao = mockk(relaxed = true)
private val testDispatcher = UnconfinedTestDispatcher()
private val repository = DefaultCountryRepository(remoteDataSource, localDataSource, testDispatcher)
private val repository = DefaultCountryRepository(remoteDataSource, countryDao, testDispatcher)

@Test
fun `sync should insert data in database when remote data is gotten successfully`() = runTest {
coEvery { remoteDataSource.getCountries() } returns countryResponses
coEvery { localDataSource.insertAll(any()) } returns Unit
coEvery { countryDao.upsertAll(any()) } returns Unit

repository.sync()

coVerify {
remoteDataSource.getCountries()
localDataSource.insertAll(countryEntities)
countryDao.upsertAll(countryEntities)
}
}

Expand All @@ -38,6 +38,6 @@ class DefaultCountryRepositoryTest {

repository.sync()

coVerify(exactly = 0) { localDataSource.insertAll(any()) }
coVerify(exactly = 0) { countryDao.upsertAll(any()) }
}
}

This file was deleted.

Loading