feat: delete

This commit is contained in:
hashbro
2026-09-03 01:29:50 +08:00
parent 44bcfe544c
commit 4c49a61149
5 changed files with 196 additions and 45 deletions
+78
View File
@@ -0,0 +1,78 @@
<?php
namespace Tests\Feature;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use PHPUnit\Framework\Attributes\Test;
use Tests\TestCase;
class AgentLoginTest extends TestCase
{
use RefreshDatabase;
#[Test]
public function ajax_login_succeeds_and_sets_session(): void
{
User::query()->create([
'username' => 'okagent',
'password' => 'secret12',
'status' => 1,
]);
$this->post('/user/login', [
'username' => 'okagent',
'password' => 'secret12',
])->assertOk()
->assertJson([
'code' => 0,
'msg' => '登录成功',
'data' => route('user.home'),
]);
$this->assertAuthenticated('agent');
}
#[Test]
public function ajax_login_rejects_bad_password(): void
{
User::query()->create([
'username' => 'okagent',
'password' => 'secret12',
'status' => 1,
]);
$this->post('/user/login', [
'username' => 'okagent',
'password' => 'wrongpass',
])->assertOk()
->assertJson(['code' => 1, 'msg' => '用户名或密码错误']);
$this->assertGuest('agent');
}
#[Test]
public function login_is_rate_limited_after_failures(): void
{
User::query()->create([
'username' => 'okagent',
'password' => 'secret12',
'status' => 1,
]);
for ($i = 0; $i < 5; $i++) {
$this->post('/user/login', [
'username' => 'okagent',
'password' => 'bad-password',
])->assertOk()->assertJsonPath('code', 1);
}
$response = $this->post('/user/login', [
'username' => 'okagent',
'password' => 'secret12',
])->assertOk()
->assertJsonPath('code', 1);
$this->assertStringContainsString('登陆失败次数过多', (string) $response->json('msg'));
}
}