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

130 lines
4.2 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;
2025-03-03 00:42:20 +01:00
[TestClass]
[FeatureDescription(@"As a user with confirmed email
I want to set up my organization
So I can start using the system with my team")]
public partial class OrganizationSetupSpecs : FeatureFixture
{
IAccountService _accountService;
2025-03-03 00:42:20 +01:00
IEmailService _emailService;
IOrganizationService _organizationService;
IAccountOrganizationService _accountOrganizationService;
2025-03-03 00:42:20 +01:00
ITenantService _tenantService;
IAuthService _authService;
protected Account _currentAccount;
2025-03-03 00:42:20 +01:00
protected Organization _organization;
protected Exception _setupError;
protected List<Organization> _accountOrganizations;
2025-03-03 00:42:20 +01:00
public async Task Given_account_has_confirmed_their_email(string email)
2025-03-03 00:42:20 +01:00
{
// Create an account with confirmed email
_currentAccount = await _accountService.CreateAccountAsync(email, "TestPassword123!");
2025-03-03 00:42:20 +01:00
var confirmationLink = await _emailService.GetConfirmationLinkForEmail(email);
await _accountService.ConfirmEmailAsync(confirmationLink);
_currentAccount.EmailConfirmed.ShouldBeTrue();
2025-03-03 00:42:20 +01:00
}
public async Task When_account_submit_organization_name_and_valid_password(string orgName, string password)
2025-03-03 00:42:20 +01:00
{
try
{
_organization = await _organizationService.SetupOrganizationAsync(_currentAccount.Id, orgName, password);
2025-03-03 00:42:20 +01:00
}
catch (Exception ex)
{
_setupError = ex;
}
}
public async Task Then_a_new_organization_should_be_created_with_expected_properties()
{
_organization.ShouldNotBeNull();
_organization.Name.ShouldBe("Acme Corp");
_organization.CreatedBy.ShouldBe(_currentAccount.Id);
2025-03-03 00:42:20 +01:00
await Task.CompletedTask;
}
public async Task And_the_account_should_be_linked_to_the_organization_in_account_organizations()
2025-03-03 00:42:20 +01:00
{
var accountOrg = _accountOrganizationService.GetAccountOrganization(_currentAccount.Id, _organization.Id);
accountOrg.ShouldNotBeNull();
2025-03-03 00:42:20 +01:00
await Task.CompletedTask;
}
public async Task And_tenant_tables_should_be_created_for_the_organization()
{
var tenantTablesExist = _tenantService.ValidateTenantTablesExist(_organization.Id);
tenantTablesExist.ShouldBeTrue();
await Task.CompletedTask;
}
public async Task And_account_should_be_logged_into_the_system()
2025-03-03 00:42:20 +01:00
{
var isAuthenticated = _authService.IsAccountAuthenticated(_currentAccount.Id);
2025-03-03 00:42:20 +01:00
isAuthenticated.ShouldBeTrue();
await Task.CompletedTask;
}
public async Task When_account_submit_organization_name_without_password(string orgName)
2025-03-03 00:42:20 +01:00
{
try
{
await _organizationService.SetupOrganizationAsync(_currentAccount.Id, orgName, "");
2025-03-03 00:42:20 +01:00
}
catch (Exception ex)
{
_setupError = ex;
}
}
public async Task Then_organization_setup_should_fail_with_error(string expectedErrorMessage)
{
_setupError.ShouldNotBeNull();
_setupError.Message.ShouldBe(expectedErrorMessage);
await Task.CompletedTask;
}
public async Task Given_account_has_completed_initial_setup(string email)
2025-03-03 00:42:20 +01:00
{
await Given_account_has_confirmed_their_email(email);
await When_account_submit_organization_name_and_valid_password("First Org", "ValidP@ssw0rd");
_accountOrganizations = new List<Organization> { _organization };
2025-03-03 00:42:20 +01:00
}
public async Task When_account_create_a_new_organization(string orgName)
2025-03-03 00:42:20 +01:00
{
var newOrg = await _organizationService.CreateOrganizationAsync(_currentAccount.Id, orgName);
_accountOrganizations.Add(newOrg);
2025-03-03 00:42:20 +01:00
}
public async Task Then_a_new_organization_entry_should_be_created()
{
_accountOrganizations.Count.ShouldBe(2);
_accountOrganizations[1].Name.ShouldBe("Second Org");
2025-03-03 00:42:20 +01:00
await Task.CompletedTask;
}
public async Task And_the_account_should_be_linked_to_both_organizations()
2025-03-03 00:42:20 +01:00
{
var accountOrgs = _accountOrganizationService.GetAccountOrganizations(_currentAccount.Id);
accountOrgs.Count.ShouldBe(2);
2025-03-03 00:42:20 +01:00
await Task.CompletedTask;
}
}