From a3bbcbbbfd6e7420f357c860db7808135b723d92 Mon Sep 17 00:00:00 2001 From: AnuragNagpure <145100366+AnuragNagpure@users.noreply.github.com> Date: Mon, 23 Sep 2024 22:31:22 +0530 Subject: [PATCH] feat(technicaluser): add usertype to get service account data (#1028) Refs: #976 Reviewed-by: Phil Schneider Co-authored-by: Phil Schneider --- .../Models/CompanyServiceAccountData.cs | 1 + .../Repositories/ServiceAccountRepository.cs | 1 + .../ServiceAccountBusinessLogicTests.cs | 20 ++++++++++++++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/portalbackend/PortalBackend.DBAccess/Models/CompanyServiceAccountData.cs b/src/portalbackend/PortalBackend.DBAccess/Models/CompanyServiceAccountData.cs index b02924c9db..a12cb3cb9d 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Models/CompanyServiceAccountData.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Models/CompanyServiceAccountData.cs @@ -27,6 +27,7 @@ public record CompanyServiceAccountData( [property: JsonPropertyName("serviceAccountId")] Guid ServiceAccountId, [property: JsonPropertyName("clientId")] string? ClientId, [property: JsonPropertyName("name")] string Name, + [property: JsonPropertyName("userType")] CompanyServiceAccountKindId CompanyServiceAccountKindId, [property: JsonPropertyName("serviceAccountType")] CompanyServiceAccountTypeId CompanyServiceAccountTypeId, [property: JsonPropertyName("status")] UserStatusId UserStatusId, [property: JsonPropertyName("isOwner")] bool IsOwner, diff --git a/src/portalbackend/PortalBackend.DBAccess/Repositories/ServiceAccountRepository.cs b/src/portalbackend/PortalBackend.DBAccess/Repositories/ServiceAccountRepository.cs index c4efb0c00a..9458d35cf4 100644 --- a/src/portalbackend/PortalBackend.DBAccess/Repositories/ServiceAccountRepository.cs +++ b/src/portalbackend/PortalBackend.DBAccess/Repositories/ServiceAccountRepository.cs @@ -199,6 +199,7 @@ public void AttachAndModifyCompanyServiceAccount( x.ServiceAccount.Id, x.ServiceAccount.ClientClientId, x.ServiceAccount.Name, + x.ServiceAccount.CompanyServiceAccountKindId, x.ServiceAccount.CompanyServiceAccountTypeId, x.ServiceAccount.Identity!.UserStatusId, x.IsOwner, diff --git a/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs b/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs index bb34aefffd..2685551322 100644 --- a/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs +++ b/tests/administration/Administration.Service.Tests/BusinessLogic/ServiceAccountBusinessLogicTests.cs @@ -490,7 +490,17 @@ public async Task UpdateOwnCompanyServiceAccountDetailsAsync_WithExternalService public async Task GetOwnCompanyServiceAccountsDataAsync_GetsExpectedData(IEnumerable? userStatusIds, bool isUserInactive, IEnumerable expectedStatusIds) { // Arrange - var data = _fixture.CreateMany(15); + var count = 0; + var data = _fixture + .Build() + .With(x => x.CompanyServiceAccountKindId, (IFixture _) => + { + var kind = count % 2 == 0 ? CompanyServiceAccountKindId.INTERNAL + : CompanyServiceAccountKindId.EXTERNAL; + count++; + return kind; + }) + .CreateMany(15); A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountsUntracked(A._, A._, A._, A>._)) .Returns((int skip, int take) => Task.FromResult?>(new(data.Count(), data.Skip(skip).Take(take)))); @@ -503,6 +513,14 @@ public async Task GetOwnCompanyServiceAccountsDataAsync_GetsExpectedData(IEnumer // Assert result.Should().NotBeNull(); result.Content.Should().HaveCount(5); + result.Content + .Where(x => x.CompanyServiceAccountKindId == CompanyServiceAccountKindId.INTERNAL) + .Should() + .HaveCount(3); + result.Content + .Where(x => x.CompanyServiceAccountKindId == CompanyServiceAccountKindId.EXTERNAL) + .Should() + .HaveCount(2); A.CallTo(() => _serviceAccountRepository.GetOwnCompanyServiceAccountsUntracked(ValidCompanyId, null, null, A>.That.IsSameSequenceAs(expectedStatusIds))) .MustHaveHappenedOnceExactly(); }