Bifrost/tests/Bifrost.Web.Tests/MigrationDiscoveryTests.cs
Heimdall 8c3827b36d Consent: optional at registration, a consent page with accept and withdraw, notice version 2
Registration without acceptedNoticeVersion (JSON) or with the box unticked (form) creates the account with no receipt; a version sent must still equal the one in force. GET /auth/bifrost/consent shows the notice and the account's state with the one applicable button. POST accept and withdraw are forms behind the strict RequestOriginGuard.Allows (403 before any read or write), idempotent, and withdraw is no longer JSON. The ConsentReceipt unique index becomes filtered to live rows so a person can agree again after withdrawing. TrainingNotice.Version = 2 with the ruled text.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-11 11:22:22 +00:00

62 lines
2.2 KiB
C#

using Bifrost.Web.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Bifrost.Web.Tests;
public sealed class MigrationDiscoveryTests
{
private static readonly string[] ExpectedMigrations =
[
"20260422084653_InitialAlphaFoundation",
"20260608210000_AddHeimdallUserIdentity",
"20260609143000_AddPatronSupportDerivation",
"20260609160000_AddExternalPatronProviderIntake",
"20260617010537_AddBridgeActionLedger",
"20260617022305_AddAgentDispatchRuns",
"20260617033635_AddAgentTransportReceipts",
"20260617041417_AddGovernanceActivityReceipts",
"20260622142000_AddBridgeActionIdentityProvenance",
"20260622165000_AddBifrostNativeIdentity",
"20260622202000_AddBridgeActionTargetSurfaceName",
"20260705190000_AddPatronSupportProjectAttribution",
"20261010043937_AddConceptVotes",
"20261022163159_AddOpenIddict",
"20261109200000_AddSealedBallotMotions",
"20261109210000_AddMindKeys",
"20261111090000_AddConsentReceipts",
"20261111100000_ConsentReceiptsOneLivePerVersion",
];
// Database.GetMigrations() reads assembly metadata only; no connection is opened.
private static List<string> Discovered()
{
var options = new DbContextOptionsBuilder<BifrostDbContext>()
.UseNpgsql("Host=unused")
.Options;
using var db = new BifrostDbContext(options);
return db.Database.GetMigrations().ToList();
}
[Fact]
public void Every_migration_type_is_discovered()
{
var discovered = Discovered();
var declared = typeof(BifrostDbContext).Assembly.GetTypes()
.Where(t => !t.IsAbstract && typeof(Migration).IsAssignableFrom(t))
.ToList();
Assert.NotEmpty(declared);
Assert.Equal(declared.Count, discovered.Count);
foreach (var type in declared)
{
Assert.Contains(discovered, id => id.EndsWith("_" + type.Name, StringComparison.Ordinal));
}
}
[Fact]
public void All_sixteen_migrations_are_listed_in_order()
{
Assert.Equal(ExpectedMigrations, Discovered());
}
}