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

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
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