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

Handled Critical code smells on SonarCloud #529

Merged
merged 1 commit into from
Feb 9, 2022
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
21 changes: 13 additions & 8 deletions app/src/androidTest/java/com/infomaniak/drive/ApiRepositoryTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -311,15 +311,17 @@ class ApiRepositoryTest : KDriveTest() {

@Test
fun manageCategoryLifecycle() {
val categoryId = createCategory(userDrive.driveId, "category tests", "#0000FF").let {
var name = "category tests"
var color = "#0000FF"
val categoryId = createCategory(userDrive.driveId, name, color).let {
assertApiResponse(it)
Assert.assertEquals("Name of the category should be equals to 'category tests'", "category tests", it.data?.name)
Assert.assertEquals("Color of the category should be equals to blue", "#0000FF", it.data?.color)
Assert.assertEquals("Name of the category should be equals to '$name'", name, it.data?.name)
Assert.assertEquals("Color of the category should be equals to blue", color, it.data?.color)
it.data!!.id
}

// Create again the same category should fail
with(createCategory(userDrive.driveId, "category tests", "#0000FF")) {
with(createCategory(userDrive.driveId, name, color)) {
Assert.assertFalse(isSuccess())
Assert.assertEquals(
"Error description should be 'category already exist error'",
Expand All @@ -328,16 +330,19 @@ class ApiRepositoryTest : KDriveTest() {
)
}

with(editCategory(userDrive.driveId, categoryId, "update cat", "#FF0000")) {
name = "update cat"
color = "#FF0000"
with(editCategory(userDrive.driveId, categoryId, name, color)) {
assertApiResponse(this)
Assert.assertEquals("Name of the category should be equals to 'update cat'", "update cat", data?.name)
Assert.assertEquals("Color of the category should be equals to red", "#FF0000", data?.color)
Assert.assertEquals("Name of the category should be equals to '$name'", name, data?.name)
Assert.assertEquals("Color of the category should be equals to red", color, data?.color)
}

assertApiResponse(deleteCategory(userDrive.driveId, categoryId))
Assert.assertNull(
"The category shouldn't be found anymore",
getCategory(userDrive.driveId).data?.find { cat -> cat.id == categoryId })
getCategory(userDrive.driveId).data?.find { cat -> cat.id == categoryId },
)
}

@Test
Expand Down
8 changes: 5 additions & 3 deletions app/src/main/java/com/infomaniak/drive/utils/AccountUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ import java.util.concurrent.TimeUnit

object AccountUtils : CredentialManager {

private const val DISABLE_AUTO_SYNC = "AccountUtils: disableAutoSync"

private lateinit var userDatabase: UserDatabase
var reloadApp: (() -> Unit)? = null

Expand Down Expand Up @@ -122,7 +124,7 @@ object AccountUtils : CredentialManager {
val appSyncSettings = UploadFile.getAppSyncSettings()
for (driveRemoved in driveRemovedList) {
if (appSyncSettings?.userId == user.id && appSyncSettings.driveId == driveRemoved.id) {
Sentry.captureMessage("AccountUtils: disableAutoSync")
Sentry.captureMessage(DISABLE_AUTO_SYNC)
context.disableAutoSync()
}
if (currentDriveId == driveRemoved.id) {
Expand Down Expand Up @@ -177,7 +179,7 @@ object AccountUtils : CredentialManager {
FileController.deleteUserDriveFiles(userRemoved.id)

if (UploadFile.getAppSyncSettings()?.userId == userRemoved.id) {
Sentry.captureMessage("AccountUtils: disableAutoSync")
Sentry.captureMessage(DISABLE_AUTO_SYNC)
context.disableAutoSync()
}

Expand Down Expand Up @@ -273,7 +275,7 @@ object AccountUtils : CredentialManager {
UiSettings(context).removeUiSettings()

if (isEnableAppSync()) {
Sentry.captureMessage("AccountUtils: disableAutoSync")
Sentry.captureMessage(DISABLE_AUTO_SYNC)
context.disableAutoSync()
}

Expand Down