1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-04 14:13:28 +01:00
bitwarden-server/test/Core.Test/AdminConsole/OrganizationFeatures/OrganizationUsers/CountNewSmSeatsRequiredQueryTests.cs
Colton Hurst 7cbe888b82
SM-1012: Removing SM Beta (Phase 2) (#3663)
* SM-1012: Phase 2, removing SM Beta from the server (but not db)

* SM-1012: Add migration for RemoveSMBetaFromOrganization

* SM-1012: Dotnet format

* SM-1012: Undo RemoveSMBetaFromOrganization EF migration

* SM-1012: Redo RemoveSMBetaFromOrganization EF migration

* SM-1012: Ran dotnet format
2024-02-05 15:51:31 -05:00

90 lines
3.2 KiB
C#

using Bit.Core.AdminConsole.Entities;
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationUsers;
using Bit.Core.Exceptions;
using Bit.Core.Repositories;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationUsers;
[SutProviderCustomize]
public class CountNewSmSeatsRequiredQueryTests
{
[Theory]
[BitAutoData(2, 5, 2, 0)]
[BitAutoData(0, 5, 2, 0)]
[BitAutoData(6, 5, 2, 3)]
[BitAutoData(2, 5, 10, 7)]
public async Task CountNewSmSeatsRequiredAsync_ReturnsCorrectCount(
int usersToAdd,
int organizationSmSeats,
int currentOccupiedSmSeats,
int expectedNewSmSeatsRequired,
Organization organization,
SutProvider<CountNewSmSeatsRequiredQuery> sutProvider)
{
organization.UseSecretsManager = true;
organization.SmSeats = organizationSmSeats;
sutProvider.GetDependency<IOrganizationRepository>()
.GetByIdAsync(organization.Id)
.Returns(organization);
sutProvider.GetDependency<IOrganizationUserRepository>()
.GetOccupiedSmSeatCountByOrganizationIdAsync(organization.Id)
.Returns(currentOccupiedSmSeats);
var result = await sutProvider.Sut.CountNewSmSeatsRequiredAsync(organization.Id, usersToAdd);
Assert.Equal(expectedNewSmSeatsRequired, result);
}
[Theory]
[BitAutoData(0)]
[BitAutoData(5)]
public async Task CountNewSmSeatsRequiredAsync_WithNullSmSeats_ReturnsZero(
int usersToAdd,
Organization organization,
SutProvider<CountNewSmSeatsRequiredQuery> sutProvider)
{
const int expected = 0;
organization.UseSecretsManager = true;
organization.SmSeats = null;
sutProvider.GetDependency<IOrganizationRepository>()
.GetByIdAsync(organization.Id)
.Returns(organization);
var result = await sutProvider.Sut.CountNewSmSeatsRequiredAsync(organization.Id, usersToAdd);
Assert.Equal(expected, result);
}
[Theory, BitAutoData]
public async Task CountNewSmSeatsRequiredAsync_WithNonExistentOrganizationId_ThrowsNotFound(
Guid organizationId, int usersToAdd,
SutProvider<CountNewSmSeatsRequiredQuery> sutProvider)
{
await Assert.ThrowsAsync<NotFoundException>(async () => await sutProvider.Sut.CountNewSmSeatsRequiredAsync(organizationId, usersToAdd));
}
[Theory, BitAutoData]
public async Task CountNewSmSeatsRequiredAsync_WithOrganizationUseSecretsManagerFalse_ThrowsNotFound(
Organization organization, int usersToAdd,
SutProvider<CountNewSmSeatsRequiredQuery> sutProvider)
{
organization.UseSecretsManager = false;
sutProvider.GetDependency<IOrganizationRepository>()
.GetByIdAsync(organization.Id)
.Returns(organization);
var exception = await Assert.ThrowsAsync<BadRequestException>(async () =>
await sutProvider.Sut.CountNewSmSeatsRequiredAsync(organization.Id, usersToAdd));
Assert.Contains("Organization does not use Secrets Manager", exception.Message);
}
}