aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJana Peper <jana.peper@nextcloud.com>2024-12-12 11:06:09 +0100
committerjanepie <49834966+janepie@users.noreply.github.com>2024-12-18 18:32:34 +0100
commitb1d1badcf04867eb0b32dbc9a29f77d4f90d995d (patch)
treedf98560cdbc0338fd1ec8d0e7fb82917b8533dac
parente5f7d0017b4c53c7a48d9b23a2ba5beb0efea7dc (diff)
downloadnextcloud-server-b1d1badcf04867eb0b32dbc9a29f77d4f90d995d.tar.gz
nextcloud-server-b1d1badcf04867eb0b32dbc9a29f77d4f90d995d.zip
test: add explicitly enabled task type unit test
Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
-rw-r--r--tests/lib/TaskProcessing/TaskProcessingTest.php37
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/lib/TaskProcessing/TaskProcessingTest.php b/tests/lib/TaskProcessing/TaskProcessingTest.php
index 3b9020d9eb4..5ad1ee2fcdc 100644
--- a/tests/lib/TaskProcessing/TaskProcessingTest.php
+++ b/tests/lib/TaskProcessing/TaskProcessingTest.php
@@ -499,7 +499,6 @@ class TaskProcessingTest extends \Test\TestCase {
TextToText::ID => false,
];
$this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', json_encode($taskProcessingTypeSettings));
- $context = $this->coordinator->getRegistrationContext();
self::assertCount(0, $this->manager->getAvailableTaskTypes());
self::assertCount(1, $this->manager->getAvailableTaskTypes(true));
self::assertTrue($this->manager->hasProviders());
@@ -647,6 +646,42 @@ class TaskProcessingTest extends \Test\TestCase {
self::assertEquals(1, $task->getProgress());
}
+ public function testTaskTypeExplicitlyEnabled(): void {
+ $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([
+ new ServiceRegistration('test', SuccessfulSyncProvider::class)
+ ]);
+
+ $taskProcessingTypeSettings = [
+ TextToText::ID => true,
+ ];
+ $this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', json_encode($taskProcessingTypeSettings));
+
+ self::assertCount(1, $this->manager->getAvailableTaskTypes());
+
+ self::assertTrue($this->manager->hasProviders());
+ $task = new Task(TextToText::ID, ['input' => 'Hello'], 'test', null);
+ self::assertNull($task->getId());
+ self::assertEquals(Task::STATUS_UNKNOWN, $task->getStatus());
+ $this->manager->scheduleTask($task);
+ self::assertNotNull($task->getId());
+ self::assertEquals(Task::STATUS_SCHEDULED, $task->getStatus());
+
+ $this->eventDispatcher->expects($this->once())->method('dispatchTyped')->with(new IsInstanceOf(TaskSuccessfulEvent::class));
+
+ $backgroundJob = new \OC\TaskProcessing\SynchronousBackgroundJob(
+ \OCP\Server::get(ITimeFactory::class),
+ $this->manager,
+ $this->jobList,
+ \OCP\Server::get(LoggerInterface::class),
+ );
+ $backgroundJob->start($this->jobList);
+
+ $task = $this->manager->getTask($task->getId());
+ self::assertEquals(Task::STATUS_SUCCESSFUL, $task->getStatus(), 'Status is ' . $task->getStatus() . ' with error message: ' . $task->getErrorMessage());
+ self::assertEquals(['output' => 'Hello'], $task->getOutput());
+ self::assertEquals(1, $task->getProgress());
+ }
+
public function testAsyncProviderWithFilesShouldBeRegisteredAndRunReturningRawFileData(): void {
$this->registrationContext->expects($this->any())->method('getTaskProcessingTaskTypes')->willReturn([
new ServiceRegistration('test', AudioToImage::class)