Heimdall Gitea / Build and tests (pull_request) Failing after 9m26s
Heimdall Gitea / Build and scan server image (pull_request) Skipped
Heimdall Gitea / Build and scan agent image (pull_request) Skipped
Heimdall Gitea / Publish Docker Hub latest tags (pull_request) Skipped
Heimdall Gitea / Publish versioned release (pull_request) Skipped
81 lines
2.9 KiB
C#
81 lines
2.9 KiB
C#
using Bunit;
|
||
using Bunit.TestDoubles;
|
||
using Heimdall.Web.Components.Pages;
|
||
using Heimdall.Web.Services;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using NSubstitute;
|
||
using Shouldly;
|
||
|
||
namespace Heimdall.Web.Tests.Components.Pages;
|
||
|
||
public class RegisterTests : PageTestBase
|
||
{
|
||
private static AuthResponse SuccessResponse() => new(
|
||
"access-token", "refresh-token", DateTime.UtcNow.AddHours(1), false,
|
||
new UserInfo(Guid.NewGuid(), "user@heimdall.local", "Nouvel Utilisateur", ["Viewer"]));
|
||
|
||
private BunitNavigationManager Navigate()
|
||
=> Services.GetRequiredService<BunitNavigationManager>();
|
||
|
||
[Fact]
|
||
public void RegisterPage_AfficheFormulaire()
|
||
{
|
||
var cut = RenderPage<Register>();
|
||
|
||
cut.Markup.ShouldContain("Créer un compte");
|
||
cut.Markup.ShouldContain("Nom d’affichage");
|
||
cut.Markup.ShouldContain("Email");
|
||
cut.Markup.ShouldContain("Mot de passe");
|
||
cut.Markup.ShouldContain("S’inscrire");
|
||
cut.FindAll("input").Count.ShouldBe(3);
|
||
}
|
||
|
||
[Fact]
|
||
public async Task RegisterPage_EchecInscription_AfficheErreur()
|
||
{
|
||
Handler.On(HttpMethod.Post, "api/auth/register", System.Net.HttpStatusCode.BadRequest);
|
||
var cut = RenderPage<Register>();
|
||
|
||
cut.FindAll("input")[0].Input("Nouvel Utilisateur");
|
||
cut.FindAll("input")[1].Input("user@heimdall.local");
|
||
cut.FindAll("input")[2].Input("motdepasse-securise");
|
||
await cut.InvokeAsync(() => cut.Find("form").Submit());
|
||
|
||
cut.WaitForAssertion(() =>
|
||
cut.Markup.ShouldContain("Erreur lors de l’inscription"));
|
||
}
|
||
|
||
[Fact]
|
||
public async Task RegisterPage_Succes_NavigueVersDashboard()
|
||
{
|
||
Handler.On(HttpMethod.Post, "api/auth/register", SuccessResponse());
|
||
JSInterop.Setup<bool>("heimdallAuth.signIn", _ => true).SetResult(true);
|
||
|
||
var nav = Navigate();
|
||
var cut = RenderPage<Register>();
|
||
|
||
cut.FindAll("input")[0].Input("Nouvel Utilisateur");
|
||
cut.FindAll("input")[1].Input("user@heimdall.local");
|
||
cut.FindAll("input")[2].Input("motdepasse-securise");
|
||
await cut.InvokeAsync(() => cut.Find("form").Submit());
|
||
|
||
cut.WaitForAssertion(() => nav.Uri.ShouldBe("http://localhost/dashboard"));
|
||
await AuthProvider.Received(1).NotifyLoginAsync(Arg.Any<AuthResponse>());
|
||
}
|
||
|
||
[Fact]
|
||
public async Task RegisterPage_Exception_AfficheErreur()
|
||
{
|
||
Handler.On(HttpMethod.Post, "api/auth/register",
|
||
() => throw new InvalidOperationException("boom"));
|
||
var cut = RenderPage<Register>();
|
||
|
||
cut.FindAll("input")[0].Input("Nouvel Utilisateur");
|
||
cut.FindAll("input")[1].Input("user@heimdall.local");
|
||
cut.FindAll("input")[2].Input("motdepasse-securise");
|
||
await cut.InvokeAsync(() => cut.Find("form").Submit());
|
||
|
||
cut.WaitForAssertion(() => cut.Markup.ShouldContain("Erreur lors de l'opération"));
|
||
}
|
||
}
|