Add prefer_inner for group api
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2024-04-11 20:03:25 +02:00
parent 2ba31a0678
commit bd6ccf030b
3 changed files with 12 additions and 3 deletions

View File

@ -6,8 +6,6 @@ use App\Group;
use App\Group\Resources\GroupResource;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Inertia\Inertia;
use Inertia\Response;
use Lorisleiva\Actions\Concerns\AsAction;
class GroupApiIndexAction

View File

@ -24,7 +24,7 @@ class GroupResource extends JsonResource
public function toArray($request)
{
return [
'name' => $this->name,
'name' => $request->has('prefer_inner') && $this->inner_name ? $this->inner_name : $this->name,
'inner_name' => $this->inner_name,
'parent_id' => $this->parent_id,
'id' => $this->id,

View File

@ -36,6 +36,17 @@ class IndexTest extends TestCase
->assertJsonPath('meta.links.bulkstore', route('group.bulkstore'));
}
public function testItPrefersInnerName(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$group = Group::factory()->create(['name' => 'Afff', 'inner_name' => 'Gruppe', 'level' => Level::REGION]);
$this->get('/api/group?prefer_inner')
->assertJsonPath('data.1.name', 'Gruppe')
->assertJsonPath('data.1.id', $group->id);
}
public function testItDisplaysGroupsForParent(): void
{
$this->login()->loginNami()->withoutExceptionHandling();