using Heimdall.Application.Auth.Commands.Disable2fa; using Heimdall.Application.Common; using Heimdall.Application.Tests.Common; using Heimdall.Domain.Entities; using Microsoft.AspNetCore.Identity; using Microsoft.Extensions.Logging; using NSubstitute; namespace Heimdall.Application.Tests.Handlers.Auth; public sealed class Disable2faHandlerTests { [Fact] public async Task Wrong_current_password_does_not_disable_two_factor() { var store = Substitute.For>(); var users = Substitute.For>(store, Microsoft.Extensions.Options.Options.Create(new IdentityOptions()), null!, null!, null!, null!, null!, null!, null!); var db = Substitute.For(); db.UserRecoveryCodes.Returns(MockDbSetHelper.CreateFor()); var user = new AppUser { Id = Guid.NewGuid() }; users.FindByIdAsync(user.Id.ToString()).Returns(user); users.CheckPasswordAsync(user, "wrong").Returns(false); var handler = new Disable2faHandler(users, db, Substitute.For>()); var result = await handler.Handle(new Disable2faCommand(user.Id, "wrong"), CancellationToken.None); result.IsSuccess.ShouldBeFalse(); result.StatusCode.ShouldBe(400); await users.DidNotReceive().SetTwoFactorEnabledAsync(user, false); } }