mirror of
https://github.com/bitwarden/server.git
synced 2024-12-05 14:23:30 +01:00
3c86ec6a35
* Refactor: Rename some methods and models for consistency This commit contains no logic changes at all. It's entirely comprised of renames of existing models and methods to bring our codebase more in line with our app's functionality and terminology. * Add feature flag: AC-2476-deprecate-stripe-sources-api * Standardize error responses from applicable billing controllers During my work on CB, I found that just using the built-in TypedResults errors results in the client choking on the response because it's looking for the ErrroResponseModel. The new BaseBillingController provides Error utilities to return TypedResults wrapping that model so the client can process it. * Add feature flagged payment method endoints to OrganizationBillingController * Run dotnet format
71 lines
2.2 KiB
C#
71 lines
2.2 KiB
C#
using Bit.Api.Billing.Controllers;
|
|
using Bit.Core;
|
|
using Bit.Core.AdminConsole.Entities.Provider;
|
|
using Bit.Core.AdminConsole.Enums.Provider;
|
|
using Bit.Core.AdminConsole.Repositories;
|
|
using Bit.Core.Context;
|
|
using Bit.Core.Models.Api;
|
|
using Bit.Core.Services;
|
|
using Bit.Test.Common.AutoFixture;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Http.HttpResults;
|
|
using NSubstitute;
|
|
using Xunit;
|
|
|
|
namespace Bit.Api.Test.Billing;
|
|
|
|
public static class Utilities
|
|
{
|
|
public static void AssertNotFound(IResult result)
|
|
{
|
|
Assert.IsType<NotFound<ErrorResponseModel>>(result);
|
|
|
|
var response = ((NotFound<ErrorResponseModel>)result).Value;
|
|
|
|
Assert.Equal("Resource not found.", response.Message);
|
|
}
|
|
|
|
public static void AssertUnauthorized(IResult result)
|
|
{
|
|
Assert.IsType<JsonHttpResult<ErrorResponseModel>>(result);
|
|
|
|
var response = (JsonHttpResult<ErrorResponseModel>)result;
|
|
|
|
Assert.Equal(StatusCodes.Status401Unauthorized, response.StatusCode);
|
|
Assert.Equal("Unauthorized.", response.Value.Message);
|
|
}
|
|
|
|
public static void ConfigureStableProviderAdminInputs<T>(
|
|
Provider provider,
|
|
SutProvider<T> sutProvider) where T : BaseProviderController
|
|
{
|
|
ConfigureBaseProviderInputs(provider, sutProvider);
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().ProviderProviderAdmin(provider.Id)
|
|
.Returns(true);
|
|
}
|
|
|
|
public static void ConfigureStableProviderServiceUserInputs<T>(
|
|
Provider provider,
|
|
SutProvider<T> sutProvider) where T : BaseProviderController
|
|
{
|
|
ConfigureBaseProviderInputs(provider, sutProvider);
|
|
|
|
sutProvider.GetDependency<ICurrentContext>().ProviderUser(provider.Id)
|
|
.Returns(true);
|
|
}
|
|
|
|
private static void ConfigureBaseProviderInputs<T>(
|
|
Provider provider,
|
|
SutProvider<T> sutProvider) where T : BaseProviderController
|
|
{
|
|
sutProvider.GetDependency<IFeatureService>().IsEnabled(FeatureFlagKeys.EnableConsolidatedBilling)
|
|
.Returns(true);
|
|
|
|
provider.Type = ProviderType.Msp;
|
|
provider.Status = ProviderStatusType.Billable;
|
|
|
|
sutProvider.GetDependency<IProviderRepository>().GetByIdAsync(provider.Id).Returns(provider);
|
|
}
|
|
}
|