diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/InvitationRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/InvitationRepository.cs index 547f5a39be..1a435a024c 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/InvitationRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/InvitationRepository.cs @@ -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; @@ -33,19 +34,17 @@ public InvitationRepository(PortalDbContext dbContext) { _dbContext = dbContext; } - public IAsyncEnumerable 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 GetInvitationStatusAsync(Guid companyUserId) => _dbContext.Invitations diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/InvitationRepositoryTests.cs b/tests/portalbackend/PortalBackend.DBAccess.Tests/InvitationRepositoryTests.cs index fc9c5f8749..a060ad8650 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/InvitationRepositoryTests.cs +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/InvitationRepositoryTests.cs @@ -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 { + 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().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 == "test@user.com" && x.InvitationStatus == InvitationStatusId.CREATED, + x => x.EmailId == "company.admin1@acme.corp" && x.InvitationStatus == InvitationStatusId.CREATED); + } + + #region Setup + + private async Task CreateSut() + { + var context = await _dbTestDbFixture.GetPortalDbContext().ConfigureAwait(false); + var sut = new InvitationRepository(context); + return sut; + } - // TODO (PS): GetInvitedUserDetailsUntrackedAsync + #endregion } diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/company_users.test.json b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/company_users.test.json index 397cb5899b..b2802a1af8 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/company_users.test.json +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/company_users.test.json @@ -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": "test@user.com", + "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": "test@user.com", + "firstname": "Deleted", + "lastlogin": null, + "lastname": "User", + "last_editor_id": null } ] diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/identities.test.json b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/identities.test.json index da9cd1c656..c491aa8f2b 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/identities.test.json +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/identities.test.json @@ -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 } ] diff --git a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/invitations.test.json b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/invitations.test.json index 9f8131d0fc..c0e1e7fd58 100644 --- a/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/invitations.test.json +++ b/tests/portalbackend/PortalBackend.DBAccess.Tests/Seeder/Data/invitations.test.json @@ -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" } -] \ No newline at end of file +]