diff --git a/backend/tests/Feature/Element/EloquentElementRepositoryTest.php b/backend/tests/Feature/Element/EloquentElementRepositoryTest.php index edddeac..c339903 100644 --- a/backend/tests/Feature/Element/EloquentElementRepositoryTest.php +++ b/backend/tests/Feature/Element/EloquentElementRepositoryTest.php @@ -10,6 +10,7 @@ use App\Set\SetRepository; use App\Shared\ValueObject\EmailAddress; use App\User\CreateUserDto; use App\User\UserRepository; +use DomainException; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; @@ -71,6 +72,31 @@ class EloquentElementRepositoryTest extends TestCase ); } + public function testItRejectsAParentFromAnotherSet(): void + { + $bible = $this->createSet('Bible'); + $course = $this->createSet('Course'); + $repository = app(ElementRepository::class); + $book = $repository->create(new CreateElementDto( + set: $bible, + name: 'Genesis', + kind: 'book', + parentElement: null, + )); + + $this->expectException(DomainException::class); + $this->expectExceptionMessage( + 'parent element must belong to the same set', + ); + + $repository->create(new CreateElementDto( + set: $course, + name: 'Invalid lesson', + kind: 'lesson', + parentElement: $book, + )); + } + private function createSet(string $name): Set { $creator = app(UserRepository::class)->create(new CreateUserDto(