Fixed the login unit test.
This commit is contained in:
parent
37de640317
commit
d93d7e3dcc
@ -1,8 +1,10 @@
|
||||
using e_suite.API.Common.models;
|
||||
using eSuite.API.Controllers;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Moq;
|
||||
using NUnit.Framework;
|
||||
using System.Text.Json;
|
||||
|
||||
namespace eSuite.API.UnitTests.Controllers.AccountControllerUnitTests;
|
||||
|
||||
@ -65,29 +67,37 @@ public class LoginGetUnitTests : AccountControllerTestBase
|
||||
Assert.That(actualLogin, Is.EqualTo(login));
|
||||
}
|
||||
|
||||
|
||||
[Test]
|
||||
public async Task LoginGet_WhenSsoIdCookieExists_RedirectsToSsoLoginUrl()
|
||||
{
|
||||
//Arrange
|
||||
// Arrange
|
||||
Login? login = null;
|
||||
|
||||
var ssoProviderId = 1;
|
||||
var ssoUrl = "http://test.test/login";
|
||||
|
||||
_cookieManagerMock.Setup(x => x.GetSsoIdFromSsoIdCookie(It.IsAny<HttpRequest>())).ReturnsAsync(() => ssoProviderId);
|
||||
_singleSignOnMock.Setup(x => x.StartSingleSignOn(ssoProviderId, It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(() => ssoUrl);
|
||||
_cookieManagerMock
|
||||
.Setup(x => x.GetSsoIdFromSsoIdCookie(It.IsAny<HttpRequest>()))
|
||||
.ReturnsAsync(ssoProviderId);
|
||||
|
||||
//Act
|
||||
_singleSignOnMock
|
||||
.Setup(x => x.StartSingleSignOn(ssoProviderId, It.IsAny<CancellationToken>()))
|
||||
.ReturnsAsync(ssoUrl);
|
||||
|
||||
// Act
|
||||
var response = await _accountController.LoginGet(login, CancellationToken.None);
|
||||
|
||||
//Assert
|
||||
Assert.That(response, Is.TypeOf<RedirectResult>());
|
||||
// Assert
|
||||
Assert.That(response, Is.TypeOf<OkObjectResult>());
|
||||
|
||||
var redirectResult = response as RedirectResult;
|
||||
Assert.That( redirectResult?.Url, Is.EqualTo(ssoUrl));
|
||||
var json = response as OkObjectResult;
|
||||
Assert.That(json?.Value, Is.Not.Null);
|
||||
|
||||
_cookieManagerMock.Verify( x => x.DeleteSsoIdCookie(It.IsAny<HttpResponse>()), Times.Once);
|
||||
var payload = json!.Value as Redirect;
|
||||
Assert.That(payload.RedirectTo, Is.EqualTo(ssoUrl));
|
||||
|
||||
_cookieManagerMock.Verify(
|
||||
x => x.DeleteSsoIdCookie(It.IsAny<HttpResponse>()),
|
||||
Times.Once);
|
||||
}
|
||||
}
|
||||
@ -22,6 +22,11 @@ public class ProfileViewModel
|
||||
public ITranslatorFactory TranslatorFactory { get; set; }
|
||||
}
|
||||
|
||||
public class Redirect
|
||||
{
|
||||
public string RedirectTo { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This MVC controller is used to support all user interactions when logging in and out of the system, including profile updates.
|
||||
/// </summary>
|
||||
@ -71,7 +76,8 @@ public class AccountController : ESuiteController
|
||||
{
|
||||
await _cookieManager.DeleteSsoIdCookie(Response);
|
||||
var url = await _singleSignOn.StartSingleSignOn(ssoId.Value, cancellationToken);
|
||||
return Ok(new { redirectTo = url });
|
||||
|
||||
return Ok(new Redirect { RedirectTo = url });
|
||||
}
|
||||
|
||||
login ??= new Login();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user