add node to scheduled node
This commit is contained in:
parent
d47a0235d2
commit
a9265abeae
8 changed files with 88 additions and 6 deletions
|
|
@ -20,6 +20,7 @@ class FakeScheduledNodeRepository implements ScheduledNodeRepository
|
|||
id: $id,
|
||||
date: $dto->date,
|
||||
plan: $dto->plan,
|
||||
node: $dto->node,
|
||||
);
|
||||
$this->existingScheduledNodes[$id] = $scheduledNode;
|
||||
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ class CreatePlanTest extends TestCase
|
|||
$this->createScheduledNode = new CreateScheduledNode(
|
||||
scheduledNodeRepo: $this->scheduledNodeRepo,
|
||||
planRepo: $this->planRepo,
|
||||
nodeRepo: $this->nodeRepo,
|
||||
);
|
||||
$this->textRepo->create(new CreateTextDto('testname'));
|
||||
$this->useCase = new CreatePlan(
|
||||
|
|
|
|||
|
|
@ -3,15 +3,19 @@
|
|||
namespace Tests\Unit\ScheduledNode\UseCases;
|
||||
|
||||
use App\Exceptions\BadRequestException;
|
||||
use App\Node\CreateNodeDto;
|
||||
use App\Node\Node;
|
||||
use App\Plan\CreatePlanDto;
|
||||
use App\Plan\Plan;
|
||||
use App\ScheduledNode\ScheduledNode;
|
||||
use App\ScheduledNode\ScheduledNodeRepository;
|
||||
use App\ScheduledNode\UseCases\CreateScheduledNode;
|
||||
use App\ScheduledNode\UseCases\CreateScheduledNodeRequest;
|
||||
use App\Text\Text;
|
||||
use App\User\User;
|
||||
use App\ValueObjects\EmailAddress;
|
||||
use DomainException;
|
||||
use Tests\Fakes\FakeNodeRepository;
|
||||
use Tests\Fakes\FakePlanRepository;
|
||||
use Tests\Fakes\FakeScheduledNodeRepository;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
|
@ -22,12 +26,20 @@ class CreateScheduledNodeTest extends TestCase
|
|||
|
||||
private FakePlanRepository $planRepo;
|
||||
|
||||
private FakeNodeRepository $nodeRepo;
|
||||
|
||||
private CreateScheduledNode $useCase;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->scheduledNodeRepo = new FakeScheduledNodeRepository();
|
||||
$this->planRepo = new FakePlanRepository();
|
||||
$this->nodeRepo = new FakeNodeRepository();
|
||||
$this->nodeRepo->create(new CreateNodeDto(
|
||||
text: new Text(0, 'text name'),
|
||||
title: 'test node',
|
||||
parentNode: null,
|
||||
));
|
||||
$this->planRepo->create(new CreatePlanDto(
|
||||
name: 'testplan',
|
||||
user: new User(
|
||||
|
|
@ -40,6 +52,7 @@ class CreateScheduledNodeTest extends TestCase
|
|||
$this->useCase = new CreateScheduledNode(
|
||||
$this->scheduledNodeRepo,
|
||||
$this->planRepo,
|
||||
$this->nodeRepo,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -49,6 +62,7 @@ class CreateScheduledNodeTest extends TestCase
|
|||
new CreateScheduledNodeRequest(
|
||||
date: '2025-01-01',
|
||||
planId: 0,
|
||||
nodeId: 0,
|
||||
)
|
||||
);
|
||||
$this->assertInstanceOf(ScheduledNode::class, $scheduledNode);
|
||||
|
|
@ -64,11 +78,24 @@ class CreateScheduledNodeTest extends TestCase
|
|||
new CreateScheduledNodeRequest(
|
||||
date: '2025-01-01',
|
||||
planId: 0,
|
||||
nodeId: 0
|
||||
)
|
||||
);
|
||||
$this->assertInstanceOf(Plan::class, $scheduledNode->getPlan());
|
||||
}
|
||||
|
||||
public function test_scheduled_node_belongs_to_node(): void
|
||||
{
|
||||
$scheduledNode = $this->useCase->execute(
|
||||
new CreateScheduledNodeRequest(
|
||||
date: '2025-01-01',
|
||||
planId: 0,
|
||||
nodeId: 0
|
||||
)
|
||||
);
|
||||
$this->assertInstanceOf(Node::class, $scheduledNode->getNode());
|
||||
}
|
||||
|
||||
public function test_nonexistant_plan_throws(): void
|
||||
{
|
||||
$this->expectException(DomainException::class);
|
||||
|
|
@ -77,6 +104,20 @@ class CreateScheduledNodeTest extends TestCase
|
|||
new CreateScheduledNodeRequest(
|
||||
date: '2025-01-01',
|
||||
planId: 1,
|
||||
nodeId: 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_nonexistant_node_throws(): void
|
||||
{
|
||||
$this->expectException(DomainException::class);
|
||||
$this->expectExceptionMessage('Node with id: 1 doesnt exist');
|
||||
$this->useCase->execute(
|
||||
new CreateScheduledNodeRequest(
|
||||
date: '2025-01-01',
|
||||
planId: 0,
|
||||
nodeId: 1,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -90,6 +131,7 @@ class CreateScheduledNodeTest extends TestCase
|
|||
new CreateScheduledNodeRequest(
|
||||
date: null,
|
||||
planId: 0,
|
||||
nodeId: 0
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
@ -103,6 +145,21 @@ class CreateScheduledNodeTest extends TestCase
|
|||
new CreateScheduledNodeRequest(
|
||||
date: '2025-01-01',
|
||||
planId: null,
|
||||
nodeId: 0,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public function test_throws_if_node_id_is_null(): void
|
||||
{
|
||||
$this->expectException(BadRequestException::class);
|
||||
$this->expectExceptionMessage('nodeId is required');
|
||||
|
||||
$this->useCase->execute(
|
||||
new CreateScheduledNodeRequest(
|
||||
date: '2025-01-01',
|
||||
planId: 0,
|
||||
nodeId: null,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ class PlanControllerTest extends TestCase
|
|||
$createScheduledNode = new CreateScheduledNode(
|
||||
scheduledNodeRepo: $this->scheduledNodeRepo,
|
||||
planRepo: $this->planRepo,
|
||||
nodeRepo: $this->nodeRepo,
|
||||
);
|
||||
$this->createPlan = new CreatePlan(
|
||||
$this->planRepo,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue