Skip to content

Commit

Permalink
fix: Changes in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Aitorbp committed Mar 26, 2024
1 parent 98205af commit 5aa0789
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,25 @@ class OCLocalFileDataSourceTest {
}

@Test
fun `getFilesForAccount returns a list of OCFile`() {
every { fileDao.getFilesForAccount(OC_ACCOUNT_NAME) } returns listOf(OC_FILE_ENTITY)
fun `getDownloadedFilesForAccount returns a list of OCFile`() {
every { fileDao.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) } returns listOf(OC_FILE_ENTITY)

val result = ocLocalFileDataSource.getFilesForAccount(OC_ACCOUNT_NAME)
val result = ocLocalFileDataSource.getDownloadedFilesForAccount(OC_ACCOUNT_NAME)

assertEquals(listOf(OC_FILE), result)

verify(exactly = 1) { fileDao.getFilesForAccount(OC_ACCOUNT_NAME) }
verify(exactly = 1) { fileDao.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) }
}

@Test
fun `getDownloadedFilesForAccount returns an empty list when DAO returns an empty list`() {
every { fileDao.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) } returns emptyList()

val result = ocLocalFileDataSource.getDownloadedFilesForAccount(OC_ACCOUNT_NAME)

assertEquals(emptyList<OCFile>(), result)

verify(exactly = 1) { fileDao.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) }
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ class OCFileRepositoryTest {
private val localFileDataSource = mockk<LocalFileDataSource>(relaxed = true)
private val localSpacesDataSource = mockk<LocalSpacesDataSource>(relaxed = true)
private val localStorageProvider = mockk<LocalStorageProvider>()
private val ocFileRepository: OCFileRepository = OCFileRepository(localFileDataSource, remoteFileDataSource, localSpacesDataSource, localStorageProvider)
private val ocFileRepository: OCFileRepository =
OCFileRepository(localFileDataSource, remoteFileDataSource, localSpacesDataSource, localStorageProvider)

private val folderToFetch = OC_FOLDER
private val listOfFilesRetrieved = listOf(
Expand Down Expand Up @@ -110,7 +111,7 @@ class OCFileRepositoryTest {
}

@Test
fun `getFileWithSyncInfoByIdAsFlow returns OCFileWithSyncInfo`() = runTest {
fun `getFileWithSyncInfoByIdAsFlow returns OCFileWithSyncInfo`() = runTest {
every { localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } returns flowOf(OC_FILE_WITH_SYNC_INFO_AND_SPACE)

val ocFile = ocFileRepository.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!)
Expand All @@ -125,7 +126,7 @@ class OCFileRepositoryTest {
}

@Test
fun `getFileWithSyncInfoByIdAsFlow returns null`() = runTest {
fun `getFileWithSyncInfoByIdAsFlow returns null`() = runTest {
every { localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } returns flowOf(null)

val ocFile = ocFileRepository.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!)
Expand All @@ -139,17 +140,17 @@ class OCFileRepositoryTest {
}
}


@Test(expected = Exception::class)
fun `getFileWithSyncInfoByIdAsFlow returns an exception`() = runTest {
every { localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } throws Exception()
fun `getFileWithSyncInfoByIdAsFlow returns an exception`() = runTest {
every { localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!) } throws Exception()

ocFileRepository.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!)

verify(exactly = 1) {
localFileDataSource.getFileWithSyncInfoByIdAsFlow(OC_FILE.id!!)
}
}

@Test
fun `get file by id - ok - null`() {
every { localFileDataSource.getFileById(OC_FOLDER.id!!) } returns null
Expand Down Expand Up @@ -199,20 +200,31 @@ class OCFileRepositoryTest {
}

@Test
fun `getFilesForAccount returns a list of OCFile`() {
fun `getDownloadedFilesForAccount returns a list of OCFile`() {
every {
localFileDataSource.getFilesForAccount(OC_ACCOUNT_NAME)
localFileDataSource.getDownloadedFilesForAccount(OC_ACCOUNT_NAME)
} returns listOf(OC_FILE)

val result = ocFileRepository.getFilesForAccount(OC_ACCOUNT_NAME)
val result = ocFileRepository.getDownloadedFilesForAccount(OC_ACCOUNT_NAME)

assertEquals(listOf(OC_FILE), result)

verify(exactly = 1) {
localFileDataSource.getFilesForAccount(OC_ACCOUNT_NAME)
localFileDataSource.getDownloadedFilesForAccount(OC_ACCOUNT_NAME)
}
}

@Test
fun `getDownloadedFilesForAccount returns an empty list when datasource returns an empty list`() {
every { localFileDataSource.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) } returns emptyList()

val result = ocFileRepository.getDownloadedFilesForAccount(OC_ACCOUNT_NAME)

assertEquals(emptyList<OCFile>(), result)

verify(exactly = 1) { localFileDataSource.getDownloadedFilesForAccount(OC_ACCOUNT_NAME) }
}

@Test
fun `get folder content - ok`() {
every { localFileDataSource.getFolderContent(OC_FOLDER.parentId!!) } returns listOf(OC_FOLDER)
Expand Down

0 comments on commit 5aa0789

Please sign in to comment.