-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: public routes cannot get guests users (#22)
- Loading branch information
1 parent
c779783
commit b28fe4d
Showing
6 changed files
with
126 additions
and
18 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
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
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
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
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,88 @@ | ||
<?php | ||
|
||
namespace Tests\Feature; | ||
|
||
use App\Models\Calendar; | ||
use App\Models\User; | ||
use Illuminate\Foundation\Testing\RefreshDatabase; | ||
use Illuminate\Foundation\Testing\WithFaker; | ||
use Tests\TestCase; | ||
use Tests\Traits\UseFirebaseUser; | ||
|
||
class CalendarPrivacyTest extends TestCase | ||
{ | ||
use RefreshDatabase, UseFirebaseUser; | ||
|
||
public function test_it_allows_guests_to_view_public_calendars(): void | ||
{ | ||
$user = $this->createUser(); | ||
$calendar = Calendar::factory()->create([ | ||
'user_id' => $user->id, | ||
'is_public' => true | ||
]); | ||
// Does not use any user to fetch the calendar | ||
|
||
$response = $this->getJson(route('calendars.show', $calendar->uuid)); | ||
|
||
$response->assertOk(); | ||
} | ||
|
||
public function test_it_allows_other_users_to_view_public_calendars(): void | ||
{ | ||
$user1 = User::create(['id' => 'unused-user']); | ||
$calendar = Calendar::factory()->create([ | ||
'user_id' => $user1->id, | ||
'is_public' => true | ||
]); | ||
$firebaseUser = $this->createUser(); | ||
$this->actingAsFirebaseUser($firebaseUser); | ||
|
||
$response = $this->getJson(route('calendars.show', $calendar->uuid)); | ||
|
||
$response->assertOk(); | ||
} | ||
|
||
public function test_it_allows_owners_to_view_own_calendars(): void | ||
{ | ||
$user = $this->createUser(); | ||
$calendar = Calendar::factory()->create([ | ||
'user_id' => $user->id, | ||
'is_public' => false | ||
]); | ||
$this->actingAsFirebaseUser($user); | ||
|
||
$response = $this->getJson(route('calendars.show', $calendar->uuid)); | ||
|
||
$response->assertOk(); | ||
} | ||
|
||
public function test_it_denies_guests_to_see_private_calendars(): void | ||
{ | ||
$user = $this->createUser(); | ||
$calendar = Calendar::factory()->create([ | ||
'user_id' => $user->id, | ||
'is_public' => false | ||
]); | ||
// Does not use any user to fetch the calendar | ||
|
||
$response = $this->getJson(route('calendars.show', $calendar->uuid)); | ||
|
||
$response->assertForbidden(); | ||
} | ||
|
||
public function test_it_denies_other_users_to_see_private_calendars(): void | ||
{ | ||
$user = User::create(['id' => 'owner-user']); | ||
$calendar = Calendar::factory()->create([ | ||
'user_id' => $user->id, | ||
'is_public' => false | ||
]); | ||
$firebaseUser = $this->createUser(); | ||
$this->actingAsFirebaseUser($firebaseUser); | ||
|
||
$response = $this->getJson(route('calendars.show', $calendar->uuid)); | ||
|
||
$response->assertForbidden(); | ||
} | ||
|
||
} |
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