Skip to content

Commit

Permalink
Merge pull request #52 from he4rt/v2/test/meeting-domain-tests
Browse files Browse the repository at this point in the history
daniel, não apaga as parada que tão certa denovo!! kkkj
  • Loading branch information
danielhe4rt authored Mar 14, 2023
2 parents d783524 + c18a9b7 commit e300d0d
Show file tree
Hide file tree
Showing 8 changed files with 311 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Heart/Meeting/Domain/Actions/PersistAttendMeeting.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public function __construct(private readonly MeetingRepository $meetingRepositor
{
}

public function handle(string $meetingId, string $userId)
public function handle(string $meetingId, string $userId): void
{
$this->meetingRepository->attendMeeting($meetingId, $userId);
}
Expand Down
53 changes: 53 additions & 0 deletions tests/Unit/Meeting/Domain/Actions/CreateMeetingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Tests\Unit\Meeting\Domain\Actions;

use Heart\Meeting\Domain\Actions\CreateMeeting;
use Heart\Meeting\Domain\DTO\NewMeetingDTO;
use Heart\Meeting\Domain\Entities\MeetingEntity;
use Heart\Meeting\Domain\Repositories\MeetingRepository;
use Mockery as m;
use Mockery\MockInterface;
use Tests\TestCase;
use Tests\Unit\Meeting\MeetingProviderTrait;

class CreateMeetingTest extends TestCase
{
use MeetingProviderTrait;
private MockInterface $meetingTypeRepositoryStub;

private MeetingEntity $meetingEntity;

private NewMeetingDTO $payloadDTO;

public function setUp(): void
{
parent::setUp();
$this->meetingTypeRepositoryStub = m::mock(MeetingRepository::class);
$this->meetingEntity = $this->validMeetingEntity();
$this->payloadDTO = NewMeetingDTO::make(
'discord',
'canhassi',
$this->meetingEntity->meetingTypeId
);
}

public function tearDown(): void
{
parent::tearDown();
m::close();
}

public function testCreateMeeting(): void
{
$this->meetingTypeRepositoryStub
->shouldReceive('create')
->with($this->payloadDTO, $this->meetingEntity->adminId)
->once()
->andReturn($this->meetingEntity);

$test = new CreateMeeting($this->meetingTypeRepositoryStub);

$test->handle($this->payloadDTO, $this->meetingEntity->adminId);
}
}
64 changes: 64 additions & 0 deletions tests/Unit/Meeting/Domain/Actions/FindMeetingTypeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace Tests\Unit\Meeting\Domain\Actions;

use Heart\Meeting\Domain\Actions\FindMeetingType;
use Heart\Meeting\Domain\Entities\MeetingTypeEntity;
use Heart\Meeting\Domain\Exceptions\MeetingException;
use Heart\Meeting\Domain\Repositories\MeetingTypeRepository;
use Mockery as m;
use Mockery\MockInterface;
use Tests\TestCase;
use Tests\Unit\Meeting\MeetingTypeProviderTrait;

class FindMeetingTypeTest extends TestCase
{
use MeetingTypeProviderTrait;
private MockInterface $meetingTypeRepositoryStub;

private MeetingTypeEntity $meetingTypeEntity;

public function setUp(): void
{
parent::setUp();
$this->meetingTypeRepositoryStub = m::mock(MeetingTypeRepository::class);
$this->meetingEntity = $this->validMeetingTypeEntity();
}

public function tearDown(): void
{
parent::tearDown();
m::close();
}

public function testMeetingTypeIsNotFound(): void
{
$this->expectException(MeetingException::class);

$this->meetingTypeRepositoryStub
->shouldReceive('findById')
->with(12)
->once()
->andReturn(null);

$test = new FindMeetingType($this->meetingTypeRepositoryStub);

$test->handle(12);
}

/**
* @throws MeetingException
*/
public function testFindMeetingTypeSuccess(): void
{
$this->meetingTypeRepositoryStub
->shouldReceive('findById')
->with(2)
->once()
->andReturn($this->meetingEntity);

$test = new FindMeetingType($this->meetingTypeRepositoryStub);

$test->handle(2);
}
}
44 changes: 44 additions & 0 deletions tests/Unit/Meeting/Domain/Actions/FinishMeetingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace Tests\Unit\Meeting\Domain\Actions;

use Heart\Meeting\Domain\Actions\FinishMeeting;
use Heart\Meeting\Domain\Entities\MeetingEntity;
use Heart\Meeting\Domain\Repositories\MeetingRepository;
use Mockery as m;
use Mockery\MockInterface;
use Tests\TestCase;
use Tests\Unit\Meeting\MeetingProviderTrait;

class FinishMeetingTest extends TestCase
{
use MeetingProviderTrait;
private MockInterface $meetingRepositoryStub;

private MeetingEntity $meetingEntity;
public function setUp(): void
{
parent::setUp();
$this->meetingRepositoryStub = m::mock(MeetingRepository::class);
$this->meetingEntity = $this->validMeetingEntity();
}

public function tearDown(): void
{
parent::tearDown();
m::close();
}

public function testFinishMeeting(): void
{
$this->meetingRepositoryStub
->shouldReceive('endMeeting')
->with($this->meetingEntity->id)
->once()
->andReturn($this->meetingEntity);

$test = new FinishMeeting($this->meetingRepositoryStub);

$test->handle($this->meetingEntity->id);
}
}
50 changes: 50 additions & 0 deletions tests/Unit/Meeting/Domain/Actions/PaginateMeetingsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

namespace Tests\Unit\Meeting\Domain\Actions;

use Heart\Meeting\Domain\Actions\PaginateMeetings;
use Heart\Meeting\Domain\Entities\MeetingEntity;
use Heart\Meeting\Domain\Repositories\MeetingRepository;
use Heart\Provider\Domain\Enums\ProviderEnum;
use Heart\Shared\Domain\Paginator;
use Mockery\MockInterface;
use Mockery as m;
use Tests\TestCase;
use Tests\Unit\Meeting\MeetingProviderTrait;

class PaginateMeetingsTest extends TestCase
{
use MeetingProviderTrait;
private MockInterface $meetingRepositoryStub;

private MeetingEntity $meetingEntity;

private Paginator $paginatorStub;

public function setUp(): void
{
parent::setUp();
$this->meetingRepositoryStub = m::mock(MeetingRepository::class);
$this->meetingEntity = $this->validMeetingEntity();
$this->paginatorStub = m::mock(Paginator::class);
}

public function tearDown(): void
{
parent::tearDown();
m::close();
}

public function testPaginateMeetings(): void
{
$this->meetingRepositoryStub
->shouldReceive('paginate')
->with(['meetingType'])
->once()
->andReturn($this->paginatorStub);

$test = new PaginateMeetings($this->meetingRepositoryStub);

$test->handle(ProviderEnum::Discord);
}
}
47 changes: 47 additions & 0 deletions tests/Unit/Meeting/Domain/Actions/PersistAttendMeetingTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace Tests\Unit\Meeting\Domain\Actions;

use Heart\Meeting\Domain\Actions\PersistAttendMeeting;
use Heart\Meeting\Domain\DTO\NewMeetingDTO;
use Heart\Meeting\Domain\Entities\MeetingEntity;
use Heart\Meeting\Domain\Repositories\MeetingRepository;
use Mockery\MockInterface;
use Mockery as m;
use Tests\TestCase;
use Tests\Unit\Meeting\MeetingProviderTrait;

class PersistAttendMeetingTest extends TestCase
{
use MeetingProviderTrait;
private MockInterface $meetingTypeRepositoryStub;

private MeetingEntity $meetingEntity;

private NewMeetingDTO $payloadDTO;

public function setUp(): void
{
parent::setUp();
$this->meetingTypeRepositoryStub = m::mock(MeetingRepository::class);
$this->meetingEntity = $this->validMeetingEntity();
}

public function tearDown(): void
{
parent::tearDown();
m::close();
}

public function testPersistAttendMeeting(): void
{
$this->meetingTypeRepositoryStub
->shouldReceive('attendMeeting')
->with($this->meetingEntity->id, 12)
->once();

$test = new PersistAttendMeeting($this->meetingTypeRepositoryStub);

$test->handle($this->meetingEntity->id, 12);
}
}
28 changes: 28 additions & 0 deletions tests/Unit/Meeting/MeetingProviderTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace Tests\Unit\Meeting;

use Carbon\Carbon;
use Heart\Meeting\Domain\Entities\MeetingEntity;

trait MeetingProviderTrait
{
public function validMeetingPayload(array $fields = []): array
{
return [
'id' => 12,
'content' => null,
'meeting_type_id' => 12,
'admin_id' => "12",
'starts_at' => $time = Carbon::now(),
'ends_at' => $time->addMinutes(12),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
];
}

public function validMeetingEntity(): MeetingEntity
{
return MeetingEntity::make($this->validMeetingPayload());
}
}
24 changes: 24 additions & 0 deletions tests/Unit/Meeting/MeetingTypeProviderTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\Unit\Meeting;

use Carbon\Carbon;
use Heart\Meeting\Domain\Entities\MeetingTypeEntity;

trait MeetingTypeProviderTrait
{
public function validMeetingPayload(array $fields = []): array
{
return [
'id' => 12,
'name' => 'canhassi',
'week_day' => 1,
'start_at' => Carbon::now()
];
}

public function validMeetingTypeEntity(): MeetingTypeEntity
{
return MeetingTypeEntity::make($this->validMeetingPayload());
}
}

0 comments on commit e300d0d

Please sign in to comment.