Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: adjust query to get users for role assignment #1135

Merged
merged 1 commit into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public IAsyncEnumerable<CompanyInvitedUserData> GetInvitedUsersWithoutInitialRol
.Select(invitation => invitation.CompanyUser)
.Where(companyUser =>
companyUser!.Identity!.UserStatusId == UserStatusId.ACTIVE &&
userRoleIds.Any(x => companyUser.Identity.IdentityAssignedRoles.Select(iar => iar.UserRoleId).Contains(x)))
userRoleIds.Any(x => !companyUser.Identity.IdentityAssignedRoles.Any(iar => iar.UserRoleId == x)))
.Select(companyUser => new CompanyInvitedUserData(
companyUser!.Id,
companyUser.Identity!.IdentityAssignedRoles.Select(companyUserAssignedRole => companyUserAssignedRole.UserRoleId)))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,23 +28,12 @@

namespace Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Tests;

public class ApplicationRepositoryTests : IAssemblyFixture<TestDbFixture>
public class ApplicationRepositoryTests(TestDbFixture testDbFixture)
: IAssemblyFixture<TestDbFixture>
{
private static readonly Guid SubmittedApplicationWithBpn = new("6b2d1263-c073-4a48-bfaf-704dc154ca9f");
private static readonly Guid ApplicationWithoutBpn = new("4829b64c-de6a-426c-81fc-c0bcf95bcb76");
private static readonly Guid CompanyId = new("2dc4249f-b5ca-4d42-bef1-7a7a950a4f88");
private readonly IFixture _fixture;
private readonly TestDbFixture _dbTestDbFixture;

public ApplicationRepositoryTests(TestDbFixture testDbFixture)
{
_fixture = new Fixture().Customize(new AutoFakeItEasyCustomization { ConfigureMembers = true });
_fixture.Behaviors.OfType<ThrowingRecursionBehavior>().ToList()
.ForEach(b => _fixture.Behaviors.Remove(b));

_fixture.Behaviors.Add(new OmitOnRecursionBehavior());
_dbTestDbFixture = testDbFixture;
}

#region GetCompanyUserRoleWithAddressUntrackedAsync

Expand Down Expand Up @@ -662,15 +651,55 @@ public async Task GetDeclineApplicationForApplicationId_WithInvalidCompanyId_Ret

#endregion

#region GetInvitedUsersWithoutInitialRoles

[Fact]
public async Task GetInvitedUsersWithoutInitialRoles_WithAllRoles_ReturnsEmpty()
{
// Arrange
var userRoles = new[]
{
new Guid("58f897ec-0aad-4588-8ffa-5f45d6638632"),
new Guid("efc20368-9e82-46ff-b88f-6495b9810253"),
new Guid("aabcdfeb-6669-4c74-89f0-19cda090873f")
};
var sut = await CreateSut().ConfigureAwait(false);

// Act
var result = await sut.GetInvitedUsersWithoutInitialRoles(SubmittedApplicationWithBpn, userRoles).ToListAsync().ConfigureAwait(false);

// Assert
result.Should().BeEmpty();
}

[Fact]
public async Task GetInvitedUsersWithoutInitialRoles_WithNotExistingRole_ReturnsExpected()
{
// Arrange
var userRoleId = Guid.NewGuid();
var sut = await CreateSut().ConfigureAwait(false);

// Act
var result = await sut.GetInvitedUsersWithoutInitialRoles(SubmittedApplicationWithBpn, new[] { userRoleId }).ToListAsync().ConfigureAwait(false);

// Assert
result.Should().ContainSingle().And.Satisfy(x =>
x.CompanyUserId == new Guid("ac1cf001-7fbc-1f2f-817f-bce058020001") &&
x.RoleIds.Count() == 3);
}

#endregion

private async Task<(IApplicationRepository sut, PortalDbContext context)> CreateSutWithContext()
{
var context = await _dbTestDbFixture.GetPortalDbContext();
var context = await testDbFixture.GetPortalDbContext();
var sut = new ApplicationRepository(context);
return (sut, context);
}

private async Task<IApplicationRepository> CreateSut()
{
var context = await _dbTestDbFixture.GetPortalDbContext();
var context = await testDbFixture.GetPortalDbContext();
var sut = new ApplicationRepository(context);
return sut;
}
Expand Down
Loading