create(['name' => 'Ideengremium']); $role->grants()->create(['ability' => 'ideas.manage']); $this->board = User::factory()->withRoles([$role])->create(); } public function test_submit_support_and_comment(): void { Notification::fake(); $author = User::factory()->create(); $fan = User::factory()->create(); $this->actingAs($author)->post('/ideen', ['title' => 'Überdachte Fahrradständer', 'body' => 'Damit die Räder nicht nass werden.'])->assertRedirect(); $idea = Idea::query()->firstOrFail(); $this->assertSame($author->id, $idea->author_id); $this->actingAs($author)->post("/ideen/{$idea->id}/unterstuetzen")->assertStatus(422); $this->actingAs($fan)->post("/ideen/{$idea->id}/unterstuetzen")->assertRedirect(); $this->actingAs($fan)->post("/ideen/{$idea->id}/unterstuetzen"); $this->assertSame(1, $idea->fresh()->supports_count); $this->actingAs($fan)->post("/ideen/{$idea->id}/kommentare", ['body' => 'Gute Idee!', 'official' => true])->assertRedirect(); $this->assertFalse($idea->comments()->first()->official); Notification::assertSentTo($author, PortalNotification::class); $this->actingAs($fan)->get("/ideen/{$idea->id}")->assertInertia(fn (Assert $page) => $page ->where('idea.supported', true)->where('idea.supports', 1)->where('idea.can_edit', false)->where('idea.can_manage', false) ->has('idea.comment_list', 1)); $this->actingAs($fan)->delete("/ideen/{$idea->id}/unterstuetzen"); $this->assertSame(0, $idea->fresh()->supports_count); } public function test_anonymous_ideas_keep_no_author(): void { $user = User::factory()->create(['first_name' => 'Anna', 'last_name' => 'Nym']); $this->actingAs($user)->post('/ideen', ['title' => 'Mehr Pausenräume', 'body' => 'Bitte.', 'anonymous' => true]); $idea = Idea::query()->firstOrFail(); $this->assertNull($idea->author_id); $this->actingAs($this->board)->get("/ideen/{$idea->id}")->assertInertia(fn (Assert $page) => $page->where('idea.author', null)->where('idea.anonymous', true)); $this->actingAs($this->board)->get('/ideen')->assertDontSee('Nym'); $this->actingAs($user)->put("/ideen/{$idea->id}", ['title' => 'Neu', 'body' => 'x'])->assertForbidden(); } public function test_board_sets_status_and_informs_author_and_supporters(): void { Notification::fake(); $author = User::factory()->create(); $fans = User::factory()->count(2)->create(); $idea = Idea::query()->create(['title' => 'Obstkorb', 'body' => 'Frisches Obst', 'author_id' => $author->id]); $idea->supporters()->attach($fans->pluck('id')); $this->actingAs($author)->put("/ideen/{$idea->id}/status", ['status' => 'done'])->assertForbidden(); $this->actingAs($this->board)->put("/ideen/{$idea->id}/status", ['status' => 'done', 'status_note' => 'Ab Montag in jeder Etage.'])->assertRedirect(); $this->assertSame('done', $idea->fresh()->status); Notification::assertSentTo([$author, ...$fans], PortalNotification::class, fn ($n) => str_contains($n->title, 'Umgesetzt')); // Nach der Bewertung kann die einreichende Person nicht mehr bearbeiten oder löschen $this->actingAs($author)->put("/ideen/{$idea->id}", ['title' => 'Neu', 'body' => 'x'])->assertForbidden(); $this->actingAs($author)->delete("/ideen/{$idea->id}")->assertForbidden(); $this->actingAs($this->board)->post("/ideen/{$idea->id}/kommentare", ['body' => 'Danke!', 'official' => true]); $this->assertTrue($idea->comments()->first()->official); } public function test_listing_filters_and_api(): void { $user = User::factory()->create(); $coffee = Idea::query()->create(['title' => 'Kaffeemaschine', 'body' => 'Neue bitte', 'status' => 'review']); Idea::query()->create(['title' => 'Parkplätze', 'body' => 'Mehr davon']); $this->actingAs($user)->get('/ideen?status=review')->assertInertia(fn (Assert $page) => $page->has('ideas', 1)->where('ideas.0.title', 'Kaffeemaschine')->where('counts.new', 1)); $this->actingAs($user)->get('/ideen?q=Park')->assertInertia(fn (Assert $page) => $page->has('ideas', 1)); $headers = ['Authorization' => 'Bearer '.$user->createToken('App')->plainTextToken]; $this->getJson('/api/v1/ideas', $headers)->assertOk()->assertJsonCount(2, 'data'); $id = $this->postJson('/api/v1/ideas', ['title' => 'Aus der App', 'body' => 'Test'], $headers)->assertCreated()->json('data.id'); $this->postJson("/api/v1/ideas/{$coffee->id}/support", [], $headers)->assertOk()->assertJsonPath('data.supports', 1); $this->postJson("/api/v1/ideas/{$id}/comments", ['body' => 'Hallo'], $headers)->assertCreated()->assertJsonPath('data.comments', 1); } }