mirror of
https://github.com/Bubka/2FAuth.git
synced 2025-06-25 06:24:07 +02:00
Update tests
This commit is contained in:
parent
f4ebbf401d
commit
de3603fcfa
@ -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]
|
#[Test]
|
||||||
public function test_store_invalid_data_returns_validation_error()
|
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]
|
#[Test]
|
||||||
public function test_update_returns_updated_group_resource()
|
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
|
* 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]
|
#[Test]
|
||||||
public function test_destroy_group_resets_user_preferences()
|
public function test_destroy_group_resets_user_preferences()
|
||||||
{
|
{
|
||||||
|
@ -88,10 +88,11 @@ class GroupControllerTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_show_returns_api_resource()
|
public function test_show_returns_api_resource()
|
||||||
{
|
{
|
||||||
|
$request = Mockery::mock(GroupStoreRequest::class);
|
||||||
$controller = Mockery::mock(GroupController::class)->makePartial();
|
$controller = Mockery::mock(GroupController::class)->makePartial();
|
||||||
$group = Group::factory()->make();
|
$group = Group::factory()->make();
|
||||||
|
|
||||||
$response = $controller->show($group);
|
$response = $controller->show($request, $group);
|
||||||
|
|
||||||
$this->assertInstanceOf(GroupResource::class, $response);
|
$this->assertInstanceOf(GroupResource::class, $response);
|
||||||
}
|
}
|
||||||
@ -138,10 +139,11 @@ class GroupControllerTest extends TestCase
|
|||||||
#[Test]
|
#[Test]
|
||||||
public function test_accounts_returns_api_resources()
|
public function test_accounts_returns_api_resources()
|
||||||
{
|
{
|
||||||
|
$request = Mockery::mock(GroupStoreRequest::class);
|
||||||
$controller = Mockery::mock(GroupController::class)->makePartial();
|
$controller = Mockery::mock(GroupController::class)->makePartial();
|
||||||
$group = Group::factory()->make();
|
$group = Group::factory()->make();
|
||||||
|
|
||||||
$response = $controller->accounts($group);
|
$response = $controller->accounts($request, $group);
|
||||||
|
|
||||||
$this->assertContainsOnlyInstancesOf(TwoFAccountReadResource::class, $response->collection);
|
$this->assertContainsOnlyInstancesOf(TwoFAccountReadResource::class, $response->collection);
|
||||||
}
|
}
|
||||||
|
@ -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);
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,7 +3,6 @@
|
|||||||
namespace Tests\Unit;
|
namespace Tests\Unit;
|
||||||
|
|
||||||
use App\Events\GroupDeleted;
|
use App\Events\GroupDeleted;
|
||||||
use App\Events\GroupDeleting;
|
|
||||||
use App\Models\Group;
|
use App\Models\Group;
|
||||||
use App\Models\TwoFAccount;
|
use App\Models\TwoFAccount;
|
||||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
@ -32,7 +31,6 @@ class GroupModelTest extends ModelTestCase
|
|||||||
'user_id' => 'integer',
|
'user_id' => 'integer',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'deleting' => GroupDeleting::class,
|
|
||||||
'deleted' => GroupDeleted::class,
|
'deleted' => GroupDeleted::class,
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Tests\Unit\Listeners;
|
namespace Tests\Unit\Listeners;
|
||||||
|
|
||||||
use App\Events\GroupDeleting;
|
use App\Events\GroupDeleted;
|
||||||
use App\Listeners\DissociateTwofaccountFromGroup;
|
use App\Listeners\DissociateTwofaccountFromGroup;
|
||||||
use Illuminate\Support\Facades\Event;
|
use Illuminate\Support\Facades\Event;
|
||||||
use PHPUnit\Framework\Attributes\CoversClass;
|
use PHPUnit\Framework\Attributes\CoversClass;
|
||||||
@ -16,12 +16,12 @@ use Tests\TestCase;
|
|||||||
class DissociateTwofaccountFromGroupTest extends TestCase
|
class DissociateTwofaccountFromGroupTest extends TestCase
|
||||||
{
|
{
|
||||||
#[Test]
|
#[Test]
|
||||||
public function test_DissociateTwofaccountFromGroup_listen_to_groupDeleting_event()
|
public function test_DissociateTwofaccountFromGroup_listen_to_groupDeleted_event()
|
||||||
{
|
{
|
||||||
Event::fake();
|
Event::fake();
|
||||||
|
|
||||||
Event::assertListening(
|
Event::assertListening(
|
||||||
GroupDeleting::class,
|
GroupDeleted::class,
|
||||||
DissociateTwofaccountFromGroup::class
|
DissociateTwofaccountFromGroup::class
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user