diff --git a/tests/Bifrost.Web.Tests/AccountMergeSagaTests.cs b/tests/Bifrost.Web.Tests/AccountMergeSagaTests.cs index d3cfc6b..3503c53 100644 --- a/tests/Bifrost.Web.Tests/AccountMergeSagaTests.cs +++ b/tests/Bifrost.Web.Tests/AccountMergeSagaTests.cs @@ -20,12 +20,12 @@ public sealed class AccountMergeSagaTests { private const string Passkey = "bifrost-passkey"; - private sealed record Party(Guid Id, string HeimdallId, IReadOnlyDictionary Logins); + internal sealed record Party(Guid Id, string HeimdallId, IReadOnlyDictionary Logins); /// A host plus the helpers every test needs: accounts with logins at the fake Heimdall, proofs, a scope per operation. - 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); diff --git a/tests/Bifrost.Web.Tests/MergeUndoPageTests.cs b/tests/Bifrost.Web.Tests/MergeUndoPageTests.cs new file mode 100644 index 0000000..9250349 --- /dev/null +++ b/tests/Bifrost.Web.Tests/MergeUndoPageTests.cs @@ -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; + +/// 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. +public sealed class MergeUndoPageTests +{ + /// The Heimdall account that holds a login now, by the fake's own model of where a move left it. + 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); + } +}