using NSubstitute;
using TeleWave.Application.Admin.Roles.ChangeUserRole;
using TeleWave.Application.Common.Interfaces;
using TeleWave.Application.Common.Models;
using Xunit;

namespace TeleWave.Application.Tests.Admin.Roles;

public class ChangeUserRoleCommandHandlerTests
{
    private readonly IRoleService _roleService = Substitute.For<IRoleService>();

    [Fact]
    public async Task Handle_DelegatesToRoleService()
    {
        var userId = Guid.NewGuid();
        var roleId = Guid.NewGuid();
        _roleService
            .ChangeUserRoleAsync(userId, roleId, Arg.Any<CancellationToken>())
            .Returns(Result.Success());

        var handler = new ChangeUserRoleCommandHandler(_roleService);
        var result = await handler.Handle(
            new ChangeUserRoleCommand(userId, roleId),
            CancellationToken.None
        );

        Assert.True(result.IsSuccess);
        await _roleService
            .Received(1)
            .ChangeUserRoleAsync(userId, roleId, Arg.Any<CancellationToken>());
    }
}
