Skip to content

Commit

Permalink
Merge pull request #4389 from owncloud/technical/testing_repositories_2
Browse files Browse the repository at this point in the history
[TECHNICAL] Unit tests for repository classes - Part 2
  • Loading branch information
JuancaG05 authored Nov 22, 2024
2 parents 21b5b6c + ef54ad9 commit dfb744f
Show file tree
Hide file tree
Showing 7 changed files with 1,958 additions and 230 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ownCloud admins and users.
## Summary

* Change - Replace auto-uploads with automatic uploads: [#4252](https://github.com/owncloud/android/issues/4252)
* Enhancement - Unit tests for repository classes - Part 2: [#4233](https://github.com/owncloud/android/issues/4233)
* Enhancement - Add status message when (un)setting av. offline from preview: [#4382](https://github.com/owncloud/android/issues/4382)
* Enhancement - Quota improvements from GraphAPI: [#4411](https://github.com/owncloud/android/issues/4411)
* Enhancement - Upgraded AGP version to 8.7.2: [#4478](https://github.com/owncloud/android/issues/4478)
Expand All @@ -51,6 +52,13 @@ ownCloud admins and users.
https://github.com/owncloud/android/issues/4252
https://github.com/owncloud/android/pull/4492

* Enhancement - Unit tests for repository classes - Part 2: [#4233](https://github.com/owncloud/android/issues/4233)

Unit tests for OCFileRepository class have been completed.

https://github.com/owncloud/android/issues/4233
https://github.com/owncloud/android/pull/4389

* Enhancement - Add status message when (un)setting av. offline from preview: [#4382](https://github.com/owncloud/android/issues/4382)

A message has been added in all previews when the (un)setting av. offline
Expand Down
6 changes: 6 additions & 0 deletions changelog/unreleased/4389
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Unit tests for repository classes - Part 2

Unit tests for OCFileRepository class have been completed.

https://github.com/owncloud/android/issues/4233
https://github.com/owncloud/android/pull/4389
Original file line number Diff line number Diff line change
Expand Up @@ -157,12 +157,12 @@ class OCFileRepository(
override fun getFileById(fileId: Long): OCFile? =
localFileDataSource.getFileById(fileId)

override fun getFileWithSyncInfoByIdAsFlow(fileId: Long): Flow<OCFileWithSyncInfo?> =
localFileDataSource.getFileWithSyncInfoByIdAsFlow(fileId)

override fun getFileByIdAsFlow(fileId: Long): Flow<OCFile?> =
localFileDataSource.getFileByIdAsFlow(fileId)

override fun getFileWithSyncInfoByIdAsFlow(fileId: Long): Flow<OCFileWithSyncInfo?> =
localFileDataSource.getFileWithSyncInfoByIdAsFlow(fileId)

override fun getFileByRemotePath(remotePath: String, owner: String, spaceId: String?): OCFile? =
localFileDataSource.getFileByRemotePath(remotePath, owner, spaceId)

Expand Down Expand Up @@ -328,46 +328,6 @@ class OCFileRepository(
return filesNeedsAction
}

private fun getFinalRemotePath(
replace: List<Boolean?>,
expectedRemotePath: String,
targetFolder: OCFile,
targetSpaceWebDavUrl: String?,
filesNeedsAction: MutableList<OCFile>,
ocFile: OCFile,
position: Int,
isUserLogged: Boolean,
) =
if (replace.isEmpty()) {
val pathExists = remoteFileDataSource.checkPathExistence(
path = expectedRemotePath,
isUserLogged = isUserLogged,
accountName = targetFolder.owner,
spaceWebDavUrl = targetSpaceWebDavUrl,
)
if (pathExists) {
filesNeedsAction.add(ocFile)
null
} else {
if (ocFile.isFolder) expectedRemotePath.plus(File.separator) else expectedRemotePath
}
} else {
if (replace[position] == true) {
if (ocFile.isFolder) expectedRemotePath.plus(File.separator) else expectedRemotePath
} else if (replace[position] == false) {
remoteFileDataSource.getAvailableRemotePath(
remotePath = expectedRemotePath,
accountName = targetFolder.owner,
spaceWebDavUrl = targetSpaceWebDavUrl,
isUserLogged = isUserLogged,
).let {
if (ocFile.isFolder) it.plus(File.separator) else it
}
} else {
null
}
}

override fun readFile(remotePath: String, accountName: String, spaceId: String?): OCFile {
val spaceWebDavUrl = localSpacesDataSource.getWebDavUrlForSpace(spaceId, accountName)

Expand Down Expand Up @@ -571,10 +531,6 @@ class OCFileRepository(
localFileDataSource.updateDownloadedFilesStorageDirectoryInStoragePath(oldDirectory, newDirectory)
}

override fun saveUploadWorkerUuid(fileId: Long, workerUuid: UUID) {
TODO("Not yet implemented")
}

override fun saveDownloadWorkerUuid(fileId: Long, workerUuid: UUID) {
localFileDataSource.saveDownloadWorkerUuid(fileId, workerUuid)
}
Expand All @@ -583,6 +539,46 @@ class OCFileRepository(
localFileDataSource.cleanWorkersUuid(fileId)
}

private fun getFinalRemotePath(
replace: List<Boolean?>,
expectedRemotePath: String,
targetFolder: OCFile,
targetSpaceWebDavUrl: String?,
filesNeedsAction: MutableList<OCFile>,
ocFile: OCFile,
position: Int,
isUserLogged: Boolean,
) =
if (replace.isEmpty()) {
val pathExists = remoteFileDataSource.checkPathExistence(
path = expectedRemotePath,
isUserLogged = isUserLogged,
accountName = targetFolder.owner,
spaceWebDavUrl = targetSpaceWebDavUrl,
)
if (pathExists) {
filesNeedsAction.add(ocFile)
null
} else {
if (ocFile.isFolder) expectedRemotePath.plus(File.separator) else expectedRemotePath
}
} else {
if (replace[position] == true) {
if (ocFile.isFolder) expectedRemotePath.plus(File.separator) else expectedRemotePath
} else if (replace[position] == false) {
remoteFileDataSource.getAvailableRemotePath(
remotePath = expectedRemotePath,
accountName = targetFolder.owner,
spaceWebDavUrl = targetSpaceWebDavUrl,
isUserLogged = isUserLogged,
).let {
if (ocFile.isFolder) it.plus(File.separator) else it
}
} else {
null
}
}

private fun deleteLocalFolderRecursively(ocFile: OCFile, onlyFromLocalStorage: Boolean) {
val folderContent = localFileDataSource.getFolderContent(ocFile.id!!)

Expand Down
Loading

0 comments on commit dfb744f

Please sign in to comment.