From 03402f27e2575776a5b367e4e029c6ac9684b5c9 Mon Sep 17 00:00:00 2001 From: Jana Peper Date: Wed, 11 Dec 2024 09:37:43 +0100 Subject: [PATCH] test: add disabled task type unit test Signed-off-by: Jana Peper --- .../lib/TaskProcessing/TaskProcessingTest.php | 48 ++++++++++++------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/lib/TaskProcessing/TaskProcessingTest.php b/tests/lib/TaskProcessing/TaskProcessingTest.php index a210ff00274f2..f19ce6aa2a47e 100644 --- a/tests/lib/TaskProcessing/TaskProcessingTest.php +++ b/tests/lib/TaskProcessing/TaskProcessingTest.php @@ -387,6 +387,7 @@ public function getExpectedRuntime(): int { */ class TaskProcessingTest extends \Test\TestCase { private IManager $manager; + private IManager $disabledTypeManager; private Coordinator $coordinator; private array $providers; private IServerContainer $serverContainer; @@ -442,17 +443,6 @@ protected function setUp(): void { $this->jobList->expects($this->any())->method('add')->willReturnCallback(function () { }); - - $taskProcessingTypeSettings = []; - $taskProcessingTypeSettings[TextToText::ID] = false; - $config = $this->createMock(IConfig::class); - $config->method('getAppValue') - ->with('core', 'ai.textprocessing_provider_preferences', '') - ->willReturn(''); - $config->method('getAppValue') - ->with('core', 'ai.taskprocessing_type_preferences', '') - ->willReturn(json_encode($taskProcessingTypeSettings)); - $this->eventDispatcher = $this->createMock(IEventDispatcher::class); $text2imageManager = new \OC\TextToImage\Manager( @@ -468,7 +458,32 @@ protected function setUp(): void { $this->userMountCache = $this->createMock(IUserMountCache::class); $this->manager = new Manager( - $config, + \OC::$server->get(IConfig::class), + $this->coordinator, + $this->serverContainer, + \OC::$server->get(LoggerInterface::class), + $this->taskMapper, + $this->jobList, + $this->eventDispatcher, + \OC::$server->get(IAppDataFactory::class), + \OC::$server->get(IRootFolder::class), + $text2imageManager, + $this->userMountCache, + \OC::$server->get(IClientService::class), + \OC::$server->get(IAppManager::class), + ); + + + $taskProcessingTypeSettings = []; + $taskProcessingTypeSettings[TextToText::ID] = false; + + $disabledConfig = $this->createMock(IConfig::class); + $disabledConfig->method('getAppValue') + ->with('core', 'ai.taskprocessing_type_preferences', '') + ->willReturn(json_encode($taskProcessingTypeSettings)); + + $this->disabledTypeManager = new Manager( + $disabledConfig, $this->coordinator, $this->serverContainer, \OC::$server->get(LoggerInterface::class), @@ -505,16 +520,17 @@ public function testProviderShouldBeRegisteredAndTaskTypeDisabled(): void { $this->registrationContext->expects($this->any())->method('getTaskProcessingProviders')->willReturn([ new ServiceRegistration('test', SuccessfulSyncProvider::class) ]); + /*$taskProcessingTypeSettings = []; $taskProcessingTypeSettings[TextToText::ID] = false; $this->config->method('getAppValue') ->with('core', 'ai.taskprocessing_type_preferences', '') ->willReturn(json_encode($taskProcessingTypeSettings));*/ - self::assertCount(0, $this->manager->getAvailableTaskTypes()); - self::assertCount(1, $this->manager->getAvailableTaskTypes(true)); - self::assertFalse($this->manager->hasProviders()); + self::assertCount(0, $this->disabledTypeManager->getAvailableTaskTypes()); + self::assertCount(1, $this->disabledTypeManager->getAvailableTaskTypes(true)); + self::assertFalse($this->disabledTypeManager->hasProviders()); self::expectException(\OCP\TaskProcessing\Exception\PreConditionNotMetException::class); - $this->manager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null)); + $this->disabledTypeManager->scheduleTask(new Task(TextToText::ID, ['input' => 'Hello'], 'test', null)); } public function testProviderShouldBeRegisteredAndTaskFailValidation(): void {