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;
|
2026-01-09 22:14:46 +01:00
|
|
|
|
|
|
|
|
[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
|
|
|
|
|
{
|
2026-01-09 22:14:46 +01:00
|
|
|
IAccountService _accountService;
|
2025-03-03 00:42:20 +01:00
|
|
|
IEmailService _emailService;
|
|
|
|
|
IOrganizationService _organizationService;
|
|
|
|
|
|
2026-01-09 22:14:46 +01:00
|
|
|
protected Account _currentAccount;
|
2025-03-03 00:42:20 +01:00
|
|
|
protected string _currentEmail;
|
|
|
|
|
protected string _confirmationLink;
|
|
|
|
|
protected bool _redirectedToWelcome;
|
|
|
|
|
protected string _errorMessage;
|
|
|
|
|
|
2026-01-09 22:14:46 +01:00
|
|
|
public async Task Given_an_account_exists_with_unconfirmed_email(string email)
|
2025-03-03 00:42:20 +01:00
|
|
|
{
|
2026-01-09 22:14:46 +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);
|
2026-01-09 22:14:46 +01:00
|
|
|
await _accountService.ConfirmEmailAsync(_confirmationLink);
|
2025-03-03 00:42:20 +01:00
|
|
|
_redirectedToWelcome = true; // Simulate redirect
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-09 22:14:46 +01:00
|
|
|
public async Task Then_the_accounts_email_confirmed_should_be_true()
|
2025-03-03 00:42:20 +01:00
|
|
|
{
|
2026-01-09 22:14:46 +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
|
|
|
|
|
{
|
2026-01-09 22:14:46 +01:00
|
|
|
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()
|
|
|
|
|
{
|
2026-01-09 22:14:46 +01:00
|
|
|
if (_currentAccount != null)
|
2025-03-03 00:42:20 +01:00
|
|
|
{
|
2026-01-09 22:14:46 +01:00
|
|
|
_currentAccount.EmailConfirmed.ShouldBeFalse();
|
2025-03-03 00:42:20 +01:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-09 22:14:46 +01:00
|
|
|
}
|