using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;

namespace eSuite.API.UnitTests.Controllers.AccountControllerUnitTests;

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

    [Test]
    public async Task Logout_WhenCalled_DeletesBrowserCookiesAndRedirectsToRoot()
    {
        //Arrange

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

        //Assert
        Assert.That(response, Is.TypeOf<RedirectResult>());
        var redirectResult = response as RedirectResult;
        Assert.That(redirectResult?.Url, Is.EqualTo("~/"));

        _cookieManagerMock.Verify(x => x.DeleteSessionCookie(It.IsAny<HttpResponse>()), Times.Once);
        _cookieManagerMock.Verify(x => x.DeleteSsoIdCookie(It.IsAny<HttpResponse>()), Times.Once);
    }
}