mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 15:42:48 -05:00
Turn on file scoped namespaces (#2225)
This commit is contained in:
@ -10,73 +10,72 @@ using Microsoft.Extensions.Options;
|
||||
using NSubstitute;
|
||||
using Xunit;
|
||||
|
||||
namespace Bit.Billing.Test.Controllers
|
||||
namespace Bit.Billing.Test.Controllers;
|
||||
|
||||
public class FreshsalesControllerTests
|
||||
{
|
||||
public class FreshsalesControllerTests
|
||||
private const string ApiKey = "TEST_FRESHSALES_APIKEY";
|
||||
private const string TestLead = "TEST_FRESHSALES_TESTLEAD";
|
||||
|
||||
private static (FreshsalesController, IUserRepository, IOrganizationRepository) CreateSut(
|
||||
string freshsalesApiKey)
|
||||
{
|
||||
private const string ApiKey = "TEST_FRESHSALES_APIKEY";
|
||||
private const string TestLead = "TEST_FRESHSALES_TESTLEAD";
|
||||
var userRepository = Substitute.For<IUserRepository>();
|
||||
var organizationRepository = Substitute.For<IOrganizationRepository>();
|
||||
|
||||
private static (FreshsalesController, IUserRepository, IOrganizationRepository) CreateSut(
|
||||
string freshsalesApiKey)
|
||||
var billingSettings = Options.Create(new BillingSettings
|
||||
{
|
||||
var userRepository = Substitute.For<IUserRepository>();
|
||||
var organizationRepository = Substitute.For<IOrganizationRepository>();
|
||||
FreshsalesApiKey = freshsalesApiKey,
|
||||
});
|
||||
var globalSettings = new GlobalSettings();
|
||||
globalSettings.BaseServiceUri.Admin = "https://test.com";
|
||||
|
||||
var billingSettings = Options.Create(new BillingSettings
|
||||
{
|
||||
FreshsalesApiKey = freshsalesApiKey,
|
||||
});
|
||||
var globalSettings = new GlobalSettings();
|
||||
globalSettings.BaseServiceUri.Admin = "https://test.com";
|
||||
var sut = new FreshsalesController(
|
||||
userRepository,
|
||||
organizationRepository,
|
||||
billingSettings,
|
||||
Substitute.For<ILogger<FreshsalesController>>(),
|
||||
globalSettings
|
||||
);
|
||||
|
||||
var sut = new FreshsalesController(
|
||||
userRepository,
|
||||
organizationRepository,
|
||||
billingSettings,
|
||||
Substitute.For<ILogger<FreshsalesController>>(),
|
||||
globalSettings
|
||||
);
|
||||
return (sut, userRepository, organizationRepository);
|
||||
}
|
||||
|
||||
return (sut, userRepository, organizationRepository);
|
||||
}
|
||||
[RequiredEnvironmentTheory(ApiKey, TestLead), EnvironmentData(ApiKey, TestLead)]
|
||||
public async Task PostWebhook_Success(string freshsalesApiKey, long leadId)
|
||||
{
|
||||
// This test is only for development to use:
|
||||
// `export TEST_FRESHSALES_APIKEY=[apikey]`
|
||||
// `export TEST_FRESHSALES_TESTLEAD=[lead id]`
|
||||
// `dotnet test --filter "FullyQualifiedName~FreshsalesControllerTests.PostWebhook_Success"`
|
||||
var (sut, userRepository, organizationRepository) = CreateSut(freshsalesApiKey);
|
||||
|
||||
[RequiredEnvironmentTheory(ApiKey, TestLead), EnvironmentData(ApiKey, TestLead)]
|
||||
public async Task PostWebhook_Success(string freshsalesApiKey, long leadId)
|
||||
var user = new User
|
||||
{
|
||||
// This test is only for development to use:
|
||||
// `export TEST_FRESHSALES_APIKEY=[apikey]`
|
||||
// `export TEST_FRESHSALES_TESTLEAD=[lead id]`
|
||||
// `dotnet test --filter "FullyQualifiedName~FreshsalesControllerTests.PostWebhook_Success"`
|
||||
var (sut, userRepository, organizationRepository) = CreateSut(freshsalesApiKey);
|
||||
Id = Guid.NewGuid(),
|
||||
Email = "test@email.com",
|
||||
Premium = true,
|
||||
};
|
||||
|
||||
var user = new User
|
||||
userRepository.GetByEmailAsync(user.Email)
|
||||
.Returns(user);
|
||||
|
||||
organizationRepository.GetManyByUserIdAsync(user.Id)
|
||||
.Returns(new List<Organization>
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Email = "test@email.com",
|
||||
Premium = true,
|
||||
};
|
||||
|
||||
userRepository.GetByEmailAsync(user.Email)
|
||||
.Returns(user);
|
||||
|
||||
organizationRepository.GetManyByUserIdAsync(user.Id)
|
||||
.Returns(new List<Organization>
|
||||
new Organization
|
||||
{
|
||||
new Organization
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
Name = "Test Org",
|
||||
}
|
||||
});
|
||||
Id = Guid.NewGuid(),
|
||||
Name = "Test Org",
|
||||
}
|
||||
});
|
||||
|
||||
var response = await sut.PostWebhook(freshsalesApiKey, new CustomWebhookRequestModel
|
||||
{
|
||||
LeadId = leadId,
|
||||
}, new CancellationToken(false));
|
||||
var response = await sut.PostWebhook(freshsalesApiKey, new CustomWebhookRequestModel
|
||||
{
|
||||
LeadId = leadId,
|
||||
}, new CancellationToken(false));
|
||||
|
||||
var statusCodeResult = Assert.IsAssignableFrom<StatusCodeResult>(response);
|
||||
Assert.Equal(StatusCodes.Status204NoContent, statusCodeResult.StatusCode);
|
||||
}
|
||||
var statusCodeResult = Assert.IsAssignableFrom<StatusCodeResult>(response);
|
||||
Assert.Equal(StatusCodes.Status204NoContent, statusCodeResult.StatusCode);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user