Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 34f2c801 authored by alperozturk's avatar alperozturk
Browse files

fix test

parent e4e341c5
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -9,6 +9,9 @@
package com.owncloud.android.lib.resources.assistant

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

    private fun getTaskType(): TaskTypeData {
        return TaskTypeData(
            "core:text2text",
            "Free text to text prompt",
            "Runs an arbitrary prompt through a language model that returns a reply",
            listOf(
                TaskInputShape(
                    "Prompt",
                    "Describe a task that you want the assistant to do or ask a question",
                    "Text"
                )
            ),
            listOf(
                TaskOutputShape(
                    "Generated reply",
                    "The generated text from the assistant",
                    "Text"
                )
            )
        )
    }

    @Test
    fun testGetTaskTypes() {
        val result = GetTaskTypesRemoteOperation().execute(nextcloudClient)
        assertTrue(result.isSuccess)

        val taskTypes = result.resultData.types
        val taskTypes = result.resultData
        assertTrue(taskTypes.isNotEmpty())
    }

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

        // create one task
        val input = "Give me some random output for test purpose"
        val type = "OCP\\TextProcessing\\FreePromptTaskType"
        assertTrue(CreateTaskRemoteOperation(input, type).execute(nextcloudClient).isSuccess)
        val taskType = getTaskType()
        assertTrue(CreateTaskRemoteOperation(input, taskType).execute(nextcloudClient).isSuccess)

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

        var result = GetTaskListRemoteOperation("assistant").execute(nextcloudClient)
        assertTrue(result.isSuccess)
+12 −11
Original line number Diff line number Diff line
@@ -20,7 +20,6 @@ import com.owncloud.android.lib.resources.assistant.model.TaskTypes
import org.apache.commons.httpclient.HttpStatus

class GetTaskTypesRemoteOperation : OCSRemoteOperation<List<TaskTypeData>>() {

    private val supportedTaskType = "Text"

    @Suppress("TooGenericExceptionCaught")
@@ -39,11 +38,13 @@ class GetTaskTypesRemoteOperation : OCSRemoteOperation<List<TaskTypeData>>() {
                        object : TypeToken<ServerResponse<TaskTypes>>() {}
                    )?.ocs?.data?.types

                val taskTypeList = response?.map { (key, value) ->
                val taskTypeList =
                    response?.map { (key, value) ->
                        value.copy(id = value.id ?: key)
                    }

                val supportedTaskTypeList = taskTypeList?.filter { taskType ->
                val supportedTaskTypeList =
                    taskTypeList?.filter { taskType ->
                        taskType.inputShape?.any { inputShape ->
                            inputShape.type == supportedTaskType
                        } == true && taskType.outputShape?.any { outputShape ->
+3 −3
Original line number Diff line number Diff line
@@ -21,11 +21,11 @@ data class TaskTypeData(
data class TaskInputShape(
    val name: String?,
    val description: String?,
    val type: String?,
    val type: String?
)

data class TaskOutputShape(
    val name: String?,
    val description: String?,
    val type: String?,
    val type: String?
)