test that creating a plan is done in context of a text and schedules all nodes of text
This commit is contained in:
parent
2affd2a84e
commit
a32989334e
1 changed files with 42 additions and 2 deletions
|
|
@ -2,33 +2,52 @@
|
|||
|
||||
namespace Tests\Unit\Plan\UseCases;
|
||||
|
||||
use App\Node\CreateNodeDto;
|
||||
use App\Plan\UseCases\CreatePlan;
|
||||
use App\Plan\UseCases\CreatePlanRequest;
|
||||
use App\ScheduledNode\UseCases\CreateScheduledNode;
|
||||
use App\Text\CreateTextDto;
|
||||
use App\User\UseCases\CreateUserDto;
|
||||
use App\User\User;
|
||||
use App\User\UserRepository;
|
||||
use App\ValueObjects\EmailAddress;
|
||||
use DomainException;
|
||||
use Tests\Fakes\FakeNodeRepository;
|
||||
use Tests\Fakes\FakePlanRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tests\Fakes\FakeScheduledNodeRepository;
|
||||
use Tests\Fakes\FakeTextRepository;
|
||||
use Tests\Fakes\FakeUserRepository;
|
||||
|
||||
class CreatePlanTest extends TestCase
|
||||
{
|
||||
private FakePlanRepository $planRepo;
|
||||
private UserRepository $userRepo;
|
||||
private FakeUserRepository $userRepo;
|
||||
private FakeTextRepository $textRepo;
|
||||
private FakeNodeRepository $nodeRepo;
|
||||
private FakeScheduledNodeRepository $scheduledNodeRepo;
|
||||
private CreateScheduledNode $createScheduledNode;
|
||||
private CreatePlan $useCase;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->planRepo = new FakePlanRepository;
|
||||
$this->userRepo = new FakeUserRepository;
|
||||
$this->textRepo = new FakeTextRepository;
|
||||
$this->nodeRepo = new FakeNodeRepository;
|
||||
$this->scheduledNodeRepo = new FakeScheduledNodeRepository;
|
||||
$this->userRepo->create(new CreateUserDto(
|
||||
email: new EmailAddress('test@test.com'),
|
||||
));
|
||||
$this->createScheduledNode = new CreateScheduledNode(
|
||||
scheduledNodeRepo: $this->scheduledNodeRepo,
|
||||
planRepo: $this->planRepo,
|
||||
);
|
||||
$this->useCase = new CreatePlan(
|
||||
$this->planRepo,
|
||||
$this->userRepo,
|
||||
$this->textRepo,
|
||||
$this->nodeRepo,
|
||||
$this->createScheduledNode,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -37,6 +56,7 @@ class CreatePlanTest extends TestCase
|
|||
$plan = $this->useCase->execute(new CreatePlanRequest(
|
||||
userId: 0,
|
||||
name: 'testPlan',
|
||||
textId: 0,
|
||||
));
|
||||
$this->assertEquals('testPlan', $plan->getName());
|
||||
}
|
||||
|
|
@ -46,6 +66,7 @@ class CreatePlanTest extends TestCase
|
|||
$plan = $this->useCase->execute(new CreatePlanRequest(
|
||||
userId: 0,
|
||||
name: 'testPlan',
|
||||
textId: 0,
|
||||
));
|
||||
$this->assertInstanceOf(User::class, $plan->getUser());
|
||||
}
|
||||
|
|
@ -57,6 +78,25 @@ class CreatePlanTest extends TestCase
|
|||
$plan = $this->useCase->execute(new CreatePlanRequest(
|
||||
userId: 1,
|
||||
name: 'testPlan',
|
||||
textId: 0,
|
||||
));
|
||||
}
|
||||
|
||||
public function test_plan_schedules_nodes_on_creation(): void
|
||||
{
|
||||
$text = $this->textRepo->create(new CreateTextDto(
|
||||
name: 'testname',
|
||||
));
|
||||
$this->nodeRepo->create(new CreateNodeDto(
|
||||
text: $text,
|
||||
title: 'testtitle',
|
||||
parentNode: null,
|
||||
));
|
||||
$plan = $this->useCase->execute(new CreatePlanRequest(
|
||||
userId: 0,
|
||||
name: 'testPlan',
|
||||
textId: 0,
|
||||
));
|
||||
$this->assertNotNull($this->scheduledNodeRepo->find(0));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue