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(invitedUsers): filter deleted users for invitedUsers endpoint #155

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 @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest:

    public IAsyncEnumerable<InvitedUserDetail> GetInvitedUserDetailsUntrackedAsync(Guid applicationId) =>
        _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();

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

adjusted

.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

This file was deleted.

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"
}
]
]
Loading