test element parent scope

This commit is contained in:
Yisroel Baum 2026-08-08 22:21:49 +03:00
parent fcc6ade8f3
commit eccfed2350
Signed by: yisroelbaum
GPG key ID: 0FA60884F75520A9

View file

@ -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(