2021-08-21 14:17:14 +00:00
|
|
|
<?php
|
2023-10-11 19:55:03 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
// SPDX-FileCopyrightText: BVSC e.V. <no@example.com>
|
|
|
|
// SPDX-License-Identifier: AGPL-3.0-or-later
|
2021-08-21 14:17:14 +00:00
|
|
|
|
2021-10-10 17:51:12 +00:00
|
|
|
namespace OCA\UPschooling\Tests\Unit\Service;
|
2021-08-21 14:17:14 +00:00
|
|
|
|
2021-09-18 17:28:10 +00:00
|
|
|
use OCA\UPschooling\Db\MatrixTicket;
|
2023-10-11 19:55:03 +00:00
|
|
|
use OCA\UPschooling\Db\MatrixUser;
|
2021-09-18 17:28:10 +00:00
|
|
|
use OCA\UPschooling\Db\TicketMapper;
|
2021-09-19 14:55:30 +00:00
|
|
|
use OCA\UPschooling\Db\UserMapper;
|
2023-10-11 19:55:03 +00:00
|
|
|
use OCA\UPschooling\Exceptions\TicketNotFoundException;
|
2021-09-18 19:15:03 +00:00
|
|
|
use OCA\UPschooling\Service\MatrixService;
|
2021-08-22 15:03:19 +00:00
|
|
|
use OCA\UPschooling\Service\TicketService;
|
2021-09-18 17:28:10 +00:00
|
|
|
use OCP\AppFramework\Db\DoesNotExistException;
|
2023-10-11 19:55:03 +00:00
|
|
|
use OCP\IUser;
|
|
|
|
use OCP\IUserManager;
|
2021-09-18 17:28:10 +00:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2021-09-18 19:15:03 +00:00
|
|
|
use Psr\Log\NullLogger;
|
2021-08-21 14:17:14 +00:00
|
|
|
|
2021-10-10 17:51:12 +00:00
|
|
|
class TicketServiceTest extends TestCase {
|
2021-09-18 19:15:03 +00:00
|
|
|
|
|
|
|
/** @var TicketService */
|
2023-10-11 19:55:03 +00:00
|
|
|
private $ticketService;
|
2021-09-18 19:15:03 +00:00
|
|
|
|
|
|
|
/** @var MatrixService */
|
|
|
|
private $matrixService;
|
|
|
|
|
|
|
|
/** @var TicketMapper */
|
2021-09-19 14:55:30 +00:00
|
|
|
private $ticketMapper;
|
|
|
|
|
|
|
|
/** @var UserMapper */
|
|
|
|
private $userMapper;
|
2021-09-18 19:15:03 +00:00
|
|
|
|
|
|
|
/** @var string */
|
2021-08-21 14:17:14 +00:00
|
|
|
private $userId = 'john';
|
|
|
|
|
|
|
|
public function setUp(): void {
|
2023-10-11 19:55:03 +00:00
|
|
|
$this->userManager = $this->getMockBuilder(IUserManager::class)->getMock();
|
2021-09-19 14:55:30 +00:00
|
|
|
$this->ticketMapper = $this->getMockBuilder(TicketMapper::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->userMapper = $this->getMockBuilder(UserMapper::class)
|
2021-08-21 14:17:14 +00:00
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
2023-10-11 19:55:03 +00:00
|
|
|
$this->matrixService = $this->getMockBuilder(MatrixService::class)
|
|
|
|
->disableOriginalConstructor()
|
|
|
|
->getMock();
|
|
|
|
$this->ticketService = new TicketService(
|
|
|
|
$this->userManager,
|
|
|
|
$this->matrixService,
|
|
|
|
$this->ticketMapper,
|
|
|
|
$this->userMapper,
|
|
|
|
new NullLogger(),
|
|
|
|
);
|
2021-08-21 14:17:14 +00:00
|
|
|
}
|
|
|
|
|
2023-10-11 19:55:03 +00:00
|
|
|
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,
|
2021-08-21 14:17:14 +00:00
|
|
|
]);
|
2021-09-19 14:55:30 +00:00
|
|
|
$this->ticketMapper->expects($this->once())
|
2023-10-11 19:55:03 +00:00
|
|
|
->method('findTicket')
|
|
|
|
->with($this->equalTo($ticketId))
|
|
|
|
->willReturn($ticket);
|
|
|
|
$stubTicket = new MatrixTicket();
|
|
|
|
$stubTicket->setId($ticketId);
|
|
|
|
$stubTicket->setMatrixControlRoom($matrixControlRoom);
|
2021-09-19 14:55:30 +00:00
|
|
|
$this->ticketMapper->expects($this->once())
|
2021-08-21 14:17:14 +00:00
|
|
|
->method('update')
|
2023-10-11 19:55:03 +00:00
|
|
|
->willReturn($stubTicket);
|
2021-08-21 14:17:14 +00:00
|
|
|
|
2023-10-11 19:55:03 +00:00
|
|
|
$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())
|
2021-08-21 14:17:14 +00:00
|
|
|
->method('find')
|
2023-10-11 19:55:03 +00:00
|
|
|
->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(),
|
|
|
|
));
|
2021-08-21 14:17:14 +00:00
|
|
|
|
2023-10-11 19:55:03 +00:00
|
|
|
$result = $this->ticketService->assign($ticketId, $this->userId);
|
|
|
|
$this->assertEquals($helperUserName, $result['matrixHelperName']);
|
2021-08-21 14:17:14 +00:00
|
|
|
}
|
|
|
|
}
|