feat: add TourProgressController and related entities for user tour progress tracking

- 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.
This commit is contained in:
hamed
2026-08-10 09:34:14 +03:30
parent 7716b40f6a
commit 20c8eaaad9
27 changed files with 16088 additions and 477 deletions
@@ -0,0 +1,62 @@
<?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());
}
}