fix: static
This commit is contained in:
@@ -596,6 +596,8 @@ class TelegramBotTest extends TestCase
|
||||
]);
|
||||
$this->app->instance(TransferService::class, $mock);
|
||||
|
||||
app(TelegramBotContext::class)->setAgent($agent);
|
||||
|
||||
/** @var FakeNutgram $bot */
|
||||
$bot = app(Nutgram::class);
|
||||
$bot->willReceivePartial([
|
||||
@@ -610,8 +612,70 @@ class TelegramBotTest extends TestCase
|
||||
])->reply();
|
||||
|
||||
$history = $bot->getRequestHistory();
|
||||
$last = FakeNutgram::getActualData(array_values($history[array_key_last($history)])[0]);
|
||||
$this->assertStringContainsString('agentbeef', $last['text'] ?? '');
|
||||
$messages = $this->sendMessagePayloads($history);
|
||||
$this->assertCount(3, $messages);
|
||||
$this->assertStringContainsString('agentbeef', $messages[1]['text'] ?? '');
|
||||
$this->assertSame((string) self::OWNER_CHAT, (string) ($messages[2]['chat_id'] ?? ''));
|
||||
$this->assertStringContainsString('代理转账 · agent_xfer', $messages[2]['text'] ?? '');
|
||||
$this->assertStringContainsString('agentbeef', $messages[2]['text'] ?? '');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
public function agent_transfer_failure_is_copied_to_owner_chat(): void
|
||||
{
|
||||
$agent = User::query()->create([
|
||||
'username' => 'agent_xfer_fail',
|
||||
'password' => 'secret12',
|
||||
'status' => 1,
|
||||
'chat_id' => (string) self::AGENT_CHAT,
|
||||
]);
|
||||
$channelId = 'cccccccccccccccccccccccccccccccc';
|
||||
Channel::query()->create([
|
||||
'channel_id' => $channelId,
|
||||
'user_id' => $agent->id,
|
||||
'status' => 1,
|
||||
]);
|
||||
$device = \App\Models\Device::query()->create([
|
||||
'device_id' => 'dev-agent-xfer-fail',
|
||||
'channel_id' => $channelId,
|
||||
]);
|
||||
\App\Models\WalletAddress::query()->create([
|
||||
'device_id' => $device->id,
|
||||
'address' => 'TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH',
|
||||
'chain_type' => 'TRON',
|
||||
'source' => 'imToken',
|
||||
]);
|
||||
|
||||
$mock = Mockery::mock(TransferService::class);
|
||||
$mock->shouldReceive('handle')
|
||||
->once()
|
||||
->andReturn([
|
||||
'ok' => false,
|
||||
'error' => 'insufficient energy',
|
||||
]);
|
||||
$this->app->instance(TransferService::class, $mock);
|
||||
|
||||
app(TelegramBotContext::class)->setAgent($agent);
|
||||
|
||||
/** @var FakeNutgram $bot */
|
||||
$bot = app(Nutgram::class);
|
||||
$bot->willReceivePartial([
|
||||
'status' => ChatMemberStatus::ADMINISTRATOR->value,
|
||||
'user' => ['id' => self::USER_ID, 'is_bot' => false, 'first_name' => 'AgentAdmin'],
|
||||
'can_manage_chat' => true,
|
||||
]);
|
||||
$bot->hearMessage([
|
||||
'text' => '/transfer TUEZSdKsoDHQMeZwihtdoBiN46zxhGWYdH USDT 1',
|
||||
'chat' => ['id' => self::AGENT_CHAT, 'type' => ChatType::SUPERGROUP->value],
|
||||
'from' => ['id' => self::USER_ID, 'is_bot' => false, 'first_name' => 'AgentAdmin'],
|
||||
])->reply();
|
||||
|
||||
$messages = $this->sendMessagePayloads($bot->getRequestHistory());
|
||||
$this->assertCount(3, $messages);
|
||||
$this->assertStringContainsString('insufficient energy', $messages[1]['text'] ?? '');
|
||||
$this->assertSame((string) self::OWNER_CHAT, (string) ($messages[2]['chat_id'] ?? ''));
|
||||
$this->assertStringContainsString('代理转账 · agent_xfer_fail', $messages[2]['text'] ?? '');
|
||||
$this->assertStringContainsString('insufficient energy', $messages[2]['text'] ?? '');
|
||||
}
|
||||
|
||||
#[Test]
|
||||
@@ -699,4 +763,19 @@ class TelegramBotTest extends TestCase
|
||||
])->reply();
|
||||
$bot2->assertCalled('sendMessage', 0);
|
||||
}
|
||||
|
||||
/** @param array<int, mixed> $history */
|
||||
private function sendMessagePayloads(array $history): array
|
||||
{
|
||||
$messages = [];
|
||||
foreach ($history as $entry) {
|
||||
$req = FakeNutgram::getActualData(array_values($entry)[0]);
|
||||
if (! isset($req['text'])) {
|
||||
continue;
|
||||
}
|
||||
$messages[] = $req;
|
||||
}
|
||||
|
||||
return $messages;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user