Skip to content

Commit 0e8aab9

Browse files
test for delete tags
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
1 parent 3b9472f commit 0e8aab9

2 files changed

Lines changed: 81 additions & 1 deletion

File tree

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Nextcloud Android Library
3+
*
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
5+
* SPDX-License-Identifier: MIT
6+
*/
7+
package com.owncloud.android.lib.resources.tags
8+
9+
import com.nextcloud.test.RandomStringGenerator
10+
import com.owncloud.android.AbstractIT
11+
import com.owncloud.android.lib.resources.files.CreateFolderRemoteOperation
12+
import com.owncloud.android.lib.resources.files.ReadFileRemoteOperation
13+
import com.owncloud.android.lib.resources.files.ReadFolderRemoteOperation
14+
import com.owncloud.android.lib.resources.files.model.RemoteFile
15+
import com.owncloud.android.lib.resources.status.NextcloudVersion
16+
import junit.framework.TestCase.assertEquals
17+
import junit.framework.TestCase.assertTrue
18+
import org.junit.Test
19+
20+
class DeleteTagRemoteOperationIT : AbstractIT() {
21+
companion object {
22+
const val TAG_LENGTH = 10
23+
}
24+
25+
@Test
26+
fun deleteTag() {
27+
testOnlyOnServer(NextcloudVersion.nextcloud_31)
28+
29+
// create a folder
30+
val folder = "/deleteTagFolder/"
31+
assertTrue(CreateFolderRemoteOperation(folder, true).execute(client).isSuccess)
32+
val folderMetadata = ReadFileRemoteOperation(folder).execute(client)
33+
val fileId = (folderMetadata.data[0] as RemoteFile).localId
34+
35+
// create a tag
36+
val tagName = RandomStringGenerator.make(TAG_LENGTH)
37+
assertTrue(
38+
CreateTagRemoteOperation(tagName)
39+
.execute(nextcloudClient)
40+
.isSuccess
41+
)
42+
43+
// find the created tag
44+
val tagsResult = GetTagsRemoteOperation().execute(client)
45+
assertTrue(tagsResult.isSuccess)
46+
val tag = tagsResult.resultData.find { it.name == tagName }
47+
assertTrue(tag != null)
48+
49+
// assign the tag to the folder
50+
assertTrue(
51+
PutTagRemoteOperation(tag!!.id, fileId)
52+
.execute(nextcloudClient)
53+
.isSuccess
54+
)
55+
56+
// verify the tag is on the folder
57+
var rootMetadata = ReadFolderRemoteOperation("/").execute(client)
58+
var folderTags =
59+
(rootMetadata.data as ArrayList<RemoteFile>)
60+
.find { it.remotePath == folder }
61+
?.tags
62+
assertEquals(1, folderTags?.size)
63+
assertEquals(tagName, folderTags?.first()?.name)
64+
65+
// delete the tag from the folder
66+
assertTrue(
67+
DeleteTagRemoteOperation(tag.id, fileId)
68+
.execute(nextcloudClient)
69+
.isSuccess
70+
)
71+
72+
// verify the tag is no longer on the folder
73+
rootMetadata = ReadFolderRemoteOperation("/").execute(client)
74+
folderTags =
75+
(rootMetadata.data as ArrayList<RemoteFile>)
76+
.find { it.remotePath == folder }
77+
?.tags
78+
assertTrue(folderTags.isNullOrEmpty())
79+
}
80+
}

library/src/main/java/com/owncloud/android/lib/resources/tags/DeleteTagRemoteOperation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Nextcloud Android Library
33
*
4-
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
4+
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
55
* SPDX-License-Identifier: MIT
66
*/
77
package com.owncloud.android.lib.resources.tags

0 commit comments

Comments
 (0)