toby/tests/Feature/SelectYearPeriodTest.php
Adrian Hopek 558dd27fee #23 - wip
2022-01-24 08:38:06 +01:00

47 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Carbon;
use Tests\FeatureTestCase;
use Toby\Helpers\YearPeriodRetriever;
use Toby\Models\User;
class SelectYearPeriodTest extends FeatureTestCase
{
use DatabaseMigrations;
public function testUserCanSelectNextYearPeriod(): void
{
$nextYearPeriod = $this->createYearPeriod(Carbon::now()->year + 1);
$user = User::factory()->create();
$yearPeriodRetriever = new YearPeriodRetriever();
$this->actingAs($user)
->post("/year-periods/{$nextYearPeriod->id}/select")
->assertRedirect();
$this->assertSame($nextYearPeriod->id, $yearPeriodRetriever->selected()->id);
}
public function testUserCannotSelectNextYearPeriodIfDoesntExist(): void
{
$user = User::factory()->create();
$this->actingAs($user)
->post("/year-periods/25/select")
->assertNotFound();
}
public function testIfUserDoesntSelectAnyYearPeriodCurrentActsAsSelected(): void
{
$yearPeriodRetriever = new YearPeriodRetriever();
$currentYearPeriod = $yearPeriodRetriever->current();
$this->assertSame($currentYearPeriod->id, $yearPeriodRetriever->selected()->id);
}
}