Skip to content

Commit

Permalink
test: add disabled task type unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Jana Peper <[email protected]>
  • Loading branch information
janepie committed Dec 11, 2024
1 parent fa78638 commit 03402f2
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions tests/lib/TaskProcessing/TaskProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(
Expand All @@ -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),
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 03402f2

Please sign in to comment.