Update tests

This commit is contained in:
Bubka 2025-02-19 16:24:40 +01:00
parent f4ebbf401d
commit de3603fcfa
5 changed files with 61 additions and 32 deletions

View File

@ -145,6 +145,26 @@ class GroupControllerTest extends FeatureTestCase
]);
}
#[Test]
public function test_store_with_existing_group_name_returns_validation_error()
{
$this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/groups', [
'name' => $this->userGroupA->name,
])
->assertStatus(422);
}
#[Test]
public function test_store_with_all_group_name_returns_validation_error()
{
$this->actingAs($this->user, 'api-guard')
->json('POST', '/api/v1/groups', [
'name' => __('commons.all'),
])
->assertStatus(422);
}
#[Test]
public function test_store_invalid_data_returns_validation_error()
{
@ -193,6 +213,20 @@ class GroupControllerTest extends FeatureTestCase
]);
}
#[Test]
public function test_show_missing_group_with_id_0_returns_the_virtual_all_group_resource()
{
$userTwofaccounts = $this->user->twofaccounts;
$response = $this->actingAs($this->user, 'api-guard')
->json('GET', '/api/v1/groups/0')
->assertOk()
->assertJsonFragment([
'name' => __('commons.all'),
'twofaccounts_count' => $userTwofaccounts->count(),
]);
}
#[Test]
public function test_update_returns_updated_group_resource()
{
@ -392,6 +426,15 @@ class GroupControllerTest extends FeatureTestCase
]);
}
#[Test]
public function test_accounts_of_the_all_group_returns_user_twofaccounts_collection()
{
$response = $this->actingAs($this->user, 'api-guard')
->json('GET', '/api/v1/groups/0/twofaccounts')
->assertOk()
->assertJsonCount(2);
}
/**
* test Group deletion via API
*/
@ -430,6 +473,17 @@ class GroupControllerTest extends FeatureTestCase
]);
}
#[Test]
public function test_destroy_the_all_group_is_forbidden()
{
$response = $this->actingAs($this->anotherUser, 'api-guard')
->json('DELETE', '/api/v1/groups/0')
->assertForbidden()
->assertJsonStructure([
'message',
]);
}
#[Test]
public function test_destroy_group_resets_user_preferences()
{

View File

@ -88,10 +88,11 @@ class GroupControllerTest extends TestCase
#[Test]
public function test_show_returns_api_resource()
{
$request = Mockery::mock(GroupStoreRequest::class);
$controller = Mockery::mock(GroupController::class)->makePartial();
$group = Group::factory()->make();
$response = $controller->show($group);
$response = $controller->show($request, $group);
$this->assertInstanceOf(GroupResource::class, $response);
}
@ -138,10 +139,11 @@ class GroupControllerTest extends TestCase
#[Test]
public function test_accounts_returns_api_resources()
{
$request = Mockery::mock(GroupStoreRequest::class);
$controller = Mockery::mock(GroupController::class)->makePartial();
$group = Group::factory()->make();
$response = $controller->accounts($group);
$response = $controller->accounts($request, $group);
$this->assertContainsOnlyInstancesOf(TwoFAccountReadResource::class, $response->collection);
}

View File

@ -1,25 +0,0 @@
<?php
namespace Tests\Unit\Events;
use App\Events\GroupDeleting;
use App\Models\Group;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
/**
* GroupDeletingTest test class
*/
#[CoversClass(GroupDeleting::class)]
class GroupDeletingTest extends TestCase
{
#[Test]
public function test_event_constructor()
{
$group = Group::factory()->make();
$event = new GroupDeleting($group);
$this->assertSame($group, $event->group);
}
}

View File

@ -3,7 +3,6 @@
namespace Tests\Unit;
use App\Events\GroupDeleted;
use App\Events\GroupDeleting;
use App\Models\Group;
use App\Models\TwoFAccount;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
@ -32,7 +31,6 @@ class GroupModelTest extends ModelTestCase
'user_id' => 'integer',
],
[
'deleting' => GroupDeleting::class,
'deleted' => GroupDeleted::class,
]
);

View File

@ -2,7 +2,7 @@
namespace Tests\Unit\Listeners;
use App\Events\GroupDeleting;
use App\Events\GroupDeleted;
use App\Listeners\DissociateTwofaccountFromGroup;
use Illuminate\Support\Facades\Event;
use PHPUnit\Framework\Attributes\CoversClass;
@ -16,12 +16,12 @@ use Tests\TestCase;
class DissociateTwofaccountFromGroupTest extends TestCase
{
#[Test]
public function test_DissociateTwofaccountFromGroup_listen_to_groupDeleting_event()
public function test_DissociateTwofaccountFromGroup_listen_to_groupDeleted_event()
{
Event::fake();
Event::assertListening(
GroupDeleting::class,
GroupDeleted::class,
DissociateTwofaccountFromGroup::class
);
}