feat(e2e): #147 group creation and bot invitation scenario
- Add GroupSetupScenario: create supergroup, invite GmRelay bot, send /start, wait for reply, then delete the group - Extend TelegramUserClient with DeleteGroupAsync and channel cache - Update Program.cs to run the scenario with cleanup in finally - Update README status table and runner documentation Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
namespace GmRelay.E2E.Runner;
|
||||
|
||||
/// <summary>
|
||||
/// Automates the first step of every Telegram E2E scenario:
|
||||
/// create a supergroup, invite the GmRelay bot, and verify the bot responds to /start.
|
||||
/// </summary>
|
||||
public sealed class GroupSetupScenario
|
||||
{
|
||||
private readonly TelegramUserClient _client;
|
||||
private readonly RunnerConfig _config;
|
||||
|
||||
public GroupSetupScenario(TelegramUserClient client, RunnerConfig config)
|
||||
{
|
||||
_client = client;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
public async Task<ScenarioResult> RunAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
var group = await _client.CreateGroupAsync(
|
||||
$"GmRelay E2E {DateTime.UtcNow:yyyyMMdd-HHmmss}",
|
||||
"Automated test group for GmRelay E2E suite.",
|
||||
cancellationToken);
|
||||
|
||||
Console.WriteLine($"[scenario] created group id={group.Id} title='{group.Title}'");
|
||||
|
||||
await _client.InviteBotToGroupAsync(group, _config.BotUsername, cancellationToken);
|
||||
Console.WriteLine($"[scenario] invited @{_config.BotUsername}");
|
||||
|
||||
await _client.SendCommandAsync(group, "start", cancellationToken);
|
||||
var reply = await _client.WaitForBotReplyAsync(
|
||||
group,
|
||||
containsText: null,
|
||||
timeout: TimeSpan.FromSeconds(30),
|
||||
cancellationToken);
|
||||
|
||||
if (reply is null)
|
||||
throw new InvalidOperationException("Bot did not reply to /start in the group.");
|
||||
|
||||
Console.WriteLine($"[scenario] bot replied to /start (msg id={reply.id})");
|
||||
|
||||
return new ScenarioResult(group, reply.id);
|
||||
}
|
||||
|
||||
public async Task CleanupAsync(ScenarioResult result, CancellationToken cancellationToken = default)
|
||||
{
|
||||
try
|
||||
{
|
||||
await _client.DeleteGroupAsync(result.Group, cancellationToken);
|
||||
Console.WriteLine($"[scenario] deleted group id={result.Group.Id}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"[scenario] warning: failed to delete group id={result.Group.Id}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public sealed record ScenarioResult(ChatGroup Group, int LastBotMessageId);
|
||||
Reference in New Issue
Block a user