@ -1,6 +1,5 @@
using Bit.Commercial.Core.AdminConsole.Services ;
using Bit.Commercial.Core.AdminConsole.Services ;
using Bit.Commercial.Core.Test.AdminConsole.AutoFixture ;
using Bit.Commercial.Core.Test.AdminConsole.AutoFixture ;
using Bit.Core ;
using Bit.Core.AdminConsole.Entities ;
using Bit.Core.AdminConsole.Entities ;
using Bit.Core.AdminConsole.Entities.Provider ;
using Bit.Core.AdminConsole.Entities.Provider ;
using Bit.Core.AdminConsole.Enums.Provider ;
using Bit.Core.AdminConsole.Enums.Provider ;
@ -55,36 +54,8 @@ public class ProviderServiceTests
}
}
[Theory, BitAutoData]
[Theory, BitAutoData]
public async Task CompleteSetupAsync_Success ( User user , Provider provider , string key ,
public async Task CompleteSetupAsync_Success ( User user , Provider provider , string key , TaxInfo taxInfo ,
[ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)] ProviderUser providerUser ,
[ProviderUser] ProviderUser providerUser ,
SutProvider < ProviderService > sutProvider )
{
providerUser . ProviderId = provider . Id ;
providerUser . UserId = user . Id ;
var userService = sutProvider . GetDependency < IUserService > ( ) ;
userService . GetUserByIdAsync ( user . Id ) . Returns ( user ) ;
var providerUserRepository = sutProvider . GetDependency < IProviderUserRepository > ( ) ;
providerUserRepository . GetByProviderUserAsync ( provider . Id , user . Id ) . Returns ( providerUser ) ;
var dataProtectionProvider = DataProtectionProvider . Create ( "ApplicationName" ) ;
var protector = dataProtectionProvider . CreateProtector ( "ProviderServiceDataProtector" ) ;
sutProvider . GetDependency < IDataProtectionProvider > ( ) . CreateProtector ( "ProviderServiceDataProtector" )
. Returns ( protector ) ;
sutProvider . Create ( ) ;
var token = protector . Protect ( $"ProviderSetupInvite {provider.Id} {user.Email} {CoreHelpers.ToEpocMilliseconds(DateTime.UtcNow)}" ) ;
await sutProvider . Sut . CompleteSetupAsync ( provider , user . Id , token , key ) ;
await sutProvider . GetDependency < IProviderRepository > ( ) . Received ( ) . UpsertAsync ( provider ) ;
await sutProvider . GetDependency < IProviderUserRepository > ( ) . Received ( )
. ReplaceAsync ( Arg . Is < ProviderUser > ( pu = > pu . UserId = = user . Id & & pu . ProviderId = = provider . Id & & pu . Key = = key ) ) ;
}
[Theory, BitAutoData]
public async Task CompleteSetupAsync_ConsolidatedBilling_Success ( User user , Provider provider , string key , TaxInfo taxInfo ,
[ProviderUser(ProviderUserStatusType.Confirmed, ProviderUserType.ProviderAdmin)] ProviderUser providerUser ,
SutProvider < ProviderService > sutProvider )
SutProvider < ProviderService > sutProvider )
{
{
providerUser . ProviderId = provider . Id ;
providerUser . ProviderId = provider . Id ;
@ -100,9 +71,6 @@ public class ProviderServiceTests
sutProvider . GetDependency < IDataProtectionProvider > ( ) . CreateProtector ( "ProviderServiceDataProtector" )
sutProvider . GetDependency < IDataProtectionProvider > ( ) . CreateProtector ( "ProviderServiceDataProtector" )
. Returns ( protector ) ;
. Returns ( protector ) ;
sutProvider . GetDependency < IFeatureService > ( ) . IsEnabled ( FeatureFlagKeys . EnableConsolidatedBilling )
. Returns ( true ) ;
var providerBillingService = sutProvider . GetDependency < IProviderBillingService > ( ) ;
var providerBillingService = sutProvider . GetDependency < IProviderBillingService > ( ) ;
var customer = new Customer { Id = "customer_id" } ;
var customer = new Customer { Id = "customer_id" } ;
@ -489,7 +457,7 @@ public class ProviderServiceTests
public async Task AddOrganization_OrganizationHasSecretsManager_Throws ( Provider provider , Organization organization , string key ,
public async Task AddOrganization_OrganizationHasSecretsManager_Throws ( Provider provider , Organization organization , string key ,
SutProvider < ProviderService > sutProvider )
SutProvider < ProviderService > sutProvider )
{
{
organization . PlanType = PlanType . EnterpriseAnnual ly ;
organization . PlanType = PlanType . EnterpriseMonth ly ;
organization . UseSecretsManager = true ;
organization . UseSecretsManager = true ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
@ -506,7 +474,7 @@ public class ProviderServiceTests
public async Task AddOrganization_Success ( Provider provider , Organization organization , string key ,
public async Task AddOrganization_Success ( Provider provider , Organization organization , string key ,
SutProvider < ProviderService > sutProvider )
SutProvider < ProviderService > sutProvider )
{
{
organization . PlanType = PlanType . EnterpriseAnnual ly ;
organization . PlanType = PlanType . EnterpriseMonth ly ;
var providerRepository = sutProvider . GetDependency < IProviderRepository > ( ) ;
var providerRepository = sutProvider . GetDependency < IProviderRepository > ( ) ;
providerRepository . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
providerRepository . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
@ -549,8 +517,8 @@ public class ProviderServiceTests
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
var providerOrganizationRepository = sutProvider . GetDependency < IProviderOrganizationRepository > ( ) ;
var providerOrganizationRepository = sutProvider . GetDependency < IProviderOrganizationRepository > ( ) ;
var expectedPlanType = PlanType . EnterpriseAnnual ly ;
var expectedPlanType = PlanType . EnterpriseMonth ly ;
organization . PlanType = PlanType . EnterpriseAnnual ly ;
organization . PlanType = PlanType . EnterpriseMonth ly ;
sutProvider . GetDependency < IOrganizationRepository > ( ) . GetByIdAsync ( organization . Id ) . Returns ( organization ) ;
sutProvider . GetDependency < IOrganizationRepository > ( ) . GetByIdAsync ( organization . Id ) . Returns ( organization ) ;
await sutProvider . Sut . AddOrganization ( provider . Id , organization . Id , key ) ;
await sutProvider . Sut . AddOrganization ( provider . Id , organization . Id , key ) ;
@ -579,12 +547,12 @@ public class ProviderServiceTests
BackdateProviderCreationDate ( provider , newCreationDate ) ;
BackdateProviderCreationDate ( provider , newCreationDate ) ;
provider . Type = ProviderType . Msp ;
provider . Type = ProviderType . Msp ;
organization . PlanType = PlanType . EnterpriseAnnual ly ;
organization . PlanType = PlanType . EnterpriseMonth ly ;
organization . Plan = "Enterprise (Annual ly)" ;
organization . Plan = "Enterprise (Month ly)" ;
var expectedPlanType = PlanType . EnterpriseAnnual ly2020 ;
var expectedPlanType = PlanType . EnterpriseMonth ly2020 ;
var expectedPlanId = "2020-enterprise-org-seat-annual ly" ;
var expectedPlanId = "2020-enterprise-org-seat-month ly" ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
var providerOrganizationRepository = sutProvider . GetDependency < IProviderOrganizationRepository > ( ) ;
var providerOrganizationRepository = sutProvider . GetDependency < IProviderOrganizationRepository > ( ) ;
@ -663,11 +631,11 @@ public class ProviderServiceTests
public async Task CreateOrganizationAsync_Success ( Provider provider , OrganizationSignup organizationSignup ,
public async Task CreateOrganizationAsync_Success ( Provider provider , OrganizationSignup organizationSignup ,
Organization organization , string clientOwnerEmail , User user , SutProvider < ProviderService > sutProvider )
Organization organization , string clientOwnerEmail , User user , SutProvider < ProviderService > sutProvider )
{
{
organizationSignup . Plan = PlanType . EnterpriseAnnual ly ;
organizationSignup . Plan = PlanType . EnterpriseMonth ly ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
var providerOrganizationRepository = sutProvider . GetDependency < IProviderOrganizationRepository > ( ) ;
var providerOrganizationRepository = sutProvider . GetDependency < IProviderOrganizationRepository > ( ) ;
sutProvider . GetDependency < IOrganizationService > ( ) . SignUp Async ( organizationSignup )
sutProvider . GetDependency < IOrganizationService > ( ) . SignupClient Async ( organizationSignup )
. Returns ( ( organization , null as OrganizationUser , new Collection ( ) ) ) ;
. Returns ( ( organization , null as OrganizationUser , new Collection ( ) ) ) ;
var providerOrganization =
var providerOrganization =
@ -688,7 +656,7 @@ public class ProviderServiceTests
}
}
[Theory, OrganizationCustomize, BitAutoData]
[Theory, OrganizationCustomize, BitAutoData]
public async Task CreateOrganizationAsync_ConsolidatedBillingEnabled_ InvalidPlanType_ThrowsBadRequestException (
public async Task CreateOrganizationAsync_InvalidPlanType_ThrowsBadRequestException (
Provider provider ,
Provider provider ,
OrganizationSignup organizationSignup ,
OrganizationSignup organizationSignup ,
Organization organization ,
Organization organization ,
@ -696,8 +664,6 @@ public class ProviderServiceTests
User user ,
User user ,
SutProvider < ProviderService > sutProvider )
SutProvider < ProviderService > sutProvider )
{
{
sutProvider . GetDependency < IFeatureService > ( ) . IsEnabled ( FeatureFlagKeys . EnableConsolidatedBilling ) . Returns ( true ) ;
provider . Type = ProviderType . Msp ;
provider . Type = ProviderType . Msp ;
provider . Status = ProviderStatusType . Billable ;
provider . Status = ProviderStatusType . Billable ;
@ -717,7 +683,7 @@ public class ProviderServiceTests
}
}
[Theory, OrganizationCustomize, BitAutoData]
[Theory, OrganizationCustomize, BitAutoData]
public async Task CreateOrganizationAsync_ConsolidatedBillingEnabled_ InvokeSignupClientAsync (
public async Task CreateOrganizationAsync_InvokeSignupClientAsync (
Provider provider ,
Provider provider ,
OrganizationSignup organizationSignup ,
OrganizationSignup organizationSignup ,
Organization organization ,
Organization organization ,
@ -725,8 +691,6 @@ public class ProviderServiceTests
User user ,
User user ,
SutProvider < ProviderService > sutProvider )
SutProvider < ProviderService > sutProvider )
{
{
sutProvider . GetDependency < IFeatureService > ( ) . IsEnabled ( FeatureFlagKeys . EnableConsolidatedBilling ) . Returns ( true ) ;
provider . Type = ProviderType . Msp ;
provider . Type = ProviderType . Msp ;
provider . Status = ProviderStatusType . Billable ;
provider . Status = ProviderStatusType . Billable ;
@ -771,11 +735,11 @@ public class ProviderServiceTests
( Provider provider , OrganizationSignup organizationSignup , Organization organization , string clientOwnerEmail ,
( Provider provider , OrganizationSignup organizationSignup , Organization organization , string clientOwnerEmail ,
User user , SutProvider < ProviderService > sutProvider , Collection defaultCollection )
User user , SutProvider < ProviderService > sutProvider , Collection defaultCollection )
{
{
organizationSignup . Plan = PlanType . EnterpriseAnnual ly ;
organizationSignup . Plan = PlanType . EnterpriseMonth ly ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
sutProvider . GetDependency < IProviderRepository > ( ) . GetByIdAsync ( provider . Id ) . Returns ( provider ) ;
var providerOrganizationRepository = sutProvider . GetDependency < IProviderOrganizationRepository > ( ) ;
var providerOrganizationRepository = sutProvider . GetDependency < IProviderOrganizationRepository > ( ) ;
sutProvider . GetDependency < IOrganizationService > ( ) . SignUp Async ( organizationSignup )
sutProvider . GetDependency < IOrganizationService > ( ) . SignupClient Async ( organizationSignup )
. Returns ( ( organization , null as OrganizationUser , defaultCollection ) ) ;
. Returns ( ( organization , null as OrganizationUser , defaultCollection ) ) ;
var providerOrganization =
var providerOrganization =