From 15a7687e4ca21dca45d8f87171abefbe1907be99 Mon Sep 17 00:00:00 2001 From: dmolinari Date: Tue, 14 Apr 2026 13:28:10 -0300 Subject: [PATCH] test(app): add LogoutCommandHandler tests RED --- .../Auth/Logout/LogoutCommandHandlerTests.cs | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 tests/SIGCM2.Application.Tests/Auth/Logout/LogoutCommandHandlerTests.cs diff --git a/tests/SIGCM2.Application.Tests/Auth/Logout/LogoutCommandHandlerTests.cs b/tests/SIGCM2.Application.Tests/Auth/Logout/LogoutCommandHandlerTests.cs new file mode 100644 index 0000000..2237bc4 --- /dev/null +++ b/tests/SIGCM2.Application.Tests/Auth/Logout/LogoutCommandHandlerTests.cs @@ -0,0 +1,39 @@ +using NSubstitute; +using SIGCM2.Application.Abstractions.Persistence; +using SIGCM2.Application.Auth.Logout; + +namespace SIGCM2.Application.Tests.Auth.Logout; + +public class LogoutCommandHandlerTests +{ + private readonly IRefreshTokenRepository _refreshRepo = Substitute.For(); + private readonly LogoutCommandHandler _handler; + + public LogoutCommandHandlerTests() + { + _handler = new LogoutCommandHandler(_refreshRepo); + } + + [Fact] + public async Task Handle_RevokesAllActiveForUser() + { + _refreshRepo.RevokeAllActiveForUserAsync(42, Arg.Any()).Returns(3); + + var result = await _handler.Handle(new LogoutCommand(42)); + + Assert.True(result.Success); + Assert.False(string.IsNullOrWhiteSpace(result.Mensaje)); + await _refreshRepo.Received(1).RevokeAllActiveForUserAsync(42, Arg.Any()); + } + + [Fact] + public async Task Handle_NoActiveTokens_StillReturnsSuccess() + { + // 0 rows affected = idempotent logout + _refreshRepo.RevokeAllActiveForUserAsync(Arg.Any(), Arg.Any()).Returns(0); + + var result = await _handler.Handle(new LogoutCommand(99)); + + Assert.True(result.Success); + } +}