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

[TECHNICAL] Unit tests for repository classes - Part 2 #4389

Merged
merged 8 commits into from
Nov 22, 2024
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
Loading