using e_suite.API.Common.models;
using eSuite.Core.Miscellaneous;
using Microsoft.AspNetCore.Http;
using Moq;
using NUnit.Framework;

namespace eSuite.API.UnitTests.Controllers.AccountControllerUnitTests;

[TestFixture]
public class RefreshTokenUnitTests : AccountControllerTestBase
{
    [SetUp]
    public override async Task Setup()
    {
        await base.Setup();
    }

    [Test]
    public async Task RefreshToken_WhenCalledGeneratesNewToken()
    {
        //Arrange
        var userId = 99;
        var email = "email@mail.test";
        var displayName = "Testy McTester";
        AddAuthorisedUserToController(userId, email, displayName);

        var loginResponse = new LoginResponse
        {
            Result = LoginResult.Success,
            Token = "Json Web Toke goes here"
        };


        _userManagerMock.Setup(x => x.RefreshToken(It.IsAny<GeneralIdRef>(), It.IsAny<CancellationToken>()))
            .ReturnsAsync(() => loginResponse);

        //Act
        var response = await _accountController.RefreshToken(CancellationToken.None);

        //Assert
        _cookieManagerMock.Verify( x => x.CreateSessionCookie(It.IsAny<HttpResponse>(), loginResponse), Times.Once);
    }
}