refactor(wizard): move core to Shared, add IWizardMessenger contract (issue #112)
Moves the game-creation wizard state machine, view builder, and platform-neutral contracts (callback data, step names, storage exception, club option, step limits) from GmRelay.Bot to GmRelay.Shared. Telegram continues to work through a new TelegramWizardMessenger implementing IWizardMessenger and a WizardInteractionMapper that converts Update → WizardInteraction. Wires the new platform column on wizard_drafts (V032 migration) and switches chat/owner/thread/message ids to TEXT so the same table can hold Discord snowflakes later. - GameCreationWizard: now in Shared, takes IWizardMessenger + IWizardDraftRepository, dispatches on WizardInteraction. - New IWizardMessenger contract with Edit/Send/Answer/GetOwnerClubs (returns string ids so Telegram longs and Discord snowflakes both fit). - New WizardStepViewBuilder in Shared returns (text, IReadOnlyList<WizardAction>); TelegramWizardMessenger renders actions into InlineKeyboardMarkup via a new Bot-side ToInlineKeyboard helper. - New WizardInteractionMapper in Bot (5-case test) converts Telegram Update to WizardInteraction. - WizardDraft gains a Platform column; ChatId/MessageThreadId/OwnerId/ DraftMessageId switched to string. V032 migrates existing rows and rebuilds the owner lookup index on (platform, owner_id). - All existing wizard / create-session tests updated to the new contract (HandleInteractionAsync + WizardInteraction). Wizard callback-data format preserved. - dotnet build clean, dotnet format --verify-no-changes clean, all 101 wizard tests pass.
This commit is contained in:
+13
-14
@@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using GmRelay.Bot.Features.Sessions.CreateSession.Wizard;
|
||||
using GmRelay.Shared.Domain;
|
||||
using GmRelay.Shared.Features.Sessions.CreateSession.Wizard;
|
||||
using static GmRelay.Bot.Tests.Features.Sessions.CreateSession.Wizard.WizardTestFakes;
|
||||
@@ -7,8 +6,8 @@ using static GmRelay.Bot.Tests.Features.Sessions.CreateSession.Wizard.WizardTest
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession.Wizard;
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the pool-specific branch of the wizard: the AddSlots flow that
|
||||
/// builds up slot metadata through date and capacity steps.
|
||||
/// Verifies the pool-specific branch of the wizard: the AddSlots flow
|
||||
/// that builds up slot metadata through date and capacity steps.
|
||||
/// </summary>
|
||||
public sealed class GameCreationWizardPoolSlotTests
|
||||
{
|
||||
@@ -28,7 +27,7 @@ public sealed class GameCreationWizardPoolSlotTests
|
||||
drafts.Seed(draft);
|
||||
|
||||
var addData = WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "add");
|
||||
await wizard.HandleUpdateAsync(CallbackUpdate(addData), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(CallbackInteraction(addData, ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
|
||||
Assert.Equal(WizardStepNames.PoolSlotDateTime, draft.Step);
|
||||
}
|
||||
@@ -49,7 +48,7 @@ public sealed class GameCreationWizardPoolSlotTests
|
||||
|
||||
var future = DateTimeOffset.UtcNow.AddDays(7).ToMoscow();
|
||||
var dtString = future.ToString("dd.MM.yyyy HH:mm");
|
||||
await wizard.HandleUpdateAsync(TextUpdate(dtString), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(TextInteraction(dtString, ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
|
||||
Assert.Equal(WizardStepNames.PoolSlotCapacity, draft.Step);
|
||||
}
|
||||
@@ -61,7 +60,7 @@ public sealed class GameCreationWizardPoolSlotTests
|
||||
var draft = NewDraft(WizardStepNames.PoolSlotDateTime);
|
||||
drafts.Seed(draft);
|
||||
|
||||
await wizard.HandleUpdateAsync(TextUpdate("01.01.2020 12:00"), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(TextInteraction("01.01.2020 12:00", ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
|
||||
Assert.Equal(WizardStepNames.PoolSlotDateTime, draft.Step);
|
||||
}
|
||||
@@ -74,7 +73,7 @@ public sealed class GameCreationWizardPoolSlotTests
|
||||
drafts.Seed(draft);
|
||||
|
||||
var noWaitlist = WizardCallbackData.Choice(WizardStepNames.PoolSlotCapacity, "waitlist:off");
|
||||
await wizard.HandleUpdateAsync(CallbackUpdate(noWaitlist), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(CallbackInteraction(noWaitlist, ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
|
||||
Assert.Equal(WizardStepNames.PoolAddSlots, draft.Step);
|
||||
}
|
||||
@@ -87,7 +86,7 @@ public sealed class GameCreationWizardPoolSlotTests
|
||||
drafts.Seed(draft);
|
||||
|
||||
var yesWaitlist = WizardCallbackData.Choice(WizardStepNames.PoolSlotCapacity, "waitlist:on");
|
||||
await wizard.HandleUpdateAsync(CallbackUpdate(yesWaitlist), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(CallbackInteraction(yesWaitlist, ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
|
||||
Assert.Equal(WizardStepNames.PoolAddSlots, draft.Step);
|
||||
}
|
||||
@@ -107,7 +106,7 @@ public sealed class GameCreationWizardPoolSlotTests
|
||||
drafts.Seed(draft);
|
||||
|
||||
var data = WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "done");
|
||||
await wizard.HandleUpdateAsync(CallbackUpdate(data), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(CallbackInteraction(data, ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
|
||||
Assert.Equal(WizardStepNames.PoolAddSlots, draft.Step);
|
||||
}
|
||||
@@ -132,7 +131,7 @@ public sealed class GameCreationWizardPoolSlotTests
|
||||
drafts.Seed(draft);
|
||||
|
||||
var data = WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "done");
|
||||
await wizard.HandleUpdateAsync(CallbackUpdate(data), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(CallbackInteraction(data, ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
|
||||
Assert.Equal(WizardStepNames.PoolConfirm, draft.Step);
|
||||
}
|
||||
@@ -150,10 +149,10 @@ public sealed class GameCreationWizardPoolSlotTests
|
||||
drafts.Seed(draft);
|
||||
|
||||
// "add" then "done" — no date/capacity supplied in between.
|
||||
await wizard.HandleUpdateAsync(CallbackUpdate(
|
||||
WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "add")), draft, CancellationToken.None);
|
||||
await wizard.HandleUpdateAsync(CallbackUpdate(
|
||||
WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "done")), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(CallbackInteraction(
|
||||
WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "add"), ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
await wizard.HandleInteractionAsync(CallbackInteraction(
|
||||
WizardCallbackData.Choice(WizardStepNames.PoolAddSlots, "done"), ownerId: draft.OwnerId), draft, CancellationToken.None);
|
||||
|
||||
// The wizard sees the in-memory slot count > 0 and advances to confirm.
|
||||
Assert.Equal(WizardStepNames.PoolConfirm, draft.Step);
|
||||
|
||||
Reference in New Issue
Block a user