Skip to content

Commit

Permalink
fix: adjust query to get users for role assignment
Browse files Browse the repository at this point in the history
Refs: #1134
  • Loading branch information
Phil91 committed Nov 8, 2024
1 parent c12e016 commit f035718
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 16 deletions.
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

0 comments on commit f035718

Please sign in to comment.