116 lines
3.4 KiB
PHP
116 lines
3.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
// SPDX-FileCopyrightText: BVSC e.V. <no@example.com>
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
namespace OCA\UPschooling\Tests\Unit\Service;
|
|
|
|
use OCA\UPschooling\Db\MatrixTicket;
|
|
use OCA\UPschooling\Db\MatrixUser;
|
|
use OCA\UPschooling\Db\TicketMapper;
|
|
use OCA\UPschooling\Db\UserMapper;
|
|
use OCA\UPschooling\Exceptions\TicketNotFoundException;
|
|
use OCA\UPschooling\Service\MatrixService;
|
|
use OCA\UPschooling\Service\TicketService;
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
|
use OCP\IUser;
|
|
use OCP\IUserManager;
|
|
use PHPUnit\Framework\TestCase;
|
|
use Psr\Log\NullLogger;
|
|
|
|
class TicketServiceTest extends TestCase {
|
|
|
|
/** @var TicketService */
|
|
private $ticketService;
|
|
|
|
/** @var MatrixService */
|
|
private $matrixService;
|
|
|
|
/** @var TicketMapper */
|
|
private $ticketMapper;
|
|
|
|
/** @var UserMapper */
|
|
private $userMapper;
|
|
|
|
/** @var string */
|
|
private $userId = 'john';
|
|
|
|
public function setUp(): void {
|
|
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
|
|
$this->ticketMapper = $this->getMockBuilder(TicketMapper::class)
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$this->userMapper = $this->getMockBuilder(UserMapper::class)
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$this->matrixService = $this->getMockBuilder(MatrixService::class)
|
|
->disableOriginalConstructor()
|
|
->getMock();
|
|
$this->ticketService = new TicketService(
|
|
$this->userManager,
|
|
$this->matrixService,
|
|
$this->ticketMapper,
|
|
$this->userMapper,
|
|
new NullLogger(),
|
|
);
|
|
}
|
|
|
|
public function testAssign() {
|
|
$ticketId = 3;
|
|
$matrixControlRoom = "!room:server";
|
|
$assistedUserMatrixId = "@user:server";
|
|
$ticket = MatrixTicket::fromRow([
|
|
'id' => $ticketId,
|
|
'matrixControlRoom' => $matrixControlRoom,
|
|
'matrixAssistedUser' => $assistedUserMatrixId,
|
|
'matrixHelperUser' => null,
|
|
'status' => "open",
|
|
'version' => 1,
|
|
]);
|
|
$this->ticketMapper->expects($this->once())
|
|
->method('findTicket')
|
|
->with($this->equalTo($ticketId))
|
|
->willReturn($ticket);
|
|
$stubTicket = new MatrixTicket();
|
|
$stubTicket->setId($ticketId);
|
|
$stubTicket->setMatrixControlRoom($matrixControlRoom);
|
|
$this->ticketMapper->expects($this->once())
|
|
->method('update')
|
|
->willReturn($stubTicket);
|
|
|
|
$helperUserMatrixId = "@helper:server";
|
|
$helperUserName = "Expected Helper User Name";
|
|
$mockUser = $this->getMockBuilder(IUser::class)->getMock();
|
|
$mockUser->expects($this->once())
|
|
->method('getDisplayName')
|
|
->willReturn($helperUserName);
|
|
$this->userManager->expects($this->once())
|
|
->method('get')
|
|
->with($this->equalTo($this->userId))
|
|
->willReturn($mockUser);
|
|
$helperMatrixUser = new MatrixUser();
|
|
$helperMatrixUser->setUserId($helperUserMatrixId);
|
|
$this->userMapper->expects($this->once())
|
|
->method('find')
|
|
->with($this->equalTo($this->userId))
|
|
->willReturn($helperMatrixUser);
|
|
|
|
$this->matrixService->expects($this->once())
|
|
->method('getProperty')
|
|
->with($this->equalTo($matrixControlRoom))
|
|
->willReturn(array(
|
|
'id' => $ticketId,
|
|
'title' => $this->any(),
|
|
'description' => $this->any(),
|
|
'matrixControlRoom' => $matrixControlRoom,
|
|
'matrixAssistedUser' => $assistedUserMatrixId,
|
|
'matrixHelperUser' => $helperUserMatrixId,
|
|
'matrixHelperName' => $helperUserName,
|
|
'expirationDate' => $this->any(),
|
|
));
|
|
|
|
$result = $this->ticketService->assign($ticketId, $this->userId);
|
|
$this->assertEquals($helperUserName, $result['matrixHelperName']);
|
|
}
|
|
}
|