Files
meeting-assistant/MeetingAssistant.Tests/MeetingWorkflowDiagnosticEndpointTests.cs

63 lines
2.5 KiB
C#

using System.Net;
using System.Net.Http.Json;
using System.Text.Json;
using Microsoft.AspNetCore.Mvc.Testing;
using Microsoft.Extensions.Configuration;
namespace MeetingAssistant.Tests;
public sealed class MeetingWorkflowDiagnosticEndpointTests
{
[Fact]
public async Task ReloadEndpointReloadsAutomationRulesPathFromConfigurationFile()
{
var root = Path.Combine(Path.GetTempPath(), "meeting-assistant-tests", Guid.NewGuid().ToString("N"));
Directory.CreateDirectory(root);
var configPath = Path.Combine(root, "workflow-config.json");
var firstRulesPath = Path.Combine(root, "first-rules.yaml");
var secondRulesPath = Path.Combine(root, "second-rules.yaml");
await File.WriteAllTextAsync(configPath, CreateConfigJson(firstRulesPath));
await using var factory = new WebApplicationFactory<Program>()
.WithWebHostBuilder(builder =>
{
builder.ConfigureAppConfiguration((_, configuration) =>
{
configuration.AddJsonFile(configPath, optional: false, reloadOnChange: false);
configuration.AddInMemoryCollection(new Dictionary<string, string?>
{
["MeetingAssistant:FunAsr:Backend:Enabled"] = "false"
});
});
});
using var client = factory.CreateClient();
using var firstResponse = await client.PostAsync("/diagnostics/workflow/reload", null);
var firstBody = await firstResponse.Content.ReadFromJsonAsync<WorkflowReloadResponse>();
await File.WriteAllTextAsync(configPath, CreateConfigJson(secondRulesPath));
using var secondResponse = await client.PostAsync("/diagnostics/workflow/reload", null);
var secondBody = await secondResponse.Content.ReadFromJsonAsync<WorkflowReloadResponse>();
Assert.Equal(HttpStatusCode.OK, firstResponse.StatusCode);
Assert.Equal(firstRulesPath, firstBody?.RulesPath);
Assert.Equal(HttpStatusCode.OK, secondResponse.StatusCode);
Assert.Equal(secondRulesPath, secondBody?.RulesPath);
}
private static string CreateConfigJson(string rulesPath)
{
return JsonSerializer.Serialize(new
{
MeetingAssistant = new
{
Automation = new
{
RulesPath = rulesPath
}
}
});
}
private sealed record WorkflowReloadResponse(string? RulesPath);
}