mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 07:36:14 -05:00
PM-15066 added drop feature and unit tests. (#5053)
This commit is contained in:
@ -1,7 +1,9 @@
|
||||
using Bit.Api.Tools.Controllers;
|
||||
using AutoFixture;
|
||||
using Bit.Api.Tools.Controllers;
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Tools.ReportFeatures.Interfaces;
|
||||
using Bit.Core.Tools.ReportFeatures.Requests;
|
||||
using Bit.Test.Common.AutoFixture;
|
||||
using Bit.Test.Common.AutoFixture.Attributes;
|
||||
using NSubstitute;
|
||||
@ -45,5 +47,98 @@ public class ReportsControllerTests
|
||||
.Received(0);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task AddPasswordHealthReportApplicationAsync_withAccess_success(SutProvider<ReportsController> sutProvider)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<ICurrentContext>().AccessReports(Arg.Any<Guid>()).Returns(true);
|
||||
|
||||
// Act
|
||||
var request = new Api.Tools.Models.PasswordHealthReportApplicationModel
|
||||
{
|
||||
OrganizationId = Guid.NewGuid(),
|
||||
Url = "https://example.com",
|
||||
};
|
||||
await sutProvider.Sut.AddPasswordHealthReportApplication(request);
|
||||
|
||||
// Assert
|
||||
_ = sutProvider.GetDependency<IAddPasswordHealthReportApplicationCommand>()
|
||||
.Received(1)
|
||||
.AddPasswordHealthReportApplicationAsync(Arg.Is<AddPasswordHealthReportApplicationRequest>(_ =>
|
||||
_.OrganizationId == request.OrganizationId && _.Url == request.Url));
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task AddPasswordHealthReportApplicationAsync_multiple_withAccess_success(
|
||||
SutProvider<ReportsController> sutProvider)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<ICurrentContext>().AccessReports(Arg.Any<Guid>()).Returns(true);
|
||||
|
||||
// Act
|
||||
var fixture = new Fixture();
|
||||
var request = fixture.CreateMany<Api.Tools.Models.PasswordHealthReportApplicationModel>(2);
|
||||
await sutProvider.Sut.AddPasswordHealthReportApplications(request);
|
||||
|
||||
// Assert
|
||||
_ = sutProvider.GetDependency<IAddPasswordHealthReportApplicationCommand>()
|
||||
.Received(1)
|
||||
.AddPasswordHealthReportApplicationAsync(Arg.Any<IEnumerable<AddPasswordHealthReportApplicationRequest>>());
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task AddPasswordHealthReportApplicationAsync_withoutAccess(SutProvider<ReportsController> sutProvider)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<ICurrentContext>().AccessReports(Arg.Any<Guid>()).Returns(false);
|
||||
|
||||
// Act
|
||||
var request = new Api.Tools.Models.PasswordHealthReportApplicationModel
|
||||
{
|
||||
OrganizationId = Guid.NewGuid(),
|
||||
Url = "https://example.com",
|
||||
};
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () =>
|
||||
await sutProvider.Sut.AddPasswordHealthReportApplication(request));
|
||||
|
||||
// Assert
|
||||
_ = sutProvider.GetDependency<IAddPasswordHealthReportApplicationCommand>()
|
||||
.Received(0);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task DropPasswordHealthReportApplicationAsync_withoutAccess(SutProvider<ReportsController> sutProvider)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<ICurrentContext>().AccessReports(Arg.Any<Guid>()).Returns(false);
|
||||
|
||||
// Act
|
||||
var fixture = new Fixture();
|
||||
var request = fixture.Create<Api.Tools.Models.PasswordHealthReportApplicationModel>();
|
||||
await Assert.ThrowsAsync<NotFoundException>(async () =>
|
||||
await sutProvider.Sut.AddPasswordHealthReportApplication(request));
|
||||
|
||||
// Assert
|
||||
_ = sutProvider.GetDependency<IDropPasswordHealthReportApplicationCommand>()
|
||||
.Received(0);
|
||||
}
|
||||
|
||||
[Theory, BitAutoData]
|
||||
public async Task DropPasswordHealthReportApplicationAsync_withAccess_success(SutProvider<ReportsController> sutProvider)
|
||||
{
|
||||
// Arrange
|
||||
sutProvider.GetDependency<ICurrentContext>().AccessReports(Arg.Any<Guid>()).Returns(true);
|
||||
|
||||
// Act
|
||||
var fixture = new Fixture();
|
||||
var request = fixture.Create<DropPasswordHealthReportApplicationRequest>();
|
||||
await sutProvider.Sut.DropPasswordHealthReportApplication(request);
|
||||
|
||||
// Assert
|
||||
_ = sutProvider.GetDependency<IDropPasswordHealthReportApplicationCommand>()
|
||||
.Received(1)
|
||||
.DropPasswordHealthReportApplicationAsync(Arg.Is<DropPasswordHealthReportApplicationRequest>(_ =>
|
||||
_.OrganizationId == request.OrganizationId &&
|
||||
_.PasswordHealthReportApplicationIds == request.PasswordHealthReportApplicationIds));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user