feat: bot
This commit is contained in:
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user