Test: a sign-in through a moved login lands on the survivor's account (saga rig opens to page tests)

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Heimdall 2026-11-14 10:07:46 +00:00
commit 24a880ad4c
2 changed files with 38 additions and 4 deletions

View file

@ -20,12 +20,12 @@ public sealed class AccountMergeSagaTests
{
private const string Passkey = "bifrost-passkey";
private sealed record Party(Guid Id, string HeimdallId, IReadOnlyDictionary<string, string> Logins);
internal sealed record Party(Guid Id, string HeimdallId, IReadOnlyDictionary<string, string> Logins);
/// <summary>A host plus the helpers every test needs: accounts with logins at the fake Heimdall, proofs, a scope per operation.</summary>
private sealed class Rig : IDisposable
internal sealed class Rig(bool realSessions = false) : IDisposable
{
public HeimdallHost Host { get; } = new();
public HeimdallHost Host { get; } = new(realSessions: realSessions);
public FakeMoves Moves => Host.Heimdall.Moves;
@ -42,7 +42,8 @@ public sealed class AccountMergeSagaTests
var account = new UserAccount
{
DisplayName = name, BifrostIdentity = name, NormalizedBifrostIdentity = BifrostIdentityService.NormalizeIdentity(name),
HeimdallAccountId = heimdallId, CreatedAtUtc = Clock.Now, LastSeenAtUtc = Clock.Now
HeimdallAccountId = heimdallId, CreatedAtUtc = Clock.Now, LastSeenAtUtc = Clock.Now,
MemberProfile = new MemberProfile { Nickname = name, Headline = "seed", UpdatedAtUtc = Clock.Now }
};
account.Membership = new Membership { UserAccountId = account.Id, Status = MembershipStatus.Active };
db.UserAccounts.Add(account);

View file

@ -0,0 +1,33 @@
using System.Net;
using Bifrost.Web.Domain;
using Bifrost.Web.Tests.Support;
using static Bifrost.Web.Tests.AccountMergeSagaTests;
namespace Bifrost.Web.Tests;
/// <summary>The merge status page's undo from the person's side: a browser session of the real host over the saga rig and the fake Heimdall's account model.</summary>
public sealed class MergeUndoPageTests
{
/// <summary>The Heimdall account that holds a login now, by the fake's own model of where a move left it.</summary>
private static string OwnerOf(Rig rig, string loginId) =>
rig.Moves.Logins.Single(x => x.Value.Any(l => l.Id == loginId)).Key;
[Fact]
public async Task A_sign_in_through_a_login_the_merge_moved_lands_on_the_survivors_account_not_the_folded_one()
{
using var rig = new Rig(realSessions: true);
var survivor = await rig.AccountAsync("survivor", "twitch");
var folded = await rig.AccountAsync("folded", "discord");
var id = await rig.ConfirmedAsync(survivor, folded, rig.Weak(survivor, "twitch"), rig.Weak(folded, "discord"));
Assert.Equal(AccountMergeState.Committed, (await rig.AdvanceAsync(id)).State);
// Heimdall answers a sign-in through the moved login with the account that holds the login now.
var landedOn = OwnerOf(rig, folded.Logins["discord"]);
Assert.Equal(survivor.HeimdallId, landedOn);
var session = await rig.Host.SignInSessionAsync(landedOn, "discord");
// The survivor acts (the folded account would be refused on this page: its actor has no account).
var (response, _) = await rig.Host.GetLinkedAccountsAsync(session);
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
}
}