2023-08-25 00:23:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Tests\Feature\Group;
|
|
|
|
|
|
|
|
use App\Group;
|
2023-12-30 02:02:07 +01:00
|
|
|
use App\Group\Enums\Level;
|
2023-08-25 00:23:38 +02:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Tests\TestCase;
|
|
|
|
|
|
|
|
class IndexTest extends TestCase
|
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
|
|
|
|
2023-12-30 22:21:08 +01:00
|
|
|
public function testItDisplaysGroupPage(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
|
|
|
|
$this->get('/group')
|
|
|
|
->assertOk()
|
|
|
|
->assertInertiaPath('data.meta.links.root_path', route('api.group'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItDisplaysParentGroup(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
|
|
|
|
$group = Group::factory()->create(['name' => 'Afff', 'inner_name' => 'Gruppe', 'level' => Level::REGION]);
|
|
|
|
|
|
|
|
$this->get('/api/group')
|
|
|
|
->assertJsonCount(2, 'data')
|
|
|
|
->assertJsonPath('data.1.name', 'Afff')
|
|
|
|
->assertJsonPath('data.1.inner_name', 'Gruppe')
|
|
|
|
->assertJsonPath('data.1.id', $group->id)
|
|
|
|
->assertJsonPath('data.1.level', 'Bezirk')
|
|
|
|
->assertJsonPath('data.1.parent_id', null)
|
|
|
|
->assertJsonPath('meta.links.bulkstore', route('group.bulkstore'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testItDisplaysGroupsForParent(): void
|
2023-08-25 00:23:38 +02:00
|
|
|
{
|
2023-12-30 02:02:07 +01:00
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
2023-08-25 00:23:38 +02:00
|
|
|
|
2023-12-30 02:02:07 +01:00
|
|
|
$group = Group::factory()->for(Group::first(), 'parent')->create(['name' => 'Afff', 'inner_name' => 'Gruppe', 'level' => Level::REGION]);
|
2023-12-30 22:21:08 +01:00
|
|
|
Group::factory()->for(Group::first(), 'parent')->create(['name' => 'Afff', 'inner_name' => 'Gruppe', 'level' => Level::REGION]);
|
2023-08-25 00:23:38 +02:00
|
|
|
|
2023-12-30 22:21:08 +01:00
|
|
|
$this->get('/api/group/' . Group::first()->id)
|
|
|
|
->assertJsonCount(2, 'data')
|
|
|
|
->assertJsonPath('data.0.name', 'Afff')
|
|
|
|
->assertJsonPath('data.0.inner_name', 'Gruppe')
|
|
|
|
->assertJsonPath('data.0.id', $group->id)
|
|
|
|
->assertJsonPath('data.0.level', 'Bezirk')
|
|
|
|
->assertJsonPath('data.0.parent_id', Group::first()->id)
|
|
|
|
->assertJsonPath('data.0.links.children', route('api.group', ['group' => $group->id]))
|
|
|
|
->assertJsonPath('meta.links.bulkstore', route('group.bulkstore'));
|
2023-12-30 02:02:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLevelCanBeNull(): void
|
|
|
|
{
|
|
|
|
$this->login()->loginNami()->withoutExceptionHandling();
|
|
|
|
|
2023-12-30 22:21:08 +01:00
|
|
|
$group = Group::factory()->for(Group::first(), 'parent')->create(['level' => null]);
|
2023-08-25 00:23:38 +02:00
|
|
|
|
2023-12-30 22:21:08 +01:00
|
|
|
$this->get('/api/group/' . Group::first()->id)->assertJsonPath('data.0.id', $group->id);
|
2023-08-25 00:23:38 +02:00
|
|
|
}
|
|
|
|
}
|