adrema/tests/Feature/Group/IndexTest.php

96 lines
3.6 KiB
PHP
Raw Permalink Normal View History

2023-08-25 00:23:38 +02:00
<?php
namespace Tests\Feature\Group;
2024-06-29 14:36:35 +02:00
use App\Fileshare\ConnectionTypes\OwncloudConnection;
use App\Fileshare\Models\Fileshare;
2023-08-25 00:23:38 +02:00
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'));
}
2024-04-11 20:03:25 +02:00
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);
}
2023-12-30 22:21:08 +01:00
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
}
2024-06-29 14:36:35 +02:00
public function testItDisplaysFileshare(): void
{
$this->login()->loginNami()->withoutExceptionHandling();
$connection = Fileshare::factory()
->type(OwncloudConnection::from(['user' => 'badenpowell', 'password' => 'secret', 'base_url' => env('TEST_OWNCLOUD_DOMAIN')]))
->name('lokaler Server')
->create();
Group::factory()->for(Group::first(), 'parent')->create(['level' => null, 'fileshare' => [
'connection_id' => $connection->id,
'resource' => '/abc',
]]);
$this->get('/api/group/' . Group::first()->id)->assertJsonPath('data.0.fileshare.resource', '/abc');
}
2023-08-25 00:23:38 +02:00
}