1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-12 15:12:16 -05:00

Refactor error handling in ProviderClientOrganizationSignUpCommand to use constants for error messages

This commit is contained in:
Rui Tome 2025-05-02 15:24:08 +01:00
parent b62e97f601
commit bec9c555c6
No known key found for this signature in database
GPG Key ID: 526239D96A8EC066
2 changed files with 9 additions and 5 deletions

View File

@ -31,6 +31,10 @@ public interface IProviderClientOrganizationSignUpCommand
public class ProviderClientOrganizationSignUpCommand : IProviderClientOrganizationSignUpCommand
{
public const string PlanNullErrorMessage = "Password Manager Plan was null.";
public const string PlanDisabledErrorMessage = "Password Manager Plan is disabled.";
public const string AdditionalSeatsNegativeErrorMessage = "You can't subtract Password Manager seats!";
private readonly ICurrentContext _currentContext;
private readonly IPricingClient _pricingClient;
private readonly IReferenceEventService _referenceEventService;
@ -120,17 +124,17 @@ public class ProviderClientOrganizationSignUpCommand : IProviderClientOrganizati
{
if (plan is null)
{
throw new BadRequestException("Password Manager Plan was null.");
throw new BadRequestException(PlanNullErrorMessage);
}
if (plan.Disabled)
{
throw new BadRequestException("Password Manager Plan is disabled.");
throw new BadRequestException(PlanDisabledErrorMessage);
}
if (additionalSeats < 0)
{
throw new BadRequestException("You can't subtract Password Manager seats!");
throw new BadRequestException(AdditionalSeatsNegativeErrorMessage);
}
}

View File

@ -114,7 +114,7 @@ public class ProviderClientOrganizationSignUpCommandTests
var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.SignUpClientOrganizationAsync(signup));
Assert.Contains("Password Manager Plan was null", exception.Message);
Assert.Contains(ProviderClientOrganizationSignUpCommand.PlanNullErrorMessage, exception.Message);
}
[Theory]
@ -134,7 +134,7 @@ public class ProviderClientOrganizationSignUpCommandTests
var exception = await Assert.ThrowsAsync<BadRequestException>(
() => sutProvider.Sut.SignUpClientOrganizationAsync(signup));
Assert.Contains("You can't subtract Password Manager seats", exception.Message);
Assert.Contains(ProviderClientOrganizationSignUpCommand.AdditionalSeatsNegativeErrorMessage, exception.Message);
}
[Theory]