Skip to content

Commit

Permalink
fix(invitedUsers): filter deleted users for invitedUsers endpoint (#155)
Browse files Browse the repository at this point in the history
Refs: CPLP-2986
Co-authored-by: Norbert Truchsess <[email protected]>
Reviewed-By: Norbert Truchsess <[email protected]>
  • Loading branch information
Phil91 and ntruchsess authored Jul 31, 2023
1 parent c79e50c commit 60c9b3a
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Models;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Entities;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;

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

Expand All @@ -33,19 +34,17 @@ public InvitationRepository(PortalDbContext dbContext)
{
_dbContext = dbContext;
}

public IAsyncEnumerable<InvitedUserDetail> GetInvitedUserDetailsUntrackedAsync(Guid applicationId) =>
(from invitation in _dbContext.Invitations
join invitationStatus in _dbContext.InvitationStatuses on invitation.InvitationStatusId equals invitationStatus.Id
join companyuser in _dbContext.CompanyUsers on invitation.CompanyUserId equals companyuser.Id
where invitation.CompanyApplicationId == applicationId
select new InvitedUserDetail(
companyuser.Identity!.UserEntityId,
invitationStatus.Id,
companyuser.Email
))
.AsNoTracking()
.AsAsyncEnumerable();
_dbContext.Invitations
.AsNoTracking()
.Where(invitation =>
invitation.CompanyApplicationId == applicationId &&
invitation.CompanyUser!.Identity!.UserStatusId != UserStatusId.DELETED)
.Select(invitation => new InvitedUserDetail(
invitation.CompanyUser!.Identity!.UserEntityId,
invitation.InvitationStatusId,
invitation.CompanyUser.Email))
.AsAsyncEnumerable();

public Task<Invitation?> GetInvitationStatusAsync(Guid companyUserId) =>
_dbContext.Invitations
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,46 @@
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Repositories;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.DBAccess.Tests.Setup;
using Org.Eclipse.TractusX.Portal.Backend.PortalBackend.PortalEntities.Enums;
using Xunit.Extensions.AssemblyFixture;

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

public class InvitationRepositoryTests
public class InvitationRepositoryTests : IAssemblyFixture<TestDbFixture>
{
private readonly TestDbFixture _dbTestDbFixture;
private readonly Guid _applicationId = new("6b2d1263-c073-4a48-bfaf-704dc154ca9e");

public InvitationRepositoryTests(TestDbFixture testDbFixture)
{
var 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;
}

[Fact]
public async Task GetInvitedUserDetailsUntrackedAsync_WithValid_ReturnsExpected()
{
var sut = await CreateSut().ConfigureAwait(false);

var result = await sut.GetInvitedUserDetailsUntrackedAsync(_applicationId).ToListAsync().ConfigureAwait(false);

result.Should().HaveCount(2)
.And.Satisfy(
x => x.EmailId == "[email protected]" && x.InvitationStatus == InvitationStatusId.CREATED,
x => x.EmailId == "[email protected]" && x.InvitationStatus == InvitationStatusId.CREATED);
}

#region Setup

private async Task<InvitationRepository> CreateSut()
{
var context = await _dbTestDbFixture.GetPortalDbContext().ConfigureAwait(false);
var sut = new InvitationRepository(context);
return sut;
}

// TODO (PS): GetInvitedUserDetailsUntrackedAsync
#endregion
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,23 @@
"lastlogin": null,
"lastname": "Provider",
"last_editor_id": null
},
{
"id": "d0c8ae19-d4f3-49cc-9cb4-6c766d4680f5",
"date_last_changed": "2022-10-01 18:01:33.570000 +00:00",
"email": "[email protected]",
"firstname": "Test",
"lastlogin": null,
"lastname": "User",
"last_editor_id": null
},
{
"id": "1dceacb8-c5a5-4573-a77d-e2487ac4a8aa",
"date_last_changed": "2022-10-01 18:01:33.570000 +00:00",
"email": "[email protected]",
"firstname": "Deleted",
"lastlogin": null,
"lastname": "User",
"last_editor_id": null
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -102,5 +102,21 @@
"user_status_id": 1,
"user_entity_id": null,
"identity_type_id": 2
},
{
"id": "d0c8ae19-d4f3-49cc-9cb4-6c766d4680f5",
"date_created": "2022-06-01 18:01:33.439000 +00:00",
"company_id": "41fd2ab8-71cd-4546-9bef-a388d91b2542",
"user_status_id": 1,
"user_entity_id": null,
"identity_type_id": 1
},
{
"id": "1dceacb8-c5a5-4573-a77d-e2487ac4a8aa",
"date_created": "2022-06-01 18:01:33.439000 +00:00",
"company_id": "41fd2ab8-71cd-4546-9bef-a388d91b2542",
"user_status_id": 3,
"user_entity_id": null,
"identity_type_id": 1
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,19 @@
"invitation_status_id": 1,
"company_application_id": "6b2d1263-c073-4a48-bfaf-704dc154ca9e",
"company_user_id": "ac1cf001-7fbc-1f2f-817f-bce058019994"
},
{
"id": "d54db875-774c-479f-9f14-375f2cb8b263",
"date_created": "2022-03-24 18:01:33.439000 +00:00",
"invitation_status_id": 1,
"company_application_id": "6b2d1263-c073-4a48-bfaf-704dc154ca9e",
"company_user_id": "d0c8ae19-d4f3-49cc-9cb4-6c766d4680f5"
},
{
"id": "d54db875-774c-479f-9f14-375f2cb8b264",
"date_created": "2022-03-24 18:01:33.439000 +00:00",
"invitation_status_id": 1,
"company_application_id": "6b2d1263-c073-4a48-bfaf-704dc154ca9e",
"company_user_id": "1dceacb8-c5a5-4573-a77d-e2487ac4a8aa"
}
]
]

0 comments on commit 60c9b3a

Please sign in to comment.