using e_suite.API.Common.exceptions;
using e_suite.Database.Core.Extensions;
using e_suite.Database.Core.Tables.UserManager;
using NUnit.Framework;
using UserManager.UnitTests.Helpers;

namespace UserManager.UnitTests.UserManager;

[TestFixture]
public class CreateSingleUseGuidUnitTests : UserManagerTestBase<object>
{
    [SetUp]
    public override async Task Setup()
    {
        await base.Setup();
    }

    [Test]
    public async Task CreateSingleUseGuid_UserExists_TurnsOffSsoForUser()
    {
        //Arrange
        var user = new User
        {
            Id = 2,
            Email = "testuser@sun-strategy.com"
        };

        await UserManagerRepository.AddUser(AuditUserDetails, user, default);

        //Act
        var guid = await UserManager.CreateSingleUseGuid(AuditUserDetails, user.ToGeneralIdRef()!, CancellationToken.None);

        //Assert
        Assert.That(guid, Is.Not.Null);
    }

    [Test]
    public void CreateSingleUseGuid_UserDoesNotExist_ThrowsNotFoundException()
    {
        //Arrange
        var user = new User
        {
            Id = 2,
            Email = "testuser@sun-strategy.com",
        };

        //Act & Assert
        Assert.ThrowsAsync<NotFoundException>(async () =>
        {
            var guid = await UserManager.CreateSingleUseGuid(AuditUserDetails, user.ToGeneralIdRef()!,
                CancellationToken.None);
        });
    }
}