From c18a9b7ff81186d7cc1cc9cb1a029d5bad2140e6 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 27 Feb 2023 01:10:23 -0300 Subject: [PATCH] =?UTF-8?q?daniel,=20n=C3=A3o=20apaga=20as=20parada=20que?= =?UTF-8?q?=20t=C3=A3o=20certa=20denovo=20kkkkj?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Domain/Actions/PersistAttendMeeting.php | 2 +- .../Domain/Actions/CreateMeetingTest.php | 53 +++++++++++++++ .../Domain/Actions/FindMeetingTypeTest.php | 64 +++++++++++++++++++ .../Domain/Actions/FinishMeetingTest.php | 44 +++++++++++++ .../Domain/Actions/PaginateMeetingsTest.php | 50 +++++++++++++++ .../Actions/PersistAttendMeetingTest.php | 47 ++++++++++++++ tests/Unit/Meeting/MeetingProviderTrait.php | 28 ++++++++ .../Unit/Meeting/MeetingTypeProviderTrait.php | 24 +++++++ 8 files changed, 311 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/Meeting/Domain/Actions/CreateMeetingTest.php create mode 100644 tests/Unit/Meeting/Domain/Actions/FindMeetingTypeTest.php create mode 100644 tests/Unit/Meeting/Domain/Actions/FinishMeetingTest.php create mode 100644 tests/Unit/Meeting/Domain/Actions/PaginateMeetingsTest.php create mode 100644 tests/Unit/Meeting/Domain/Actions/PersistAttendMeetingTest.php create mode 100644 tests/Unit/Meeting/MeetingProviderTrait.php create mode 100644 tests/Unit/Meeting/MeetingTypeProviderTrait.php diff --git a/Heart/Meeting/Domain/Actions/PersistAttendMeeting.php b/Heart/Meeting/Domain/Actions/PersistAttendMeeting.php index 2e9e74c..db374e5 100644 --- a/Heart/Meeting/Domain/Actions/PersistAttendMeeting.php +++ b/Heart/Meeting/Domain/Actions/PersistAttendMeeting.php @@ -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); } diff --git a/tests/Unit/Meeting/Domain/Actions/CreateMeetingTest.php b/tests/Unit/Meeting/Domain/Actions/CreateMeetingTest.php new file mode 100644 index 0000000..8d42265 --- /dev/null +++ b/tests/Unit/Meeting/Domain/Actions/CreateMeetingTest.php @@ -0,0 +1,53 @@ +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); + } +} diff --git a/tests/Unit/Meeting/Domain/Actions/FindMeetingTypeTest.php b/tests/Unit/Meeting/Domain/Actions/FindMeetingTypeTest.php new file mode 100644 index 0000000..c84c579 --- /dev/null +++ b/tests/Unit/Meeting/Domain/Actions/FindMeetingTypeTest.php @@ -0,0 +1,64 @@ +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); + } +} diff --git a/tests/Unit/Meeting/Domain/Actions/FinishMeetingTest.php b/tests/Unit/Meeting/Domain/Actions/FinishMeetingTest.php new file mode 100644 index 0000000..2330549 --- /dev/null +++ b/tests/Unit/Meeting/Domain/Actions/FinishMeetingTest.php @@ -0,0 +1,44 @@ +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); + } +} diff --git a/tests/Unit/Meeting/Domain/Actions/PaginateMeetingsTest.php b/tests/Unit/Meeting/Domain/Actions/PaginateMeetingsTest.php new file mode 100644 index 0000000..708d2e2 --- /dev/null +++ b/tests/Unit/Meeting/Domain/Actions/PaginateMeetingsTest.php @@ -0,0 +1,50 @@ +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); + } +} diff --git a/tests/Unit/Meeting/Domain/Actions/PersistAttendMeetingTest.php b/tests/Unit/Meeting/Domain/Actions/PersistAttendMeetingTest.php new file mode 100644 index 0000000..b4d75d7 --- /dev/null +++ b/tests/Unit/Meeting/Domain/Actions/PersistAttendMeetingTest.php @@ -0,0 +1,47 @@ +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); + } +} diff --git a/tests/Unit/Meeting/MeetingProviderTrait.php b/tests/Unit/Meeting/MeetingProviderTrait.php new file mode 100644 index 0000000..297c348 --- /dev/null +++ b/tests/Unit/Meeting/MeetingProviderTrait.php @@ -0,0 +1,28 @@ + 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()); + } +} diff --git a/tests/Unit/Meeting/MeetingTypeProviderTrait.php b/tests/Unit/Meeting/MeetingTypeProviderTrait.php new file mode 100644 index 0000000..9ad7e6d --- /dev/null +++ b/tests/Unit/Meeting/MeetingTypeProviderTrait.php @@ -0,0 +1,24 @@ + 12, + 'name' => 'canhassi', + 'week_day' => 1, + 'start_at' => Carbon::now() + ]; + } + + public function validMeetingTypeEntity(): MeetingTypeEntity + { + return MeetingTypeEntity::make($this->validMeetingPayload()); + } +}