refactor: extract remaining Telegram handlers to platform-neutral contracts
PR Checks / test-and-build (pull_request) Successful in 13m48s
PR Checks / test-and-build (pull_request) Successful in 13m48s
- Extract CreateSessionHandler, ListSessionsHandler, DeleteSessionHandler, ExportCalendarHandler, HandleRescheduleTimeInputHandler, HandleRescheduleVoteHandler to GmRelay.Shared - Add IPlatformMessenger methods: SendScheduleAsync, UpdateScheduleAsync, SendGroupMessageAsync with actions, CreateThreadAsync, DeleteThreadAsync - Rewrite Telegram Bot wrappers as thin adapters delegating to shared handlers - Rewrite DiscordRescheduleVoteHandler to use shared HandleRescheduleVoteHandler - Update UpdateRouter with explicit type aliases for ambiguous handler names - Add contract and source-inspection tests for extracted handlers - Bump version 3.1.1 → 3.2.0 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
using GmRelay.Bot.Features.Sessions.CreateSession;
|
||||
using GmRelay.Bot.Features.Sessions.RescheduleSession;
|
||||
using BotRescheduleHandler = GmRelay.Bot.Features.Sessions.RescheduleSession.HandleRescheduleTimeInputHandler;
|
||||
using GmRelay.DiscordBot.Rendering;
|
||||
using GmRelay.Shared.Domain;
|
||||
using GmRelay.Shared.Features.Sessions.RescheduleSession;
|
||||
@@ -69,14 +69,14 @@ public sealed class DiscordLandingPromisesSmokeTests
|
||||
};
|
||||
var deadline = new DateTimeOffset(2026, 5, 20, 18, 0, 0, TimeSpan.Zero);
|
||||
var voteParticipants = scenario.ActiveVoteParticipants(firstSessionId);
|
||||
var voteMessage = HandleRescheduleTimeInputHandler.BuildVotingMessage(
|
||||
var voteMessage = BotRescheduleHandler.BuildVotingMessage(
|
||||
scenario.Title,
|
||||
scenario.Sessions[0].ScheduledAt,
|
||||
deadline,
|
||||
options,
|
||||
voteParticipants,
|
||||
[]);
|
||||
var voteKeyboard = HandleRescheduleTimeInputHandler.BuildVotingKeyboard(options);
|
||||
var voteKeyboard = BotRescheduleHandler.BuildVotingKeyboard(options);
|
||||
|
||||
Assert.Contains("Landing Promise Smoke", voteMessage);
|
||||
Assert.Contains("0/2", voteMessage);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using GmRelay.Bot.Features.Sessions.CreateSession;
|
||||
using GmRelay.Bot.Features.Sessions.RescheduleSession;
|
||||
using BotRescheduleHandler = GmRelay.Bot.Features.Sessions.RescheduleSession.HandleRescheduleTimeInputHandler;
|
||||
using GmRelay.Shared.Domain;
|
||||
using GmRelay.Shared.Features.Sessions.RescheduleSession;
|
||||
using GmRelay.Shared.Rendering;
|
||||
@@ -65,14 +65,14 @@ public sealed class TelegramLandingPromisesSmokeTests
|
||||
};
|
||||
var deadline = new DateTimeOffset(2026, 5, 20, 18, 0, 0, TimeSpan.Zero);
|
||||
var voteParticipants = scenario.ActiveVoteParticipants(firstSessionId);
|
||||
var voteMessage = HandleRescheduleTimeInputHandler.BuildVotingMessage(
|
||||
var voteMessage = BotRescheduleHandler.BuildVotingMessage(
|
||||
scenario.Title,
|
||||
scenario.Sessions[0].ScheduledAt,
|
||||
deadline,
|
||||
options,
|
||||
voteParticipants,
|
||||
[]);
|
||||
var voteKeyboard = HandleRescheduleTimeInputHandler.BuildVotingKeyboard(options);
|
||||
var voteKeyboard = BotRescheduleHandler.BuildVotingKeyboard(options);
|
||||
|
||||
Assert.Contains("Landing Promise Smoke", voteMessage);
|
||||
Assert.Contains("0/2", voteMessage);
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
using GmRelay.Shared.Features.Sessions.CreateSession;
|
||||
using GmRelay.Shared.Platform;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession;
|
||||
|
||||
public sealed class CreateSessionCommandContractTests
|
||||
{
|
||||
[Fact]
|
||||
public void CreateSessionCommand_ShouldExposePlatformNeutralContext()
|
||||
{
|
||||
AssertProperty<CreateSessionCommand>("User", typeof(PlatformUser));
|
||||
AssertProperty<CreateSessionCommand>("Group", typeof(PlatformGroup));
|
||||
AssertProperty<CreateSessionCommand>("Title", typeof(string));
|
||||
AssertProperty<CreateSessionCommand>("Link", typeof(string));
|
||||
AssertProperty<CreateSessionCommand>("ScheduledTimes", typeof(IReadOnlyList<DateTimeOffset>));
|
||||
AssertProperty<CreateSessionCommand>("MaxPlayers", typeof(int?));
|
||||
AssertProperty<CreateSessionCommand>("ImageReference", typeof(string));
|
||||
AssertNoTelegramSpecificProperties<CreateSessionCommand>();
|
||||
}
|
||||
|
||||
private static void AssertProperty<T>(string name, Type expectedType)
|
||||
{
|
||||
var property = Assert.Single(typeof(T).GetProperties(), p => p.Name == name);
|
||||
Assert.Equal(expectedType, property.PropertyType);
|
||||
}
|
||||
|
||||
private static void AssertNoTelegramSpecificProperties<T>()
|
||||
{
|
||||
var names = typeof(T).GetProperties().Select(p => p.Name).ToArray();
|
||||
Assert.DoesNotContain(names, name => name.Contains("Telegram", StringComparison.Ordinal));
|
||||
Assert.DoesNotContain("ChatId", names);
|
||||
Assert.DoesNotContain("MessageId", names);
|
||||
Assert.DoesNotContain("TelegramUserId", names);
|
||||
Assert.DoesNotContain("TelegramUsername", names);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession;
|
||||
|
||||
public sealed class CreateSessionHandlerTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task SharedHandler_ShouldExist_AndBePlatformNeutral()
|
||||
{
|
||||
var handler = await ReadRepositoryFileAsync("src/GmRelay.Shared/Features/Sessions/CreateSession/CreateSessionHandler.cs");
|
||||
|
||||
Assert.Contains("CreateSessionCommand", handler, StringComparison.Ordinal);
|
||||
Assert.Contains("CreateSessionResult", handler, StringComparison.Ordinal);
|
||||
Assert.Contains("command.User", handler, StringComparison.Ordinal);
|
||||
Assert.Contains("command.Group", handler, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("ITelegramBotClient", handler, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("Telegram.Bot", handler, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("InlineKeyboardMarkup", handler, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("MessageThreadId", handler, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
private static async Task<string> ReadRepositoryFileAsync(string relativePath)
|
||||
{
|
||||
var directory = new DirectoryInfo(AppContext.BaseDirectory);
|
||||
while (directory is not null)
|
||||
{
|
||||
var candidate = Path.Combine(directory.FullName, relativePath);
|
||||
if (File.Exists(candidate))
|
||||
{
|
||||
return await File.ReadAllTextAsync(candidate);
|
||||
}
|
||||
|
||||
directory = directory.Parent;
|
||||
}
|
||||
|
||||
throw new FileNotFoundException($"Could not locate repository file '{relativePath}'.");
|
||||
}
|
||||
}
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
using GmRelay.Shared.Features.Sessions.ExportCalendar;
|
||||
using GmRelay.Shared.Platform;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.ExportCalendar;
|
||||
|
||||
public sealed class ExportCalendarCommandContractTests
|
||||
{
|
||||
[Fact]
|
||||
public void ExportCalendarCommand_ShouldExposePlatformNeutralContext()
|
||||
{
|
||||
AssertProperty<ExportCalendarCommand>("Group", typeof(PlatformGroup));
|
||||
AssertProperty<ExportCalendarCommand>("User", typeof(PlatformUser));
|
||||
AssertNoTelegramSpecificProperties<ExportCalendarCommand>();
|
||||
}
|
||||
|
||||
private static void AssertProperty<T>(string name, Type expectedType)
|
||||
{
|
||||
var property = Assert.Single(typeof(T).GetProperties(), p => p.Name == name);
|
||||
Assert.Equal(expectedType, property.PropertyType);
|
||||
}
|
||||
|
||||
private static void AssertNoTelegramSpecificProperties<T>()
|
||||
{
|
||||
var names = typeof(T).GetProperties().Select(p => p.Name).ToArray();
|
||||
Assert.DoesNotContain(names, name => name.Contains("Telegram", StringComparison.Ordinal));
|
||||
Assert.DoesNotContain("ChatId", names);
|
||||
Assert.DoesNotContain("MessageId", names);
|
||||
Assert.DoesNotContain("TelegramUserId", names);
|
||||
Assert.DoesNotContain("TelegramUsername", names);
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
using GmRelay.Shared.Features.Sessions.ListSessions;
|
||||
using GmRelay.Shared.Platform;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.ListSessions;
|
||||
|
||||
public sealed class ListSessionsCommandContractTests
|
||||
{
|
||||
[Fact]
|
||||
public void ListSessionsCommand_ShouldExposePlatformNeutralContext()
|
||||
{
|
||||
AssertProperty<ListSessionsCommand>("Group", typeof(PlatformGroup));
|
||||
AssertProperty<ListSessionsCommand>("User", typeof(PlatformUser));
|
||||
AssertNoTelegramSpecificProperties<ListSessionsCommand>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DeleteSessionCommand_ShouldExposePlatformNeutralContext()
|
||||
{
|
||||
AssertProperty<DeleteSessionCommand>("SessionId", typeof(Guid));
|
||||
AssertProperty<DeleteSessionCommand>("User", typeof(PlatformUser));
|
||||
AssertProperty<DeleteSessionCommand>("Group", typeof(PlatformGroup));
|
||||
AssertProperty<DeleteSessionCommand>("ScheduleMessage", typeof(PlatformMessageRef));
|
||||
AssertNoTelegramSpecificProperties<DeleteSessionCommand>();
|
||||
}
|
||||
|
||||
private static void AssertProperty<T>(string name, Type expectedType)
|
||||
{
|
||||
var property = Assert.Single(typeof(T).GetProperties(), p => p.Name == name);
|
||||
Assert.Equal(expectedType, property.PropertyType);
|
||||
}
|
||||
|
||||
private static void AssertNoTelegramSpecificProperties<T>()
|
||||
{
|
||||
var names = typeof(T).GetProperties().Select(p => p.Name).ToArray();
|
||||
Assert.DoesNotContain(names, name => name.Contains("Telegram", StringComparison.Ordinal));
|
||||
Assert.DoesNotContain("ChatId", names);
|
||||
Assert.DoesNotContain("MessageId", names);
|
||||
Assert.DoesNotContain("TelegramUserId", names);
|
||||
Assert.DoesNotContain("TelegramUsername", names);
|
||||
}
|
||||
}
|
||||
+11
-13
@@ -1,5 +1,6 @@
|
||||
using GmRelay.Bot.Features.Sessions.ListSessions;
|
||||
using GmRelay.Shared.Domain;
|
||||
using GmRelay.Shared.Features.Sessions.ListSessions;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.ListSessions;
|
||||
|
||||
@@ -22,17 +23,15 @@ public sealed class SessionListMessageRendererTests
|
||||
true)
|
||||
};
|
||||
|
||||
var result = SessionListMessageRenderer.Render(sessions);
|
||||
Assert.NotNull(result.Markup);
|
||||
var buttons = result.Markup.InlineKeyboard.SelectMany(row => row).ToList();
|
||||
var text = SessionListMessageRenderer.RenderText(sessions);
|
||||
var actions = SessionListMessageRenderer.RenderActions(sessions);
|
||||
|
||||
Assert.Contains("Ravenloft", result.Text);
|
||||
Assert.Collection(
|
||||
buttons.Select(button => button.CallbackData),
|
||||
callbackData => Assert.Equal($"cancel_session:{sessionId}", callbackData),
|
||||
callbackData => Assert.Equal($"reschedule_session:{sessionId}", callbackData),
|
||||
callbackData => Assert.Equal($"promote_waitlist:{sessionId}", callbackData),
|
||||
callbackData => Assert.Equal($"delete_session:{sessionId}", callbackData));
|
||||
Assert.Contains("Ravenloft", text);
|
||||
Assert.Equal(4, actions.Count);
|
||||
Assert.Contains(actions, a => a.Payload == $"cancel_session:{sessionId}");
|
||||
Assert.Contains(actions, a => a.Payload == $"reschedule_session:{sessionId}");
|
||||
Assert.Contains(actions, a => a.Payload == $"promote_waitlist:{sessionId}");
|
||||
Assert.Contains(actions, a => a.Payload == $"delete_session:{sessionId}");
|
||||
}
|
||||
|
||||
[Fact]
|
||||
@@ -51,8 +50,7 @@ public sealed class SessionListMessageRendererTests
|
||||
false)
|
||||
};
|
||||
|
||||
var result = SessionListMessageRenderer.Render(sessions);
|
||||
|
||||
Assert.Null(result.Markup);
|
||||
var actions = SessionListMessageRenderer.RenderActions(sessions);
|
||||
Assert.Empty(actions);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
using GmRelay.Bot.Features.Sessions.RescheduleSession;
|
||||
using BotHandler = GmRelay.Bot.Features.Sessions.RescheduleSession.HandleRescheduleTimeInputHandler;
|
||||
using GmRelay.Shared.Features.Sessions.RescheduleSession;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.RescheduleSession;
|
||||
@@ -72,7 +72,7 @@ public sealed class HandleRescheduleTimeInputHandlerTests
|
||||
new(secondOptionId, bobId, "Bob", null)
|
||||
};
|
||||
|
||||
var text = HandleRescheduleTimeInputHandler.BuildVotingMessage(
|
||||
var text = BotHandler.BuildVotingMessage(
|
||||
"Shadowrun",
|
||||
currentTime,
|
||||
deadline,
|
||||
@@ -101,7 +101,7 @@ public sealed class HandleRescheduleTimeInputHandlerTests
|
||||
new(secondOptionId, 2, new DateTimeOffset(2026, 4, 27, 17, 0, 0, TimeSpan.Zero))
|
||||
};
|
||||
|
||||
var keyboard = HandleRescheduleTimeInputHandler.BuildVotingKeyboard(options);
|
||||
var keyboard = BotHandler.BuildVotingKeyboard(options);
|
||||
var buttons = keyboard.InlineKeyboard.SelectMany(row => row).ToList();
|
||||
|
||||
Assert.Collection(
|
||||
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
using GmRelay.Shared.Features.Sessions.RescheduleSession;
|
||||
using GmRelay.Shared.Platform;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.RescheduleSession;
|
||||
|
||||
public sealed class RescheduleCommandContractTests
|
||||
{
|
||||
[Fact]
|
||||
public void HandleRescheduleTimeInputCommand_ShouldExposePlatformNeutralContext()
|
||||
{
|
||||
AssertProperty<HandleRescheduleTimeInputCommand>("User", typeof(PlatformUser));
|
||||
AssertProperty<HandleRescheduleTimeInputCommand>("Group", typeof(PlatformGroup));
|
||||
AssertProperty<HandleRescheduleTimeInputCommand>("Text", typeof(string));
|
||||
AssertNoTelegramSpecificProperties<HandleRescheduleTimeInputCommand>();
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void HandleRescheduleVoteCommand_ShouldExposePlatformNeutralContext()
|
||||
{
|
||||
AssertProperty<HandleRescheduleVoteCommand>("OptionId", typeof(Guid));
|
||||
AssertProperty<HandleRescheduleVoteCommand>("User", typeof(PlatformUser));
|
||||
AssertProperty<HandleRescheduleVoteCommand>("Group", typeof(PlatformGroup));
|
||||
AssertProperty<HandleRescheduleVoteCommand>("InteractionId", typeof(string));
|
||||
AssertProperty<HandleRescheduleVoteCommand>("ScheduleMessage", typeof(PlatformMessageRef));
|
||||
AssertNoTelegramSpecificProperties<HandleRescheduleVoteCommand>();
|
||||
}
|
||||
|
||||
private static void AssertProperty<T>(string name, Type expectedType)
|
||||
{
|
||||
var property = Assert.Single(typeof(T).GetProperties(), p => p.Name == name);
|
||||
Assert.Equal(expectedType, property.PropertyType);
|
||||
}
|
||||
|
||||
private static void AssertNoTelegramSpecificProperties<T>()
|
||||
{
|
||||
var names = typeof(T).GetProperties().Select(p => p.Name).ToArray();
|
||||
Assert.DoesNotContain(names, name => name.Contains("Telegram", StringComparison.Ordinal));
|
||||
Assert.DoesNotContain("ChatId", names);
|
||||
Assert.DoesNotContain("MessageId", names);
|
||||
Assert.DoesNotContain("TelegramUserId", names);
|
||||
Assert.DoesNotContain("TelegramUsername", names);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user