feat: bot

This commit is contained in:
hashbro
2026-08-15 23:05:51 +08:00
parent 9049fdccad
commit 376b442880
26 changed files with 944 additions and 352 deletions
+47
View File
@@ -356,4 +356,51 @@ class AdminAgentPortalTest extends TestCase
])
->assertStatus(405);
}
#[Test]
public function admin_can_send_agent_telegram_test(): void
{
config(['coruna.telegram.bot_token' => 'system-token']);
\Illuminate\Support\Facades\Http::fake([
'api.telegram.org/*' => \Illuminate\Support\Facades\Http::response(['ok' => true], 200),
]);
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
$agent = User::query()->create([
'username' => 'tgagent',
'password' => 'secret12',
'status' => 1,
'chat_id' => '-200',
]);
$this->actingAs($admin, 'admin')
->post(route('admin.agents.telegramTest'), [
'agent_id' => $agent->id,
'chat_id' => '-300',
])
->assertOk()
->assertJsonPath('code', 0);
\Illuminate\Support\Facades\Http::assertSent(function ($request) {
$text = (string) ($request->data()['text'] ?? '');
return str_contains($request->url(), '/botsystem-token/')
&& ($request->data()['chat_id'] ?? null) === '-300'
&& str_contains($text, 'Telegram 测试')
&& str_contains($text, 'tgagent');
});
}
#[Test]
public function agent_telegram_test_requires_chat_id(): void
{
config(['coruna.telegram.bot_token' => 'system-token']);
$admin = Admin::query()->create(['username' => 'admin', 'password' => 'admin123']);
$this->actingAs($admin, 'admin')
->post(route('admin.agents.telegramTest'), [])
->assertOk()
->assertJsonPath('code', 1)
->assertJsonPath('msg', '未填写 Chat ID');
}
}