
* change layout * change layout * #22 - wip * wip * wip * #22 - wip * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - wip * #22 - added some tests * #22 - wip * #22 - wip * #22 - fix * #41 - wip * #22 - wip * #22 - wip * #22 - wip * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #22 - fix * #41 - wip * #41 - wip * #49 - laravel 9 * #41 - wip * #41 - fix * #41 - fix * Apply suggestions from code review Co-authored-by: Jacek Sawoszczuk <jacek.sawoszczuk@gmail.com> * #41 - cr fix * #41 - cr fix Co-authored-by: Adrian Hopek <adrian.hopek@blumilk.pl> Co-authored-by: Jacek Sawoszczuk <jacek.sawoszczuk@gmail.com>
71 lines
2.3 KiB
PHP
71 lines
2.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Unit;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Support\Facades\Notification;
|
|
use Tests\TestCase;
|
|
use Tests\Traits\InteractsWithYearPeriods;
|
|
use Toby\Domain\Enums\Role;
|
|
use Toby\Domain\Enums\VacationRequestState;
|
|
use Toby\Domain\Enums\VacationType;
|
|
use Toby\Domain\Notifications\VacationRequestWaitsForTechApprovalNotification;
|
|
use Toby\Domain\VacationRequestStateManager;
|
|
use Toby\Eloquent\Models\User;
|
|
use Toby\Eloquent\Models\VacationRequest;
|
|
use Toby\Eloquent\Models\YearPeriod;
|
|
|
|
class VacationRequestNotificationTest extends TestCase
|
|
{
|
|
use DatabaseMigrations;
|
|
use InteractsWithYearPeriods;
|
|
|
|
protected VacationRequestStateManager $stateManager;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
|
|
$this->stateManager = $this->app->make(VacationRequestStateManager::class);
|
|
|
|
$this->createCurrentYearPeriod();
|
|
}
|
|
|
|
public function testAfterChangingVacationRequestStateNotificationAreSentToUsers(): void
|
|
{
|
|
Notification::fake();
|
|
|
|
$user = User::factory([
|
|
"role" => Role::Employee,
|
|
])->createQuietly();
|
|
$technicalApprover = User::factory([
|
|
"role" => Role::TechnicalApprover,
|
|
])->createQuietly();
|
|
$administrativeApprover = User::factory([
|
|
"role" => Role::AdministrativeApprover,
|
|
])->createQuietly();
|
|
|
|
$currentYearPeriod = YearPeriod::current();
|
|
|
|
/** @var VacationRequest $vacationRequest */
|
|
$vacationRequest = VacationRequest::factory([
|
|
"type" => VacationType::Vacation->value,
|
|
"state" => VacationRequestState::Created,
|
|
"from" => Carbon::create($currentYearPeriod->year, 2, 1)->toDateString(),
|
|
"to" => Carbon::create($currentYearPeriod->year, 2, 4)->toDateString(),
|
|
"comment" => "Comment for the vacation request.",
|
|
])
|
|
->for($user)
|
|
->for($currentYearPeriod)
|
|
->create();
|
|
|
|
$this->stateManager->waitForTechnical($vacationRequest);
|
|
|
|
Notification::assertSentTo($technicalApprover, VacationRequestWaitsForTechApprovalNotification::class);
|
|
Notification::assertNotSentTo([$user, $administrativeApprover], VacationRequestWaitsForTechApprovalNotification::class);
|
|
}
|
|
}
|