1
0
mirror of https://github.com/bitwarden/server.git synced 2025-06-30 23:52:50 -05:00

[AC-1200] Admin Console code ownership - move OrganizationFeatures (#3369)

This commit is contained in:
Thomas Rittson
2023-10-27 07:47:44 +10:00
committed by GitHub
parent 26dd8b0e47
commit ad230fb6a5
66 changed files with 151 additions and 152 deletions

View File

@ -0,0 +1,26 @@
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationConnections;
using Bit.Core.Models.Data.Organizations.OrganizationConnections;
using Bit.Core.Models.OrganizationConnectionConfigs;
using Bit.Core.Repositories;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using Bit.Test.Common.Helpers;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationConnections;
[SutProviderCustomize]
public class CreateOrganizationConnectionCommandTests
{
[Theory]
[BitAutoData]
public async Task CreateAsync_CallsCreate(OrganizationConnectionData<BillingSyncConfig> data,
SutProvider<CreateOrganizationConnectionCommand> sutProvider)
{
await sutProvider.Sut.CreateAsync(data);
await sutProvider.GetDependency<IOrganizationConnectionRepository>().Received(1)
.CreateAsync(Arg.Is(AssertHelper.AssertPropertyEqual(data.ToEntity())));
}
}

View File

@ -0,0 +1,24 @@
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationConnections;
using Bit.Core.Entities;
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.OrganizationConnections;
[SutProviderCustomize]
public class DeleteOrganizationConnectionCommandTests
{
[Theory]
[BitAutoData]
public async Task DeleteAsync_CallsDelete(OrganizationConnection connection,
SutProvider<DeleteOrganizationConnectionCommand> sutProvider)
{
await sutProvider.Sut.DeleteAsync(connection);
await sutProvider.GetDependency<IOrganizationConnectionRepository>().Received(1)
.DeleteAsync(connection);
}
}

View File

@ -0,0 +1,58 @@
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationConnections;
using Bit.Core.Entities;
using Bit.Core.Exceptions;
using Bit.Core.Models.Data.Organizations.OrganizationConnections;
using Bit.Core.Models.OrganizationConnectionConfigs;
using Bit.Core.Repositories;
using Bit.Test.Common.AutoFixture;
using Bit.Test.Common.AutoFixture.Attributes;
using Bit.Test.Common.Helpers;
using NSubstitute;
using Xunit;
namespace Bit.Core.Test.AdminConsole.OrganizationFeatures.OrganizationConnections;
[SutProviderCustomize]
public class UpdateOrganizationConnectionCommandTests
{
[Theory]
[BitAutoData]
public async Task UpdateAsync_NoId_Fails(OrganizationConnectionData<BillingSyncConfig> data,
SutProvider<UpdateOrganizationConnectionCommand> sutProvider)
{
data.Id = null;
var exception = await Assert.ThrowsAsync<Exception>(() => sutProvider.Sut.UpdateAsync(data));
Assert.Contains("Cannot update connection, Connection does not exist.", exception.Message);
await sutProvider.GetDependency<IOrganizationConnectionRepository>().DidNotReceiveWithAnyArgs()
.UpsertAsync(default);
}
[Theory]
[BitAutoData]
public async Task UpdateAsync_ConnectionDoesNotExist_ThrowsNotFound(
OrganizationConnectionData<BillingSyncConfig> data,
SutProvider<UpdateOrganizationConnectionCommand> sutProvider)
{
var exception = await Assert.ThrowsAsync<NotFoundException>(() => sutProvider.Sut.UpdateAsync(data));
await sutProvider.GetDependency<IOrganizationConnectionRepository>().DidNotReceiveWithAnyArgs()
.UpsertAsync(default);
}
[Theory]
[BitAutoData]
public async Task UpdateAsync_CallsUpsert(OrganizationConnectionData<BillingSyncConfig> data,
OrganizationConnection existing,
SutProvider<UpdateOrganizationConnectionCommand> sutProvider)
{
data.Id = existing.Id;
sutProvider.GetDependency<IOrganizationConnectionRepository>().GetByIdAsync(data.Id.Value).Returns(existing);
await sutProvider.Sut.UpdateAsync(data);
await sutProvider.GetDependency<IOrganizationConnectionRepository>().Received(1)
.UpsertAsync(Arg.Is(AssertHelper.AssertPropertyEqual(data.ToEntity())));
}
}

View File

@ -0,0 +1,57 @@
using Bit.Core.AdminConsole.OrganizationFeatures.OrganizationConnections;
using Bit.Core.Entities;
using Bit.Core.Enums;
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.OrganizationConnections;
[SutProviderCustomize]
public class ValidateBillingSyncKeyCommandTests
{
[Theory]
[BitAutoData]
public async Task ValidateBillingSyncKeyAsync_NullOrganization_Throws(SutProvider<ValidateBillingSyncKeyCommand> sutProvider)
{
await Assert.ThrowsAsync<BadRequestException>(() => sutProvider.Sut.ValidateBillingSyncKeyAsync(null, null));
}
[Theory]
[BitAutoData((string)null)]
[BitAutoData("")]
[BitAutoData(" ")]
public async Task ValidateBillingSyncKeyAsync_BadString_ReturnsFalse(string billingSyncKey, SutProvider<ValidateBillingSyncKeyCommand> sutProvider)
{
Assert.False(await sutProvider.Sut.ValidateBillingSyncKeyAsync(new Organization(), billingSyncKey));
}
[Theory]
[BitAutoData]
public async Task ValidateBillingSyncKeyAsync_KeyEquals_ReturnsTrue(SutProvider<ValidateBillingSyncKeyCommand> sutProvider,
Organization organization, OrganizationApiKey orgApiKey, string billingSyncKey)
{
orgApiKey.ApiKey = billingSyncKey;
sutProvider.GetDependency<IOrganizationApiKeyRepository>()
.GetManyByOrganizationIdTypeAsync(organization.Id, OrganizationApiKeyType.BillingSync)
.Returns(new[] { orgApiKey });
Assert.True(await sutProvider.Sut.ValidateBillingSyncKeyAsync(organization, billingSyncKey));
}
[Theory]
[BitAutoData]
public async Task ValidateBillingSyncKeyAsync_KeyDoesNotEqual_ReturnsFalse(SutProvider<ValidateBillingSyncKeyCommand> sutProvider,
Organization organization, OrganizationApiKey orgApiKey, string billingSyncKey)
{
sutProvider.GetDependency<IOrganizationApiKeyRepository>()
.GetManyByOrganizationIdTypeAsync(organization.Id, OrganizationApiKeyType.BillingSync)
.Returns(new[] { orgApiKey });
Assert.False(await sutProvider.Sut.ValidateBillingSyncKeyAsync(organization, billingSyncKey));
}
}