From 0f3663380c7224411f2c767461457db78db7bdce Mon Sep 17 00:00:00 2001 From: Alfred Nutile Date: Mon, 25 Mar 2024 12:07:38 -0400 Subject: [PATCH] add collections --- app/Http/Controllers/CollectionController.php | 25 ++++++++++--------- app/Http/Middleware/HandleInertiaRequests.php | 2 +- app/Jobs/ProcessFileJob.php | 8 +++--- routes/web.php | 3 +-- .../Controllers/CollectionControllerTest.php | 12 +++------ tests/Feature/UpdateTeamMemberRoleTest.php | 6 ++--- tests/TestCase.php | 4 +-- 7 files changed, 28 insertions(+), 32 deletions(-) diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php index 892caf8f..7e2c3907 100644 --- a/app/Http/Controllers/CollectionController.php +++ b/app/Http/Controllers/CollectionController.php @@ -4,22 +4,22 @@ use App\Http\Resources\CollectionResource; use App\Models\Collection; -use Illuminate\Http\Request; class CollectionController extends Controller { - - public function index() { + public function index() + { - return inertia("Collection/Index", [ + return inertia('Collection/Index', [ 'collections' => CollectionResource::collection(Collection::query() - ->where("team_id", auth()->user()->current_team_id) - ->get()) + ->where('team_id', auth()->user()->current_team_id) + ->get()), ]); } - public function store() { - + public function store() + { + $validated = request()->validate([ 'name' => 'required', 'description' => 'required', @@ -31,14 +31,15 @@ public function store() { /** * Make and then reditect to the view page */ - request()->session()->flash("flash.banner", "Collection created successfully!"); + request()->session()->flash('flash.banner', 'Collection created successfully!'); return to_route('collections.show', $collection); } - public function show(Collection $collection) { - return inertia("Collection/Show", [ - 'collection' => new CollectionResource($collection) + public function show(Collection $collection) + { + return inertia('Collection/Show', [ + 'collection' => new CollectionResource($collection), ]); } } diff --git a/app/Http/Middleware/HandleInertiaRequests.php b/app/Http/Middleware/HandleInertiaRequests.php index a677547e..9bc66810 100644 --- a/app/Http/Middleware/HandleInertiaRequests.php +++ b/app/Http/Middleware/HandleInertiaRequests.php @@ -37,7 +37,7 @@ public function version(Request $request): ?string public function share(Request $request): array { return array_merge(parent::share($request), [ - 'app_name' => config("app.name"), + 'app_name' => config('app.name'), 'features' => Feature::all(), ]); } diff --git a/app/Jobs/ProcessFileJob.php b/app/Jobs/ProcessFileJob.php index f989e71d..b52c4cf9 100644 --- a/app/Jobs/ProcessFileJob.php +++ b/app/Jobs/ProcessFileJob.php @@ -52,10 +52,10 @@ public function handle(): void ->name('OptOutRequests') ->finally(function (Batch $batch) { /** - * @TODO - * make a job that does that and also - * closes up the batch on the run watcher - */ + * @TODO + * make a job that does that and also + * closes up the batch on the run watcher + */ CollectionStatusEvent::dispatch( $this->document->collection, CollectionStatusEnum::PROCESSED); diff --git a/routes/web.php b/routes/web.php index 30038f21..173fb6db 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,7 +3,6 @@ use App\Http\Controllers\CollectionController; use App\Http\Controllers\ExampleChatBotController; use App\Http\Controllers\ExampleController; -use App\Models\Collection; use Illuminate\Foundation\Application; use Illuminate\Support\Facades\Route; use Inertia\Inertia; @@ -23,7 +22,7 @@ 'verified', ])->group(function () { Route::get('/dashboard', function () { - return to_route("collections.index"); + return to_route('collections.index'); //return Inertia::render('Dashboard'); })->name('dashboard'); diff --git a/tests/Feature/Http/Controllers/CollectionControllerTest.php b/tests/Feature/Http/Controllers/CollectionControllerTest.php index 64f5330d..6682629e 100644 --- a/tests/Feature/Http/Controllers/CollectionControllerTest.php +++ b/tests/Feature/Http/Controllers/CollectionControllerTest.php @@ -3,12 +3,9 @@ namespace Tests\Feature\Http\Controllers; use App\Models\Collection; -use App\Models\Team; use App\Models\User; -use Illuminate\Foundation\Testing\RefreshDatabase; -use Illuminate\Foundation\Testing\WithFaker; -use Tests\TestCase; use Inertia\Testing\AssertableInertia as Assert; +use Tests\TestCase; class CollectionControllerTest extends TestCase { @@ -25,7 +22,7 @@ public function test_example(): void Collection::factory()->create(); - $response = $this->get(route("collections.index")) + $response = $this->get(route('collections.index')) ->assertStatus(200) ->assertInertia(fn (Assert $page) => $page ->component('Collection/Index') @@ -39,12 +36,11 @@ public function test_store(): void $this->actingAs($user); $this->assertDatabaseCount('collections', 0); - $response = $this->post(route("collections.store"), [ - 'name' => "Test", + $response = $this->post(route('collections.store'), [ + 'name' => 'Test', 'description' => 'Test Description', ])->assertStatus(302); $this->assertDatabaseCount('collections', 1); - } } diff --git a/tests/Feature/UpdateTeamMemberRoleTest.php b/tests/Feature/UpdateTeamMemberRoleTest.php index 4a7c4746..37b83ec6 100644 --- a/tests/Feature/UpdateTeamMemberRoleTest.php +++ b/tests/Feature/UpdateTeamMemberRoleTest.php @@ -19,11 +19,11 @@ public function test_team_member_roles_can_be_updated(): void ); $response = $this->put('/teams/'.$user->currentTeam->id.'/members/'.$otherUser->id, [ - 'role' => 'editor', + 'role' => 'member', ]); $this->assertTrue($otherUser->fresh()->hasTeamRole( - $user->currentTeam->fresh(), 'editor' + $user->currentTeam->fresh(), 'member' )); } @@ -38,7 +38,7 @@ public function test_only_team_owner_can_update_team_member_roles(): void $this->actingAs($otherUser); $response = $this->put('/teams/'.$user->currentTeam->id.'/members/'.$otherUser->id, [ - 'role' => 'editor', + 'role' => 'member', ]); $this->assertTrue($otherUser->fresh()->hasTeamRole( diff --git a/tests/TestCase.php b/tests/TestCase.php index ef9df369..8cc99aa3 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -11,8 +11,8 @@ abstract class TestCase extends BaseTestCase { use LazilyRefreshDatabase; - - public function createUserWithCurrentTeam() { + public function createUserWithCurrentTeam() + { $user = User::factory()->withPersonalTeam()->create(); $user->current_team_id = Team::first()->id; $user->save();