Skip to content

Commit 34f2c80

Browse files
committed
fix test
Signed-off-by: alperozturk <alper_ozturk@proton.me>
1 parent e4e341c commit 34f2c80

File tree

3 files changed

+45
-19
lines changed

3 files changed

+45
-19
lines changed

library/src/androidTest/java/com/owncloud/android/lib/resources/assistant/AssistantIT.kt

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
package com.owncloud.android.lib.resources.assistant
1010

1111
import com.owncloud.android.AbstractIT
12+
import com.owncloud.android.lib.resources.assistant.model.TaskInputShape
13+
import com.owncloud.android.lib.resources.assistant.model.TaskOutputShape
14+
import com.owncloud.android.lib.resources.assistant.model.TaskTypeData
1215
import com.owncloud.android.lib.resources.status.NextcloudVersion
1316
import junit.framework.TestCase.assertEquals
1417
import junit.framework.TestCase.assertTrue
@@ -21,12 +24,34 @@ class AssistantIT : AbstractIT() {
2124
testOnlyOnServer(NextcloudVersion.nextcloud_28)
2225
}
2326

27+
private fun getTaskType(): TaskTypeData {
28+
return TaskTypeData(
29+
"core:text2text",
30+
"Free text to text prompt",
31+
"Runs an arbitrary prompt through a language model that returns a reply",
32+
listOf(
33+
TaskInputShape(
34+
"Prompt",
35+
"Describe a task that you want the assistant to do or ask a question",
36+
"Text"
37+
)
38+
),
39+
listOf(
40+
TaskOutputShape(
41+
"Generated reply",
42+
"The generated text from the assistant",
43+
"Text"
44+
)
45+
)
46+
)
47+
}
48+
2449
@Test
2550
fun testGetTaskTypes() {
2651
val result = GetTaskTypesRemoteOperation().execute(nextcloudClient)
2752
assertTrue(result.isSuccess)
2853

29-
val taskTypes = result.resultData.types
54+
val taskTypes = result.resultData
3055
assertTrue(taskTypes.isNotEmpty())
3156
}
3257

@@ -38,8 +63,8 @@ class AssistantIT : AbstractIT() {
3863

3964
// create one task
4065
val input = "Give me some random output for test purpose"
41-
val type = "OCP\\TextProcessing\\FreePromptTaskType"
42-
assertTrue(CreateTaskRemoteOperation(input, type).execute(nextcloudClient).isSuccess)
66+
val taskType = getTaskType()
67+
assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess)
4368

4469
result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient)
4570
assertTrue(result.isSuccess)
@@ -52,8 +77,8 @@ class AssistantIT : AbstractIT() {
5277
fun testDeleteTask() {
5378
// create one task
5479
val input = "Give me some random output for test purpose"
55-
val type = "OCP\\TextProcessing\\FreePromptTaskType"
56-
assertTrue(CreateTaskRemoteOperation(input, type).execute(nextcloudClient).isSuccess)
80+
val taskType = getTaskType()
81+
assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess)
5782

5883
var result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient)
5984
assertTrue(result.isSuccess)

library/src/main/java/com/owncloud/android/lib/resources/assistant/GetTaskTypesRemoteOperation.kt

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import com.owncloud.android.lib.resources.assistant.model.TaskTypes
2020
import org.apache.commons.httpclient.HttpStatus
2121

2222
class GetTaskTypesRemoteOperation : OCSRemoteOperation<List<TaskTypeData>>() {
23-
2423
private val supportedTaskType = "Text"
2524

2625
@Suppress("TooGenericExceptionCaught")
@@ -39,17 +38,19 @@ class GetTaskTypesRemoteOperation : OCSRemoteOperation<List<TaskTypeData>>() {
3938
object : TypeToken<ServerResponse<TaskTypes>>() {}
4039
)?.ocs?.data?.types
4140

42-
val taskTypeList = response?.map { (key, value) ->
43-
value.copy(id = value.id ?: key)
44-
}
41+
val taskTypeList =
42+
response?.map { (key, value) ->
43+
value.copy(id = value.id ?: key)
44+
}
4545

46-
val supportedTaskTypeList = taskTypeList?.filter { taskType ->
47-
taskType.inputShape?.any { inputShape ->
48-
inputShape.type == supportedTaskType
49-
} == true && taskType.outputShape?.any { outputShape ->
50-
outputShape.type == supportedTaskType
51-
} == true
52-
}
46+
val supportedTaskTypeList =
47+
taskTypeList?.filter { taskType ->
48+
taskType.inputShape?.any { inputShape ->
49+
inputShape.type == supportedTaskType
50+
} == true && taskType.outputShape?.any { outputShape ->
51+
outputShape.type == supportedTaskType
52+
} == true
53+
}
5354

5455
result = RemoteOperationResult(true, getMethod)
5556
result.setResultData(supportedTaskTypeList)

library/src/main/java/com/owncloud/android/lib/resources/assistant/model/TaskTypes.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
package com.owncloud.android.lib.resources.assistant.model
1010

11-
data class TaskTypes(val types: Map<String, TaskTypeData>)
11+
data class TaskTypes(val types: Map<String, TaskTypeData>)
1212

1313
data class TaskTypeData(
1414
val id: String?,
@@ -21,11 +21,11 @@ data class TaskTypeData(
2121
data class TaskInputShape(
2222
val name: String?,
2323
val description: String?,
24-
val type: String?,
24+
val type: String?
2525
)
2626

2727
data class TaskOutputShape(
2828
val name: String?,
2929
val description: String?,
30-
val type: String?,
30+
val type: String?
3131
)

0 commit comments

Comments
 (0)