Skip to content

Commit

Permalink
Fix consultation report proposed term (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
mako321 authored Dec 6, 2024
1 parent 31248f6 commit 9f86ec7
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Services/ConsultationService.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ public function reportTerm(int $consultationTermId, string $executedAt): bool
$userTerm = $this->consultationUserTermRepository->createUserTerm($consultationTerm, $data);

$consultationTerm->consultation->teachers
->push($consultationTerm->consultation->author)
->when(
$consultationTerm->consultation->author_id !== null,
fn ($teachers) => $teachers->push($consultationTerm->consultation->author)
)
->filter()
->each(function ($author) use ($consultationTerm, $userTerm) {
event(new ReportTerm($author, $consultationTerm, $userTerm));
Expand Down
31 changes: 31 additions & 0 deletions tests/APIs/ConsultationReportTermTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use EscolaLms\Consultations\Events\ApprovedTermWithTrainer;
use EscolaLms\Consultations\Events\RejectTermWithTrainer;
use EscolaLms\Consultations\Events\ReportTerm;
use EscolaLms\Consultations\Models\ConsultationProposedTerm;
use EscolaLms\Consultations\Models\ConsultationUserTerm;
use EscolaLms\Consultations\Tests\Models\User;
use EscolaLms\Consultations\Enum\ConsultationTermStatusEnum;
Expand Down Expand Up @@ -59,6 +61,35 @@ public function testConsultationReportTerm(): void
$this->response->assertOk();
}

public function testConsultationReportProposedTerm(): void
{
Event::fake([ReportTerm::class]);
$this->initVariable();
$this->consultation->update(['author_id' => null]);
$this->consultation->teachers()->attach([
User::factory()->create()->getKey(),
User::factory()->create()->getKey(),
]);

$proposedTerm = ConsultationProposedTerm::factory()
->state([
'proposed_at' => now()->addDays(2),
])
->for($this->consultation)
->create();

$this->response = $this->actingAs($this->user, 'api')
->json('POST',
'/api/consultations/report-term/' . $this->consultationUserPivot->getKey(),
[
'term' => $proposedTerm->proposed_at,
]
)
->assertOk();

Event::assertDispatchedTimes(ReportTerm::class, 2);
}

public function testConsultationReportTermMultipleTerm(): void
{
$this->initVariable();
Expand Down

0 comments on commit 9f86ec7

Please sign in to comment.