using Bit.Api.IntegrationTest.Factories; using Bit.Core.AdminConsole.Entities.Provider; using Bit.Core.AdminConsole.Enums.Provider; using Bit.Core.AdminConsole.Repositories; using Bit.Core.Repositories; namespace Bit.Api.IntegrationTest.Helpers; public static class ProviderTestHelpers { /// /// Creates a provider and links it to an organization. /// This does NOT create any provider users. /// /// The API application factory /// The organization ID to link to the provider /// The type of provider to create /// The provider status (defaults to Created) /// The created provider public static async Task CreateProviderAndLinkToOrganizationAsync( ApiApplicationFactory factory, Guid organizationId, ProviderType providerType, ProviderStatusType providerStatus = ProviderStatusType.Created) { var providerRepository = factory.GetService(); var providerOrganizationRepository = factory.GetService(); // Create the provider var provider = await providerRepository.CreateAsync(new Provider { Name = $"Test {providerType} Provider", BusinessName = $"Test {providerType} Provider Business", BillingEmail = $"provider-{providerType.ToString().ToLower()}@example.com", Type = providerType, Status = providerStatus, Enabled = true }); // Link the provider to the organization await providerOrganizationRepository.CreateAsync(new ProviderOrganization { ProviderId = provider.Id, OrganizationId = organizationId, Key = "test-provider-key" }); return provider; } /// /// Creates a providerUser for a provider. /// public static async Task CreateProviderUserAsync( ApiApplicationFactory factory, Guid providerId, string userEmail, ProviderUserType providerUserType) { var userRepository = factory.GetService(); var user = await userRepository.GetByEmailAsync(userEmail); if (user is null) { throw new Exception("No user found in test setup."); } var providerUserRepository = factory.GetService(); return await providerUserRepository.CreateAsync(new ProviderUser { ProviderId = providerId, Status = ProviderUserStatusType.Confirmed, UserId = user.Id, Key = Guid.NewGuid().ToString(), Type = providerUserType }); } }