Various work around the architecture

This commit is contained in:
Janus C. H. Knudsen 2025-03-03 00:42:20 +01:00
parent b1e134490d
commit 71576a4b1f
18 changed files with 522 additions and 358 deletions

View file

@ -0,0 +1,73 @@
using LightBDD.Framework;
using LightBDD.Framework.Scenarios;
using LightBDD.MsTest3;
using PlanTempus.X.Services;
using Shouldly;
namespace PlanTempus.X.BDD.FeatureFixtures;
[TestClass]
[FeatureDescription(@"As a registered user
I want to confirm my email
So I can activate my account")]
public partial class EmailConfirmationSpecs : FeatureFixture
{
IUserService _userService;
IEmailService _emailService;
IOrganizationService _organizationService;
protected User _currentUser;
protected string _currentEmail;
protected string _confirmationLink;
protected bool _redirectedToWelcome;
protected string _errorMessage;
public async Task Given_a_user_exists_with_unconfirmed_email(string email)
{
_currentUser = await _userService.CreateUserAsync(email, "Test User");
_currentUser.EmailConfirmed.ShouldBeFalse();
_currentEmail = email;
}
public async Task When_I_click_the_valid_confirmation_link_for(string email)
{
_confirmationLink = await _emailService.GetConfirmationLinkForEmail(email);
await _userService.ConfirmEmailAsync(_confirmationLink);
_redirectedToWelcome = true; // Simulate redirect
}
public async Task Then_the_users_email_confirmed_should_be_true()
{
_currentUser = _userService.GetUserByEmail(_currentEmail);
_currentUser.EmailConfirmed.ShouldBeTrue();
}
public async Task And_I_should_be_redirected_to_the_welcome_page()
{
_redirectedToWelcome.ShouldBeTrue();
}
public async Task When_I_click_an_invalid_confirmation_link()
{
try
{
await _userService.ConfirmEmailAsync("invalid-confirmation-token");
}
catch (Exception ex)
{
_errorMessage = ex.Message;
}
}
public async Task Then_I_should_see_an_error_message(string expectedErrorMessage)
{
_errorMessage.ShouldBe(expectedErrorMessage);
}
public async Task And_my_email_remains_unconfirmed()
{
if (_currentUser != null)
{
_currentUser.EmailConfirmed.ShouldBeFalse();
}
}
}