-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
868abde
commit e51fccf
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Tests\Feature; | ||
|
||
use Illuminate\Foundation\Testing\DatabaseMigrations; | ||
use Tests\FeatureTestCase; | ||
use Toby\Models\User; | ||
use Toby\Models\YearPeriod; | ||
|
||
class CalendarTest extends FeatureTestCase | ||
{ | ||
use DatabaseMigrations; | ||
|
||
protected User $user; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->user = User::factory()->create(); | ||
} | ||
|
||
public function testUserCanChangeYearPeriodOnTheCalendar(): void | ||
{ | ||
$currentYearPeriod = YearPeriod::current(); | ||
$nextYearPeriod = YearPeriod::query() | ||
->create([ | ||
"year" => $currentYearPeriod->year + 1, | ||
]); | ||
|
||
$this->assertNotEquals($currentYearPeriod->year, $nextYearPeriod->year); | ||
|
||
$this->actingAs($this->user) | ||
->get("/calendar/january/$nextYearPeriod->year") | ||
->assertRedirect(); | ||
|
||
$selectedYearPeriod = YearPeriod::query()->where("id", session()->get("selected_year_period"))->first(); | ||
$this->assertEquals($selectedYearPeriod->year, $nextYearPeriod->year); | ||
} | ||
|
||
public function testUserCannotChangeYearPeriodIfYearPeriodDoesNotExist(): void | ||
{ | ||
$currentYearPeriod = YearPeriod::current(); | ||
|
||
$this->actingAs($this->user) | ||
->get("/calendar/january/" . ($currentYearPeriod->year + 1)) | ||
->assertStatus(404); | ||
|
||
$this->actingAs($this->user) | ||
->get("/calendar/january/$currentYearPeriod->year") | ||
->assertStatus(302); | ||
} | ||
|
||
public function testUserCanSeeCalendar(): void | ||
{ | ||
$this->actingAs($this->user) | ||
->get("/calendar") | ||
->assertOk(); | ||
} | ||
} |