function it_does_not_allow_changing_priority_if_editor_is_not_organization_organizationMember(OrganizationRepository $organizationRepository, ProjectRepository $projectRepository, TaskRepository $taskRepository, ChangeTaskPriorityCommand $command, Task $task, Project $project, ProjectId $projectId, OrganizationId $organizationId, Organization $organization) { $command->id()->shouldBeCalled()->willReturn('task-id'); $command->editorId()->shouldBeCalled()->willReturn('editor-id'); $taskRepository->taskOfId(Argument::type(TaskId::class))->shouldBeCalled()->willReturn($task); $task->projectId()->shouldBeCalled()->willReturn($projectId); $projectRepository->projectOfId($projectId)->shouldBeCalled()->willReturn($project); $project->organizationId()->shouldBeCalled()->willReturn($organizationId); $organizationRepository->organizationOfId($organizationId)->shouldBeCalled()->willReturn($organization); $organization->isOrganizationMember(UserId::generate('editor-id'))->shouldBeCalled()->willReturn(false); $this->shouldThrow(UnauthorizedTaskActionException::class)->during('__invoke', [$command]); }
public function __invoke(ChangeTaskPriorityCommand $command) { $task = $this->taskRepository->taskOfId(TaskId::generate($command->id())); if (!$task instanceof Task) { throw new TaskDoesNotExistException(); } $project = $this->projectRepository->projectOfId($task->projectId()); $organization = $this->organizationRepository->organizationOfId($project->organizationId()); if (!$organization->isOrganizationMember(UserId::generate($command->editorId()))) { throw new UnauthorizedTaskActionException(); } $task->changePriority(new TaskPriority($command->priority())); $this->taskRepository->persist($task); }