админка

This commit is contained in:
2026-03-13 23:33:35 +04:00
parent bae063a4fa
commit eaedeeb52b
41 changed files with 2506 additions and 67 deletions
+41 -1
View File
@@ -3,7 +3,10 @@
namespace Tests\Feature;
use App\Exceptions\DuplicateGameAccountException;
use App\Exceptions\InviteCodeException;
use App\Services\AzerothCoreAccountRegistrar;
use App\Services\InviteCodeService;
use Closure;
use Mockery\MockInterface;
use Tests\TestCase;
@@ -11,6 +14,13 @@ class GameAccountRegistrationTest extends TestCase
{
public function test_registration_form_submits_successfully(): void
{
$this->mock(InviteCodeService::class, function (MockInterface $mock): void {
$mock->shouldReceive('redeemForRegistration')
->once()
->with('INVITE-1234', 'playerone', \Mockery::type(Closure::class))
->andReturnUsing(fn (string $code, string $username, Closure $callback): array => $callback());
});
$this->mock(AzerothCoreAccountRegistrar::class, function (MockInterface $mock): void {
$mock->shouldReceive('register')
->once()
@@ -21,6 +31,7 @@ class GameAccountRegistrationTest extends TestCase
$response = $this->from(route('landing.index'))->post(route('game-account.store'), [
'username' => 'playerone',
'email' => 'player@example.com',
'invite_code' => 'INVITE-1234',
'password' => 'Pass1234',
'password_confirmation' => 'Pass1234',
'terms' => '1',
@@ -35,17 +46,24 @@ class GameAccountRegistrationTest extends TestCase
$response = $this->from(route('landing.index'))->post(route('game-account.store'), [
'username' => 'игрок!',
'email' => 'not-an-email',
'invite_code' => '',
'password' => '123',
'password_confirmation' => '456',
'terms' => '',
]);
$response->assertRedirect(route('landing.index'));
$response->assertSessionHasErrors(['username', 'email', 'password', 'terms']);
$response->assertSessionHasErrors(['username', 'email', 'invite_code', 'password', 'terms']);
}
public function test_duplicate_username_is_reported_back_to_the_form(): void
{
$this->mock(InviteCodeService::class, function (MockInterface $mock): void {
$mock->shouldReceive('redeemForRegistration')
->once()
->andReturnUsing(fn (string $code, string $username, Closure $callback): array => $callback());
});
$this->mock(AzerothCoreAccountRegistrar::class, function (MockInterface $mock): void {
$mock->shouldReceive('register')
->once()
@@ -55,6 +73,7 @@ class GameAccountRegistrationTest extends TestCase
$response = $this->from(route('landing.index'))->post(route('game-account.store'), [
'username' => 'playerone',
'email' => 'player@example.com',
'invite_code' => 'INVITE-1234',
'password' => 'Pass1234',
'password_confirmation' => 'Pass1234',
'terms' => '1',
@@ -63,4 +82,25 @@ class GameAccountRegistrationTest extends TestCase
$response->assertRedirect(route('landing.index'));
$response->assertSessionHasErrors(['username']);
}
public function test_invalid_invite_code_is_reported_back_to_the_form(): void
{
$this->mock(InviteCodeService::class, function (MockInterface $mock): void {
$mock->shouldReceive('redeemForRegistration')
->once()
->andThrow(InviteCodeException::invalid());
});
$response = $this->from(route('landing.index'))->post(route('game-account.store'), [
'username' => 'playerone',
'email' => 'player@example.com',
'invite_code' => 'WRONG-CODE',
'password' => 'Pass1234',
'password_confirmation' => 'Pass1234',
'terms' => '1',
]);
$response->assertRedirect(route('landing.index'));
$response->assertSessionHasErrors(['invite_code']);
}
}