feat(platform): route scheduler notifications through platform messenger
PR Checks / test-and-build (pull_request) Successful in 7m9s
PR Checks / test-and-build (pull_request) Successful in 7m9s
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
namespace GmRelay.Bot.Tests.Infrastructure.Scheduling;
|
||||
|
||||
public sealed class SchedulerNotificationSourceTests
|
||||
{
|
||||
[Theory]
|
||||
[InlineData("src/GmRelay.Shared/Features/Confirmation/SendConfirmation/SendConfirmationHandler.cs")]
|
||||
[InlineData("src/GmRelay.Shared/Features/Confirmation/HandleRsvp/HandleRsvpHandler.cs")]
|
||||
[InlineData("src/GmRelay.Shared/Features/Reminders/SendOneHourReminder/SendOneHourReminderHandler.cs")]
|
||||
[InlineData("src/GmRelay.Shared/Features/Reminders/SendJoinLink/SendJoinLinkHandler.cs")]
|
||||
public async Task SchedulerNotificationHandlers_ShouldUsePlatformMessengerWithoutSdkClients(string relativePath)
|
||||
{
|
||||
var source = await ReadRepositoryFileAsync(relativePath);
|
||||
|
||||
Assert.True(
|
||||
source.Contains("IPlatformMessenger", StringComparison.Ordinal) ||
|
||||
source.Contains("PlatformDirectNotificationSender", StringComparison.Ordinal),
|
||||
"Handler should use IPlatformMessenger directly or through PlatformDirectNotificationSender.");
|
||||
Assert.DoesNotContain("Telegram.Bot", source, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("ITelegramBotClient", source, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("NetCord", source, StringComparison.Ordinal);
|
||||
Assert.DoesNotContain("RestClient", source, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task DiscordProgram_ShouldRegisterSharedSchedulerForDiscordPlatform()
|
||||
{
|
||||
var program = await ReadRepositoryFileAsync("src/GmRelay.DiscordBot/Program.cs");
|
||||
|
||||
Assert.Contains("PlatformSchedulerOptions(PlatformKind.Discord)", program, StringComparison.Ordinal);
|
||||
Assert.Contains("AddHostedService<SessionSchedulerService>", program, StringComparison.Ordinal);
|
||||
Assert.Contains("DbSessionTriggerStore", program, StringComparison.Ordinal);
|
||||
Assert.Contains("SendConfirmationHandler", program, StringComparison.Ordinal);
|
||||
Assert.Contains("SendJoinLinkHandler", program, StringComparison.Ordinal);
|
||||
Assert.Contains("SendOneHourReminderHandler", program, 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}'.");
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
using GmRelay.Bot.Features.Confirmation.SendConfirmation;
|
||||
using GmRelay.Bot.Features.Reminders.SendJoinLink;
|
||||
using GmRelay.Bot.Features.Reminders.SendOneHourReminder;
|
||||
using GmRelay.Bot.Infrastructure.Scheduling;
|
||||
using GmRelay.Shared.Features.Confirmation.SendConfirmation;
|
||||
using GmRelay.Shared.Features.Reminders.SendJoinLink;
|
||||
using GmRelay.Shared.Features.Reminders.SendOneHourReminder;
|
||||
using GmRelay.Shared.Infrastructure.Scheduling;
|
||||
using GmRelay.Shared.Platform;
|
||||
using Microsoft.Extensions.Logging.Abstractions;
|
||||
|
||||
namespace GmRelay.Bot.Tests.Infrastructure.Scheduling;
|
||||
@@ -211,4 +212,9 @@ public sealed class SessionSchedulerServiceTests
|
||||
return Task.FromResult<IReadOnlyList<Guid>>(SessionsNeedingJoinLink);
|
||||
}
|
||||
}
|
||||
|
||||
private sealed class FakeSystemClock : ISystemClock
|
||||
{
|
||||
public DateTimeOffset UtcNow { get; set; } = DateTimeOffset.UtcNow;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace GmRelay.Bot.Tests.Infrastructure.Scheduling;
|
||||
|
||||
public sealed class SessionTriggerStoreSourceTests
|
||||
{
|
||||
[Fact]
|
||||
public async Task DbSessionTriggerStore_ShouldFilterTriggersByConfiguredPlatform()
|
||||
{
|
||||
var source = await ReadRepositoryFileAsync(
|
||||
"src/GmRelay.Shared/Infrastructure/Scheduling/ISessionTriggerStore.cs");
|
||||
|
||||
Assert.Contains("PlatformSchedulerOptions", source, StringComparison.Ordinal);
|
||||
Assert.Contains("JOIN game_groups g ON g.id = s.group_id", source, StringComparison.Ordinal);
|
||||
Assert.Contains("g.platform = @Platform", source, 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}'.");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user