test: cover core bot and web scenarios
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
using GmRelay.Bot.Features.Confirmation.HandleRsvp;
|
||||
using GmRelay.Shared.Domain;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Confirmation.HandleRsvp;
|
||||
|
||||
public sealed class RsvpFlowRulesTests
|
||||
{
|
||||
[Fact]
|
||||
public void Evaluate_ShouldRevertAndAlert_WhenConfirmedSessionGetsDecline()
|
||||
{
|
||||
var decision = RsvpFlowRules.Evaluate(
|
||||
RsvpStatus.Declined,
|
||||
SessionStatus.Confirmed,
|
||||
totalParticipants: 3,
|
||||
confirmedParticipants: 2);
|
||||
|
||||
Assert.True(decision.ShouldAlertGm);
|
||||
Assert.True(decision.ShouldRevertSessionToConfirmationSent);
|
||||
Assert.False(decision.ShouldMarkSessionConfirmed);
|
||||
Assert.Equal("Вы отказались от участия.", decision.CallbackText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Evaluate_ShouldMarkConfirmed_WhenLastParticipantConfirms()
|
||||
{
|
||||
var decision = RsvpFlowRules.Evaluate(
|
||||
RsvpStatus.Confirmed,
|
||||
SessionStatus.ConfirmationSent,
|
||||
totalParticipants: 3,
|
||||
confirmedParticipants: 3);
|
||||
|
||||
Assert.True(decision.ShouldMarkSessionConfirmed);
|
||||
Assert.True(decision.ShouldNotifyGroup);
|
||||
Assert.True(decision.ShouldNotifyGm);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Evaluate_ShouldKeepWaiting_WhenNotEveryoneConfirmed()
|
||||
{
|
||||
var decision = RsvpFlowRules.Evaluate(
|
||||
RsvpStatus.Confirmed,
|
||||
SessionStatus.ConfirmationSent,
|
||||
totalParticipants: 4,
|
||||
confirmedParticipants: 2);
|
||||
|
||||
Assert.False(decision.ShouldMarkSessionConfirmed);
|
||||
Assert.False(decision.ShouldNotifyGroup);
|
||||
Assert.False(decision.ShouldNotifyGm);
|
||||
}
|
||||
}
|
||||
+68
@@ -0,0 +1,68 @@
|
||||
using GmRelay.Bot.Features.Sessions.CreateSession;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.CreateSession;
|
||||
|
||||
public sealed class NewSessionCommandParserTests
|
||||
{
|
||||
[Fact]
|
||||
public void Parse_ShouldExtractTitleLinkAndUpcomingTimes()
|
||||
{
|
||||
var nowUtc = new DateTimeOffset(2026, 4, 23, 12, 0, 0, TimeSpan.Zero);
|
||||
var text = """
|
||||
/newsession
|
||||
Название: Curse of Strahd
|
||||
Время: 24.04.2026 19:30
|
||||
Время: 01.05.2026 20:00
|
||||
Ссылка: https://example.test/room
|
||||
""";
|
||||
|
||||
var result = NewSessionCommandParser.Parse(text, nowUtc);
|
||||
|
||||
Assert.True(result.IsValid);
|
||||
Assert.Equal("Curse of Strahd", result.Title);
|
||||
Assert.Equal("https://example.test/room", result.Link);
|
||||
Assert.Equal(
|
||||
[
|
||||
new DateTimeOffset(2026, 4, 24, 16, 30, 0, TimeSpan.Zero),
|
||||
new DateTimeOffset(2026, 5, 1, 17, 0, 0, TimeSpan.Zero)
|
||||
],
|
||||
result.ScheduledTimes);
|
||||
Assert.Empty(result.PastTimeInputs);
|
||||
Assert.Empty(result.InvalidTimeInputs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_ShouldCollectPastAndInvalidTimes()
|
||||
{
|
||||
var nowUtc = new DateTimeOffset(2026, 4, 23, 12, 0, 0, TimeSpan.Zero);
|
||||
var text = """
|
||||
Название: Delta Green
|
||||
Время: 20.04.2026 19:30
|
||||
Время: 31.04.2026 19:30
|
||||
Время: 25.04.2026 18:00
|
||||
Ссылка: https://example.test/dg
|
||||
""";
|
||||
|
||||
var result = NewSessionCommandParser.Parse(text, nowUtc);
|
||||
|
||||
Assert.True(result.IsValid);
|
||||
Assert.Single(result.ScheduledTimes);
|
||||
Assert.Equal(["20.04.2026 19:30"], result.PastTimeInputs);
|
||||
Assert.Equal(["31.04.2026 19:30"], result.InvalidTimeInputs);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Parse_ShouldBeInvalid_WhenRequiredFieldsMissing()
|
||||
{
|
||||
var text = """
|
||||
/newsession
|
||||
Название: Blades in the Dark
|
||||
Время: 25.04.2026 19:30
|
||||
""";
|
||||
|
||||
var result = NewSessionCommandParser.Parse(text, DateTimeOffset.UtcNow);
|
||||
|
||||
Assert.False(result.IsValid);
|
||||
Assert.Null(result.Link);
|
||||
}
|
||||
}
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
using GmRelay.Bot.Features.Sessions.RescheduleSession;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.RescheduleSession;
|
||||
|
||||
public sealed class HandleRescheduleTimeInputHandlerTests
|
||||
{
|
||||
[Fact]
|
||||
public void BuildVotingMessage_ShouldShowApprovedAndPendingParticipants()
|
||||
{
|
||||
var approvedId = Guid.NewGuid();
|
||||
var pendingId = Guid.NewGuid();
|
||||
var currentTime = new DateTime(2026, 4, 25, 16, 30, 0, DateTimeKind.Utc);
|
||||
var newTime = new DateTimeOffset(2026, 4, 26, 17, 0, 0, TimeSpan.Zero);
|
||||
var participants = new List<VoteParticipantDto>
|
||||
{
|
||||
new(approvedId, "Alice", "alice"),
|
||||
new(pendingId, "Bob", null)
|
||||
};
|
||||
|
||||
var text = HandleRescheduleTimeInputHandler.BuildVotingMessage(
|
||||
"Shadowrun",
|
||||
currentTime,
|
||||
newTime,
|
||||
participants,
|
||||
[approvedId]);
|
||||
|
||||
Assert.Contains("Shadowrun", text);
|
||||
Assert.Contains("✅ @alice", text);
|
||||
Assert.Contains("⏳ Bob", text);
|
||||
Assert.Contains("Голоса: 1/2 ✅", text);
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
using GmRelay.Bot.Features.Sessions.RescheduleSession;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Features.Sessions.RescheduleSession;
|
||||
|
||||
public sealed class RescheduleVoteRulesTests
|
||||
{
|
||||
[Fact]
|
||||
public void Evaluate_ShouldReject_WhenParticipantVotesNo()
|
||||
{
|
||||
var decision = RescheduleVoteRules.Evaluate("no", totalParticipants: 4, approvedParticipants: 3);
|
||||
|
||||
Assert.Equal(RescheduleVoteOutcome.Rejected, decision.Outcome);
|
||||
Assert.False(decision.ShouldRescheduleSession);
|
||||
Assert.Equal("Вы проголосовали против переноса.", decision.CallbackText);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Evaluate_ShouldApprove_WhenEveryoneVotedYes()
|
||||
{
|
||||
var decision = RescheduleVoteRules.Evaluate("yes", totalParticipants: 3, approvedParticipants: 3);
|
||||
|
||||
Assert.Equal(RescheduleVoteOutcome.Approved, decision.Outcome);
|
||||
Assert.True(decision.ShouldRescheduleSession);
|
||||
Assert.True(decision.ShouldResetParticipantRsvps);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void Evaluate_ShouldStayPending_WhileVotesOutstanding()
|
||||
{
|
||||
var decision = RescheduleVoteRules.Evaluate("yes", totalParticipants: 5, approvedParticipants: 2);
|
||||
|
||||
Assert.Equal(RescheduleVoteOutcome.Pending, decision.Outcome);
|
||||
Assert.False(decision.ShouldRescheduleSession);
|
||||
Assert.False(decision.ShouldResetParticipantRsvps);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user