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 <jana.peper@nextcloud.com>
  • Loading branch information
janepie committed Dec 11, 2024
1 parent 574a97c commit e4e2ea0
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions tests/lib/TaskProcessing/TaskProcessingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,8 @@ public function getOptionalOutputShapeEnumValues(): array {
}
}



class FailingSyncProvider implements IProvider, ISynchronousProvider {
public const ERROR_MESSAGE = 'Failure';
public function getId(): string {
Expand Down Expand Up @@ -387,6 +389,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 All @@ -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';

Expand Down Expand Up @@ -442,11 +446,6 @@ protected function setUp(): void {
$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(
Expand All @@ -460,9 +459,9 @@ protected function setUp(): void {
);

$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),
Expand Down Expand Up @@ -492,7 +491,25 @@ public function testShouldNotHaveAnyProviders(): void {
$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)
]);
Expand Down

0 comments on commit e4e2ea0

Please sign in to comment.