PlanTempusApp/PlanTempus.X.BDD/FeatureFixtures/EmailConfirmationSpecs.cs

75 lines
1.9 KiB
C#
Raw Normal View History

2025-03-03 00:42:20 +01:00
using LightBDD.Framework;
using LightBDD.Framework.Scenarios;
using LightBDD.MsTest3;
using PlanTempus.X.Services;
using Shouldly;
namespace PlanTempus.X.BDD.FeatureFixtures;
[TestClass]
2025-03-03 00:42:20 +01:00
[FeatureDescription(@"As a registered user
I want to confirm my email
So I can activate my account")]
public partial class EmailConfirmationSpecs : FeatureFixture
{
IAccountService _accountService;
2025-03-03 00:42:20 +01:00
IEmailService _emailService;
IOrganizationService _organizationService;
protected Account _currentAccount;
2025-03-03 00:42:20 +01:00
protected string _currentEmail;
protected string _confirmationLink;
protected bool _redirectedToWelcome;
protected string _errorMessage;
public async Task Given_an_account_exists_with_unconfirmed_email(string email)
2025-03-03 00:42:20 +01:00
{
_currentAccount = await _accountService.CreateAccountAsync(email, "TestPassword123!");
_currentAccount.EmailConfirmed.ShouldBeFalse();
2025-03-03 00:42:20 +01:00
_currentEmail = email;
}
public async Task When_I_click_the_valid_confirmation_link_for(string email)
{
_confirmationLink = await _emailService.GetConfirmationLinkForEmail(email);
await _accountService.ConfirmEmailAsync(_confirmationLink);
2025-03-03 00:42:20 +01:00
_redirectedToWelcome = true; // Simulate redirect
}
public async Task Then_the_accounts_email_confirmed_should_be_true()
2025-03-03 00:42:20 +01:00
{
_currentAccount = _accountService.GetAccountByEmail(_currentEmail);
_currentAccount.EmailConfirmed.ShouldBeTrue();
2025-03-03 00:42:20 +01:00
}
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 _accountService.ConfirmEmailAsync("invalid-confirmation-token");
2025-03-03 00:42:20 +01:00
}
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 (_currentAccount != null)
2025-03-03 00:42:20 +01:00
{
_currentAccount.EmailConfirmed.ShouldBeFalse();
2025-03-03 00:42:20 +01:00
}
}
}