-
Notifications
You must be signed in to change notification settings - Fork 1
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
Appman 1408 user overview #1947
Open
ogrwill
wants to merge
7
commits into
APPMAN-1409-account-details
Choose a base branch
from
APPMAN-1408-user-overview
base: APPMAN-1409-account-details
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
296460c
adding GetUserSummary for user overview
f63dac5
renaming to GetUserOverview
b52bbae
unit tests
28091ff
Merge remote-tracking branch 'origin/APPMAN-1409-account-details' int…
379ff75
tidy
2c80396
adding response object returning from apim controller
11b3e60
Merge remote-tracking branch 'origin/APPMAN-1409-account-details' int…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...port/SFA.DAS.ToolsSupport.Api.UnitTests/Controllers/UsersQuery/WhenGettingUserOverview.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using MediatR; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Moq; | ||
using NUnit.Framework; | ||
using SFA.DAS.Testing.AutoFixture; | ||
using SFA.DAS.ToolsSupport.Api.Controllers; | ||
using SFA.DAS.ToolsSupport.Application.Queries.GetUserOverview; | ||
|
||
namespace SFA.DAS.ToolsSupport.Api.UnitTests.Controllers.UsersQuery; | ||
|
||
public class WhenGettingUserOverview | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task Then_Gets_Account_Details_From_Mediator( | ||
Guid userId, | ||
GetUserOverviewQueryResult getOverviewResult, | ||
[Frozen] Mock<IMediator> mockMediator, | ||
[Greedy] UsersQueryController controller) | ||
{ | ||
mockMediator | ||
.Setup(mediator => mediator.Send( | ||
It.Is<GetUserOverviewQuery>(x => | ||
x.UserId == userId), | ||
It.IsAny<CancellationToken>())) | ||
.ReturnsAsync(getOverviewResult); | ||
|
||
var controllerResult = await controller.GetUserOverview(userId) as ObjectResult; | ||
|
||
controllerResult.Should().NotBeNull(); | ||
var model = controllerResult.Value as GetUserOverviewQueryResult; | ||
|
||
model.Should().NotBeNull(); | ||
model.Id.Should().Be(getOverviewResult.Id); | ||
model.FirstName.Should().Be(getOverviewResult.FirstName); | ||
model.LastName.Should().Be(getOverviewResult.LastName); | ||
model.Email.Should().Be(getOverviewResult.Email); | ||
model.IsActive.Should().Be(getOverviewResult.IsActive); | ||
model.IsLocked.Should().Be(getOverviewResult.IsLocked); | ||
model.IsSuspended.Should().Be(getOverviewResult.IsSuspended); | ||
model.AccountSummaries.Should().BeEquivalentTo(getOverviewResult.AccountSummaries); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...rt/SFA.DAS.ToolsSupport.UnitTests/Application/Queries/GetUserOverviewQueryHandlerTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using AutoFixture.NUnit3; | ||
using FluentAssertions; | ||
using Moq; | ||
using SFA.DAS.SharedOuterApi.Configuration; | ||
using SFA.DAS.SharedOuterApi.Interfaces; | ||
using SFA.DAS.Testing.AutoFixture; | ||
using SFA.DAS.ToolsSupport.Application.Queries.GetUserOverview; | ||
using SFA.DAS.ToolsSupport.InnerApi.Requests; | ||
using SFA.DAS.ToolsSupport.InnerApi.Responses; | ||
using SFA.DAS.ToolsSupport.Interfaces; | ||
|
||
namespace SFA.DAS.ToolsSupport.UnitTests.Application.Queries; | ||
|
||
public class GetUserOverviewQueryHandlerTests | ||
{ | ||
[Test, MoqAutoData] | ||
public async Task Then_GetLatestDetails_from_Reference_Api( | ||
GetUserOverviewQuery query, | ||
GetUserOverviewResponse userApiResponse, | ||
List<Account> userAccounts, | ||
[Frozen] Mock<IAccountsService> accountsService, | ||
[Frozen] Mock<IInternalApiClient<EmployerProfilesApiConfiguration>> employerProfilesApi, | ||
GetUserOverviewQueryHandler handler) | ||
{ | ||
accountsService.Setup(x => x.GetUserAccounts(query.UserId)).ReturnsAsync(userAccounts); | ||
|
||
var expectedUrl = $"api/users/{query.UserId}"; | ||
|
||
employerProfilesApi.Setup(x => x.Get<GetUserOverviewResponse>(It.Is<GetUserByIdRequest>(r => r.GetUrl == expectedUrl))) | ||
.ReturnsAsync(userApiResponse); | ||
|
||
var result = await handler.Handle(query, CancellationToken.None); | ||
|
||
result.Should().NotBeNull(); | ||
result.Id.Should().Be(userApiResponse.Id); | ||
result.FirstName.Should().Be(userApiResponse.FirstName); | ||
result.LastName.Should().Be(userApiResponse.LastName); | ||
result.Email.Should().Be(userApiResponse.Email); | ||
result.IsActive.Should().Be(userApiResponse.IsActive); | ||
result.IsLocked.Should().Be(userApiResponse.IsLocked); | ||
result.IsSuspended.Should().Be(userApiResponse.IsSuspended); | ||
|
||
result.AccountSummaries.Should().NotBeNull(); | ||
result.AccountSummaries.First().DasAccountName.Should().Be(userAccounts.First().DasAccountName); | ||
result.AccountSummaries.First().HashedAccountId.Should().Be(userAccounts.First().HashedAccountId); | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
...sSupport/SFA.DAS.ToolsSupport/Application/Queries/GetUserOverview/GetUserOverviewQuery.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using MediatR; | ||
|
||
namespace SFA.DAS.ToolsSupport.Application.Queries.GetUserOverview; | ||
|
||
public class GetUserOverviewQuery : IRequest<GetUserOverviewQueryResult> | ||
{ | ||
public Guid UserId { get; set; } | ||
} |
47 changes: 47 additions & 0 deletions
47
...t/SFA.DAS.ToolsSupport/Application/Queries/GetUserOverview/GetUserOverviewQueryHandler.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
using MediatR; | ||
using SFA.DAS.SharedOuterApi.Configuration; | ||
using SFA.DAS.SharedOuterApi.Interfaces; | ||
using SFA.DAS.ToolsSupport.InnerApi.Requests; | ||
using SFA.DAS.ToolsSupport.InnerApi.Responses; | ||
using SFA.DAS.ToolsSupport.Interfaces; | ||
|
||
namespace SFA.DAS.ToolsSupport.Application.Queries.GetUserOverview; | ||
|
||
public class GetUserOverviewQueryHandler( | ||
IInternalApiClient<EmployerProfilesApiConfiguration> client, | ||
IAccountsService accountsService | ||
) : IRequestHandler<GetUserOverviewQuery, GetUserOverviewQueryResult> | ||
{ | ||
public async Task<GetUserOverviewQueryResult> Handle(GetUserOverviewQuery query, CancellationToken cancellationToken) | ||
{ | ||
var accountsTask = accountsService.GetUserAccounts(query.UserId); | ||
|
||
var userResponseTask = client.Get<GetUserOverviewResponse>(new GetUserByIdRequest(query.UserId)); | ||
|
||
await Task.WhenAll(accountsTask, userResponseTask); | ||
|
||
var accounts = await accountsTask; | ||
var userResponse = await userResponseTask; | ||
if (userResponse == null) | ||
{ | ||
return new GetUserOverviewQueryResult(); | ||
} | ||
|
||
return new GetUserOverviewQueryResult | ||
{ | ||
Id = userResponse.Id, | ||
FirstName = userResponse.FirstName, | ||
LastName = userResponse.LastName, | ||
Email = userResponse.Email, | ||
IsActive = userResponse.IsActive, | ||
IsLocked = userResponse.IsLocked, | ||
IsSuspended = userResponse.IsSuspended, | ||
AccountSummaries = accounts != null ? accounts.Select(x => | ||
new AccountSummary | ||
{ | ||
DasAccountName = x.DasAccountName, | ||
HashedAccountId = x.HashedAccountId | ||
}).ToList() : [], | ||
}; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...rt/SFA.DAS.ToolsSupport/Application/Queries/GetUserOverview/GetUserOverviewQueryResult.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using SFA.DAS.ToolsSupport.InnerApi.Responses; | ||
|
||
namespace SFA.DAS.ToolsSupport.Application.Queries.GetUserOverview; | ||
|
||
public class GetUserOverviewQueryResult | ||
{ | ||
public string Id { get; set; } = ""; | ||
public string FirstName { get; set; } = ""; | ||
public string LastName { get; set; } = ""; | ||
public string Email { get; set; } = ""; | ||
public bool IsActive { get; set; } | ||
public bool IsLocked { get; set; } | ||
public bool IsSuspended { get; set; } | ||
public List<AccountSummary> AccountSummaries { get; set; } = []; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 0 additions & 8 deletions
8
src/ToolsSupport/SFA.DAS.ToolsSupport/InnerApi/Requests/Account/GetAccountRequest.cs
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
...olsSupport/SFA.DAS.ToolsSupport/InnerApi/Requests/GetEmployerAccountLegalEntityRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using SFA.DAS.SharedOuterApi.Interfaces; | ||
|
||
namespace SFA.DAS.ToolsSupport.InnerApi.Requests; | ||
|
||
public class GetEmployerAccountLegalEntityRequest(string href) : IGetApiRequest | ||
{ | ||
public string GetUrl => href; | ||
} |
8 changes: 8 additions & 0 deletions
8
src/ToolsSupport/SFA.DAS.ToolsSupport/InnerApi/Requests/GetUserAccountsRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using SFA.DAS.SharedOuterApi.Interfaces; | ||
|
||
namespace SFA.DAS.ToolsSupport.InnerApi.Requests; | ||
|
||
internal class GetUserAccountsRequest(Guid userId) : IGetApiRequest | ||
{ | ||
public string GetUrl => $"api/user/{userId}/accounts"; | ||
cofaulco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
8 changes: 8 additions & 0 deletions
8
src/ToolsSupport/SFA.DAS.ToolsSupport/InnerApi/Requests/GetUserByIdRequest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
using SFA.DAS.SharedOuterApi.Interfaces; | ||
|
||
namespace SFA.DAS.ToolsSupport.InnerApi.Requests; | ||
|
||
public class GetUserByIdRequest(Guid userId) : IGetApiRequest | ||
{ | ||
public string GetUrl => $"api/users/{userId}"; | ||
} |
6 changes: 6 additions & 0 deletions
6
src/ToolsSupport/SFA.DAS.ToolsSupport/InnerApi/Responses/AccountSummary.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
namespace SFA.DAS.ToolsSupport.InnerApi.Responses; | ||
public class AccountSummary | ||
{ | ||
public string DasAccountName { get; set; } = ""; | ||
public string HashedAccountId { get; set; } = ""; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/ToolsSupport/SFA.DAS.ToolsSupport/InnerApi/Responses/GetUserOverviewResponse.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
namespace SFA.DAS.ToolsSupport.InnerApi.Responses; | ||
|
||
public class GetUserOverviewResponse | ||
{ | ||
public string Id { get; set; } = ""; | ||
public string FirstName { get; set; } = ""; | ||
public string LastName { get; set; } = ""; | ||
public string Email { get; set; } = ""; | ||
public bool IsActive { get; set; } | ||
public bool IsLocked { get; set; } | ||
public bool IsSuspended { get; set; } | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't return mediatr responses from the apim layer