create(); $visibleProject = Project::factory()->create([ 'name' => 'Visible project', ]); Project::factory()->create([ 'name' => 'Hidden project', ]); $this->syncProjectPermissions($visibleProject, $user, ['view']); $this->withApplicationKey($user) ->getJson(route('api.projects.index')) ->assertOk() ->assertJsonPath('data.0.name', 'Visible project') ->assertJsonCount(1, 'data'); } public function test_users_with_project_create_permission_can_create_projects(): void { $user = User::factory()->create(); $this->syncGlobalPermissions($user, ['create']); $this->withApplicationKey($user) ->postJson(route('api.projects.store'), [ 'key' => 'api', 'name' => 'API Project', ]) ->assertCreated() ->assertJsonPath('data.key', 'API') ->assertJsonPath('data.name', 'API Project') ->assertJsonPath('meta.message', 'API Project was created.'); $project = Project::query()->where('key', 'API')->firstOrFail(); $this->assertSame(2, $project->ticketTypes()->count()); $this->assertSame(1, $project->ticketStatuses()->count()); } public function test_project_show_and_delete_enforce_permissions(): void { $user = User::factory()->create(); $admin = User::factory()->create(); $project = Project::factory()->create([ 'key' => 'CORE', ]); app(InitializeProjectTicketMetadata::class)->handle($project); $this->withApplicationKey($user) ->getJson(route('api.projects.show', $project)) ->assertForbidden(); $this->syncProjectPermissions($project, $user, ['view']); $this->withApplicationKey($user) ->getJson(route('api.projects.show', $project)) ->assertOk() ->assertJsonPath('data.key', 'CORE'); $this->syncGlobalPermissions($admin, ['admin']); $this->withApplicationKey($admin) ->deleteJson(route('api.projects.destroy', $project), [ 'confirmation_key' => 'CORE', ]) ->assertNoContent(); $this->assertDatabaseMissing('projects', [ 'id' => $project->id, ]); } }