Add authentication and authorization tests for department index method

This commit is contained in:
Marcus Moore 2023-08-07 17:42:28 -07:00
parent 7c5a1b376e
commit 42055bb69d
No known key found for this signature in database

View file

@ -5,6 +5,7 @@ namespace Tests\Feature\Api\Departments;
use App\Models\Company;
use App\Models\Department;
use App\Models\User;
use Illuminate\Routing\Route;
use Illuminate\Testing\Fluent\AssertableJson;
use Tests\Support\InteractsWithSettings;
use Tests\TestCase;
@ -13,6 +14,18 @@ class DepartmentIndexTest extends TestCase
{
use InteractsWithSettings;
public function testViewingDepartmentIndexRequiresAuthentication()
{
$this->getJson(route('api.departments.index'))->assertRedirect();
}
public function testViewingDepartmentIndexRequiresPermission()
{
$this->actingAsForApi(User::factory()->create())
->getJson(route('api.departments.index'))
->assertForbidden();
}
public function testDepartmentIndexReturnsExpectedDepartments()
{
Department::factory()->count(3)->create();