7cb5b03cc2
PR Checks / test-and-build (pull_request) Failing after 20m55s
Prevent offline sessions with empty join links from entering the 5-minute join-link notification flow, omit blank link lines from direct reminders, and add offline persistence/reminder regression coverage.
69 lines
3.0 KiB
C#
69 lines
3.0 KiB
C#
using GmRelay.Bot.Tests.Features.Sessions.CreateSession;
|
|
using GmRelay.Shared.Domain;
|
|
using GmRelay.Shared.Infrastructure.Scheduling;
|
|
using GmRelay.Shared.Platform;
|
|
using Npgsql;
|
|
|
|
namespace GmRelay.Bot.Tests.Infrastructure.Scheduling;
|
|
|
|
[Collection(CreateSessionHandlerPostgresCollection.Name)]
|
|
public sealed class DbSessionTriggerStoreTests(CreateSessionHandlerPostgresFixture fixture)
|
|
{
|
|
[Fact]
|
|
public async Task GetSessionsNeedingJoinLinkAsync_IgnoresConfirmedSessionsWithoutJoinLink()
|
|
{
|
|
var connectionString = await fixture.CreateMigratedDatabaseAsync();
|
|
await using var dataSource = NpgsqlDataSource.Create(connectionString);
|
|
await using var connection = await dataSource.OpenConnectionAsync();
|
|
|
|
var groupId = await InsertTelegramGroupAsync(connection);
|
|
var dueAt = DateTimeOffset.UtcNow.AddMinutes(4).UtcDateTime;
|
|
var onlineSessionId = await InsertSessionAsync(connection, groupId, dueAt, "https://vtt.example/game", "Online");
|
|
var offlineSessionId = await InsertSessionAsync(connection, groupId, dueAt, string.Empty, "Offline");
|
|
|
|
var sut = new DbSessionTriggerStore(dataSource, new PlatformSchedulerOptions(PlatformKind.Telegram));
|
|
|
|
var result = await sut.GetSessionsNeedingJoinLinkAsync(DateTimeOffset.UtcNow, CancellationToken.None);
|
|
|
|
Assert.Contains(onlineSessionId, result);
|
|
Assert.DoesNotContain(offlineSessionId, result);
|
|
}
|
|
|
|
private static async Task<Guid> InsertTelegramGroupAsync(NpgsqlConnection connection)
|
|
{
|
|
await using var command = new NpgsqlCommand(
|
|
"""
|
|
INSERT INTO game_groups (name, platform, external_group_id)
|
|
VALUES ('Trigger Test Group', 'Telegram', @ExternalGroupId)
|
|
RETURNING id
|
|
""",
|
|
connection);
|
|
command.Parameters.AddWithValue("ExternalGroupId", Guid.NewGuid().ToString("N"));
|
|
|
|
return (Guid)(await command.ExecuteScalarAsync() ?? throw new InvalidOperationException("Group insert failed."));
|
|
}
|
|
|
|
private static async Task<Guid> InsertSessionAsync(
|
|
NpgsqlConnection connection,
|
|
Guid groupId,
|
|
DateTime scheduledAt,
|
|
string joinLink,
|
|
string format)
|
|
{
|
|
await using var command = new NpgsqlCommand(
|
|
"""
|
|
INSERT INTO sessions (group_id, title, join_link, scheduled_at, status, format)
|
|
VALUES (@GroupId, 'Trigger Test Session', @JoinLink, @ScheduledAt, @Status, @Format)
|
|
RETURNING id
|
|
""",
|
|
connection);
|
|
command.Parameters.AddWithValue("GroupId", groupId);
|
|
command.Parameters.AddWithValue("JoinLink", joinLink);
|
|
command.Parameters.AddWithValue("ScheduledAt", scheduledAt);
|
|
command.Parameters.AddWithValue("Status", SessionStatus.Confirmed);
|
|
command.Parameters.AddWithValue("Format", format);
|
|
|
|
return (Guid)(await command.ExecuteScalarAsync() ?? throw new InvalidOperationException("Session insert failed."));
|
|
}
|
|
}
|