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,134 @@
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 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
{
IUserService _userService;
IEmailService _emailService;
IOrganizationService _organizationService;
IUserOrganizationService _userOrganizationService;
ITenantService _tenantService;
IAuthService _authService;
protected User _currentUser;
protected Organization _organization;
protected Exception _setupError;
protected List<Organization> _userOrganizations;
public async Task Given_user_has_confirmed_their_email(string email)
{
// Create a user with confirmed email
_currentUser = await _userService.CreateUserAsync(email, "Test User");
var confirmationLink = await _emailService.GetConfirmationLinkForEmail(email);
await _userService.ConfirmEmailAsync(confirmationLink);
_currentUser.EmailConfirmed.ShouldBeTrue();
}
public async Task When_user_submit_organization_name_and_valid_password(string orgName, string password)
{
try
{
_organization = await _organizationService.SetupOrganizationAsync(_currentUser.Id, orgName, password);
}
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(_currentUser.Id);
await Task.CompletedTask;
}
public async Task And_the_user_should_be_linked_to_the_organization_in_user_organizations()
{
var userOrg = _userOrganizationService.GetUserOrganization(_currentUser.Id, _organization.Id);
userOrg.ShouldNotBeNull();
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_user_should_be_logged_into_the_system()
{
var isAuthenticated = _authService.IsUserAuthenticated(_currentUser.Id);
isAuthenticated.ShouldBeTrue();
await Task.CompletedTask;
}
public async Task When_user_submit_organization_name_without_password(string orgName)
{
try
{
await _organizationService.SetupOrganizationAsync(_currentUser.Id, orgName, "");
}
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_user_has_completed_initial_setup(string email)
{
await Given_user_has_confirmed_their_email(email);
await When_user_submit_organization_name_and_valid_password("First Org", "ValidP@ssw0rd");
_userOrganizations = new List<Organization> { _organization };
}
public async Task When_user_create_a_new_organization(string orgName)
{
var newOrg = await _organizationService.CreateOrganizationAsync(_currentUser.Id, orgName);
_userOrganizations.Add(newOrg);
}
public async Task Then_a_new_organization_entry_should_be_created()
{
_userOrganizations.Count.ShouldBe(2);
_userOrganizations[1].Name.ShouldBe("Second Org");
await Task.CompletedTask;
}
public async Task And_the_user_should_be_linked_to_both_organizations()
{
var userOrgs = _userOrganizationService.GetUserOrganizations(_currentUser.Id);
userOrgs.Count.ShouldBe(2);
await Task.CompletedTask;
}
}