diff options
author | Jana Peper <jana.peper@nextcloud.com> | 2024-12-11 18:12:56 +0100 |
---|---|---|
committer | janepie <49834966+janepie@users.noreply.github.com> | 2024-12-18 18:32:34 +0100 |
commit | 129af480acf167cc02d806445d5b871ee590f9e1 (patch) | |
tree | 126652f75efa690e00ab69e1eb33d438039faa71 | |
parent | 40fc07b54384125c1dcaff82f2cb18d418b15441 (diff) | |
download | nextcloud-server-129af480acf167cc02d806445d5b871ee590f9e1.tar.gz nextcloud-server-129af480acf167cc02d806445d5b871ee590f9e1.zip |
test: add disabled task type unit test
Signed-off-by: Jana Peper <jana.peper@nextcloud.com>
-rw-r--r-- | tests/lib/TaskProcessing/TaskProcessingTest.php | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/tests/lib/TaskProcessing/TaskProcessingTest.php b/tests/lib/TaskProcessing/TaskProcessingTest.php index 00e1da4acb5..3b9020d9eb4 100644 --- a/tests/lib/TaskProcessing/TaskProcessingTest.php +++ b/tests/lib/TaskProcessing/TaskProcessingTest.php @@ -187,6 +187,8 @@ class SuccessfulSyncProvider implements IProvider, ISynchronousProvider { } } + + class FailingSyncProvider implements IProvider, ISynchronousProvider { public const ERROR_MESSAGE = 'Failure'; public function getId(): string { @@ -387,6 +389,7 @@ class FailingTextToImageProvider implements \OCP\TextToImage\IProvider { */ class TaskProcessingTest extends \Test\TestCase { private IManager $manager; + private IManager $disabledTypeManager; private Coordinator $coordinator; private array $providers; private IServerContainer $serverContainer; @@ -396,6 +399,7 @@ class TaskProcessingTest extends \Test\TestCase { private IJobList $jobList; private IUserMountCache $userMountCache; private IRootFolder $rootFolder; + private IConfig $config; public const TEST_USER = 'testuser'; @@ -442,11 +446,6 @@ class TaskProcessingTest extends \Test\TestCase { $this->jobList->expects($this->any())->method('add')->willReturnCallback(function () { }); - $config = $this->createMock(IConfig::class); - $config->method('getAppValue') - ->with('core', 'ai.textprocessing_provider_preferences', '') - ->willReturn(''); - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $text2imageManager = new \OC\TextToImage\Manager( @@ -460,9 +459,9 @@ class TaskProcessingTest extends \Test\TestCase { ); $this->userMountCache = $this->createMock(IUserMountCache::class); - + $this->config = \OC::$server->get(IConfig::class); $this->manager = new Manager( - \OC::$server->get(IConfig::class), + $this->config, $this->coordinator, $this->serverContainer, \OC::$server->get(LoggerInterface::class), @@ -492,7 +491,25 @@ class TaskProcessingTest extends \Test\TestCase { $this->manager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null)); } + public function testProviderShouldBeRegisteredAndTaskTypeDisabled(): void { + $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([ + new ServiceRegistration('test', SuccessfulSyncProvider::class) + ]); + $taskProcessingTypeSettings = [ + 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()); + self::expectException(\OCP\TaskProcessing\Exception\PreConditionNotMetException::class); + $this->manager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null)); + } + + public function testProviderShouldBeRegisteredAndTaskFailValidation(): void { + $this->config->setAppValue('core', 'ai.taskprocessing_type_preferences', ''); $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([ new ServiceRegistration('test', BrokenSyncProvider::class) ]); |