Files

40 lines
1.1 KiB
PHP

<?php
declare(strict_types=1);
namespace OCA\EducAI\Tests\Unit\Controller;
use OCA\EducAI\Controller\BotController;
use OCA\EducAI\Service\BotService;
use OCA\EducAI\Service\PermissionService;
use OCP\IRequest;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
class BotControllerTest extends TestCase {
public function testCreateRejectsUsersBlockedByBotCreationPolicy(): void {
$botService = $this->createMock(BotService::class);
$botService->expects($this->never())->method('createBot');
$permissionService = $this->createMock(PermissionService::class);
$permissionService->expects($this->once())
->method('canCreateBots')
->with('blocked-user')
->willReturn(false);
$controller = new BotController(
'educai',
$this->createMock(IRequest::class),
$botService,
$permissionService,
'blocked-user',
$this->createMock(LoggerInterface::class)
);
$response = $controller->create('Blocked bot', '@blocked-bot', 'System prompt');
$this->assertSame(403, $response->getStatus());
$this->assertSame(['error' => 'You do not have permission to create bots.'], $response->getData());
}
}