create(); $this->actingAs($user); return $user; } public function test_patch_updates_scalar_and_relations(): void { $this->signIn(); $movie = Movie::factory()->create(['title' => 'Old', 'rating' => 'PG']); $payload = [ 'title' => 'New Title', 'rating' => 'R', 'genres' => ['Adventure', 'Action'], ]; $res = $this->patchJson("/admin/movies/{$movie->id}", $payload); $res->assertOk()->assertJsonPath('movie.title', 'New Title'); $this->assertDatabaseHas('movies', ['id' => $movie->id, 'title' => 'New Title', 'rating' => 'R']); $movie->refresh(); $this->assertSame(2, $movie->genres()->count()); } public function test_delete_removes_movie(): void { $this->signIn(); $movie = Movie::factory()->create(); // attach a relation to ensure cascade works $g = Genre::factory()->create(); $movie->genres()->sync([$g->id]); $this->deleteJson("/admin/movies/{$movie->id}") ->assertOk() ->assertJsonPath('deleted', true); $this->assertDatabaseMissing('movies', ['id' => $movie->id]); } }