- Implemented TourProgressController to handle API endpoints for tracking guided tours seen by users. - Created UserTourProgress entity to store the highest version of tours seen by each user. - Developed UserTourProgressRepository for database interactions related to user tour progress. - Introduced TourProgressService to manage business logic for marking tours as seen and retrieving seen maps. - Added comprehensive tests for API endpoints and entity behavior to ensure functionality and data integrity.
63 lines
1.9 KiB
PHP
63 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Tests\UserProfile;
|
|
|
|
use App\Tests\ApiTestCase;
|
|
use App\UserProfile\Entity\UserTourProgress;
|
|
use App\UserProfile\Repository\UserTourProgressRepository;
|
|
use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
|
|
|
|
class UserTourProgressTest extends ApiTestCase
|
|
{
|
|
public function testSeenMapReturnsVersionPerTour(): void
|
|
{
|
|
$user = $this->createUser();
|
|
|
|
$this->em->persist(new UserTourProgress($user, 'appointments', 1));
|
|
$this->em->persist(new UserTourProgress($user, 'patients', 3));
|
|
$this->em->flush();
|
|
|
|
/** @var UserTourProgressRepository $repo */
|
|
$repo = $this->em->getRepository(UserTourProgress::class);
|
|
|
|
self::assertSame(['appointments' => 1, 'patients' => 3], $repo->seenMap($user));
|
|
}
|
|
|
|
public function testSeenMapIsScopedToTheUser(): void
|
|
{
|
|
$user = $this->createUser();
|
|
$other = $this->createUser();
|
|
|
|
$this->em->persist(new UserTourProgress($other, 'appointments', 1));
|
|
$this->em->flush();
|
|
|
|
/** @var UserTourProgressRepository $repo */
|
|
$repo = $this->em->getRepository(UserTourProgress::class);
|
|
|
|
self::assertSame([], $repo->seenMap($user));
|
|
}
|
|
|
|
public function testTheSameTourCannotBeStoredTwiceForOneUser(): void
|
|
{
|
|
$user = $this->createUser();
|
|
|
|
$this->em->persist(new UserTourProgress($user, 'appointments', 1));
|
|
$this->em->flush();
|
|
|
|
$this->em->persist(new UserTourProgress($user, 'appointments', 2));
|
|
|
|
$this->expectException(UniqueConstraintViolationException::class);
|
|
$this->em->flush();
|
|
}
|
|
|
|
public function testMarkSeenNeverLowersTheStoredVersion(): void
|
|
{
|
|
$user = $this->createUser();
|
|
$progress = new UserTourProgress($user, 'appointments', 4);
|
|
|
|
$progress->markSeen(2);
|
|
|
|
self::assertSame(4, $progress->getVersion());
|
|
}
|
|
}
|