Skip to content

Commit

Permalink
PR Comments addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
balaji-j committed Dec 24, 2024
1 parent 837926b commit 8191c72
Show file tree
Hide file tree
Showing 12 changed files with 62 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
using Moq;
using NUnit.Framework;
using SFA.DAS.FindApprenticeshipJobs.Api.Controllers;
using SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetCandidatesByActivity;
using SFA.DAS.Testing.AutoFixture;
using System.Net;
using SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetInactiveCandidates;

namespace SFA.DAS.FindApprenticeshipJobs.Api.UnitTests.Controllers
{
Expand All @@ -20,19 +20,19 @@ public async Task Then_Candidates_Returned_From_Mediator(
int pageNumber,
int pageSize,
DateTime cutOffDateTime,
GetCandidateByActivityQueryResult mockQueryResult,
GetInactiveCandidatesQueryResult mockQueryResult,
[Frozen] Mock<IMediator> mockMediator,
[Greedy] CandidatesController sut)
{
mockMediator.Setup(x => x.Send(It.IsAny<GetCandidateByActivityQuery>(), It.IsAny<CancellationToken>())).ReturnsAsync(mockQueryResult);
mockMediator.Setup(x => x.Send(It.IsAny<GetInactiveCandidatesQuery>(), It.IsAny<CancellationToken>())).ReturnsAsync(mockQueryResult);

var actual = await sut.GetCandidatesByActivity(cutOffDateTime, pageNumber, pageSize, It.IsAny<CancellationToken>()) as ObjectResult;
var actualValue = actual!.Value as GetCandidateByActivityQueryResult;
var actual = await sut.GetInactiveCandidates(cutOffDateTime, pageNumber, pageSize, It.IsAny<CancellationToken>()) as ObjectResult;
var actualValue = actual!.Value as GetInactiveCandidatesQueryResult;

using (new AssertionScope())
{
actual.StatusCode.Should().Be((int)HttpStatusCode.OK);
actual.Value.Should().BeOfType<GetCandidateByActivityQueryResult>();
actual.Value.Should().BeOfType<GetInactiveCandidatesQueryResult>();
actualValue!.Candidates.Should().BeEquivalentTo(mockQueryResult.Candidates);
}
}
Expand All @@ -42,13 +42,13 @@ public async Task And_Exception_Returned_Then_Returns_Internal_Server_Error(
int pageNumber,
int pageSize,
DateTime cutOffDateTime,
GetCandidateByActivityQueryResult mockQueryResult,
GetInactiveCandidatesQueryResult mockQueryResult,
[Frozen] Mock<IMediator> mockMediator,
[Greedy] CandidatesController sut)
{
mockMediator.Setup(x => x.Send(It.IsAny<GetCandidateByActivityQuery>(), It.IsAny<CancellationToken>())).ThrowsAsync(new InvalidOperationException());
mockMediator.Setup(x => x.Send(It.IsAny<GetInactiveCandidatesQuery>(), It.IsAny<CancellationToken>())).ThrowsAsync(new InvalidOperationException());

var actual = await sut.GetCandidatesByActivity(cutOffDateTime, pageNumber, pageSize, It.IsAny<CancellationToken>()) as StatusCodeResult;
var actual = await sut.GetInactiveCandidates(cutOffDateTime, pageNumber, pageSize, It.IsAny<CancellationToken>()) as StatusCodeResult;

actual!.StatusCode.Should().Be((int)HttpStatusCode.InternalServerError);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetCandidatesByActivity;
using System.Net;
using SFA.DAS.FindApprenticeshipJobs.Application.Commands.Candidates;
using SFA.DAS.FindApprenticeshipJobs.Domain.Models;
using SFA.DAS.FindApprenticeshipJobs.Api.Models;
using SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetInactiveCandidates;

namespace SFA.DAS.FindApprenticeshipJobs.Api.Controllers
{
Expand All @@ -15,10 +15,10 @@ public class CandidatesController(
ILogger<CandidatesController> logger) : ControllerBase
{
[HttpGet]
[Route("GetCandidatesByActivity")]
[Route("GetInactiveCandidates")]
[ProducesResponseType((int)HttpStatusCode.OK)]
[ProducesResponseType((int)HttpStatusCode.InternalServerError)]
public async Task<IActionResult> GetCandidatesByActivity(
public async Task<IActionResult> GetInactiveCandidates(
[FromQuery] DateTime cutOffDateTime,
[FromQuery] int pageNumber = 1,
[FromQuery] int pageSize = 10,
Expand All @@ -28,13 +28,13 @@ public async Task<IActionResult> GetCandidatesByActivity(

try
{
var result = await mediator.Send(new GetCandidateByActivityQuery(cutOffDateTime, pageNumber, pageSize),
var result = await mediator.Send(new GetInactiveCandidatesQuery(cutOffDateTime, pageNumber, pageSize),
cancellationToken);
return Ok(result);
}
catch (Exception ex)
{
logger.LogError(ex, "Error invoking Get Candidates By Activity");
logger.LogError(ex, "Error invoking Get Inactive Candidates");
return new StatusCodeResult((int)HttpStatusCode.InternalServerError);
}
}
Expand All @@ -43,7 +43,7 @@ public async Task<IActionResult> GetCandidatesByActivity(
[Route("{govIdentifier}/status")]
public async Task<IActionResult> UpdateStatus(
[FromRoute] string govIdentifier,
[FromBody] CandidateUpdateStatusRequest request)
[FromBody] CandidateUpdateStatusRequest request, CancellationToken cancellationToken = default)
{
try
{
Expand All @@ -52,7 +52,7 @@ await mediator.Send(new UpdateCandidateStatusCommand
GovUkIdentifier = govIdentifier,
Email = request.Email,
Status = request.Status
});
}, cancellationToken);

return NoContent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using FluentAssertions;
using Moq;
using NUnit.Framework;
using SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetCandidatesByActivity;
using SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetInactiveCandidates;
using SFA.DAS.FindApprenticeshipJobs.InnerApi.Requests;
using SFA.DAS.FindApprenticeshipJobs.InnerApi.Responses;
using SFA.DAS.SharedOuterApi.Configuration;
Expand All @@ -17,17 +17,17 @@ public class WhenHandlingGetCandidatesByActivityQuery
[Test]
[MoqAutoData]
public async Task Then_The_Candidates_Are_Returned(
GetCandidateByActivityQuery query,
GetCandidatesByActivityApiResponse mockCandidatesByActivityApiResponse,
GetInactiveCandidatesQuery query,
GetInactiveCandidatesApiResponse mockCandidatesByActivityApiResponse,
[Frozen] Mock<ICandidateApiClient<CandidateApiConfiguration>> mockCandidateApiClient,
GetCandidateByActivityQueryHandler handler)
GetInactiveCandidatesQueryHandler handler)
{
var expectedGetCandidatesByActivityApiRequest =
new GetCandidatesByActivityApiRequest(query.CutOffDateTime.ToString("O"), query.PageNumber, query.PageSize);
new GetInactiveCandidatesApiRequest(query.CutOffDateTime.ToString("O"), query.PageNumber, query.PageSize);

mockCandidateApiClient
.Setup(client => client.Get<GetCandidatesByActivityApiResponse>(
It.Is<GetCandidatesByActivityApiRequest>(c =>
.Setup(client => client.Get<GetInactiveCandidatesApiResponse>(
It.Is<GetInactiveCandidatesApiRequest>(c =>
c.GetUrl == expectedGetCandidatesByActivityApiRequest.GetUrl)))
.ReturnsAsync(mockCandidatesByActivityApiResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
namespace SFA.DAS.FindApprenticeshipJobs.UnitTests.InnerApi
{
[TestFixture]
public class WhenBuildingGetCandidatesByActivityApiRequest
public class WhenBuildingGetInactiveCandidatesApiRequest
{
[Test, AutoData]
public void Then_The_Url_Is_Correctly_Built(string cutOffDateTime, int pageNumber, int pageSize)
{
var actual = new GetCandidatesByActivityApiRequest(cutOffDateTime, pageNumber, pageSize);
var actual = new GetInactiveCandidatesApiRequest(cutOffDateTime, pageNumber, pageSize);

actual.GetUrl.Should().Be($"api/candidates/GetCandidatesByActivity?cutOffDateTime={cutOffDateTime}&pageNumber={pageNumber}&pageSize={pageSize}");
actual.GetUrl.Should().Be($"api/candidates/GetInactiveCandidates?cutOffDateTime={cutOffDateTime}&pageNumber={pageNumber}&pageSize={pageSize}");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace SFA.DAS.FindApprenticeshipJobs.Application.Commands.Candidates
{
public record UpdateCandidateStatusCommand : IRequest
{
public string GovUkIdentifier { get; set; }
public string Email { get; set; }
public required string GovUkIdentifier { get; set; }
public required string Email { get; set; }
public UserStatus Status { get; set; }
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using MediatR;

namespace SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetInactiveCandidates
{
public record GetInactiveCandidatesQuery(
DateTime CutOffDateTime,
int PageNumber = 1,
int PageSize = 10) : IRequest<GetInactiveCandidatesQueryResult>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
using SFA.DAS.SharedOuterApi.Configuration;
using SFA.DAS.SharedOuterApi.Interfaces;

namespace SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetCandidatesByActivity
namespace SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetInactiveCandidates
{
public class GetCandidateByActivityQueryHandler(
public class GetInactiveCandidatesQueryHandler(
ICandidateApiClient<CandidateApiConfiguration> candidateApiClient)
: IRequestHandler<GetCandidateByActivityQuery, GetCandidateByActivityQueryResult>
: IRequestHandler<GetInactiveCandidatesQuery, GetInactiveCandidatesQueryResult>
{
public async Task<GetCandidateByActivityQueryResult> Handle(GetCandidateByActivityQuery request, CancellationToken cancellationToken)
public async Task<GetInactiveCandidatesQueryResult> Handle(GetInactiveCandidatesQuery request, CancellationToken cancellationToken)
{
var candidatesResponse = await candidateApiClient.Get<GetCandidatesByActivityApiResponse>(
new GetCandidatesByActivityApiRequest(
var candidatesResponse = await candidateApiClient.Get<GetInactiveCandidatesApiResponse>(
new GetInactiveCandidatesApiRequest(
request.CutOffDateTime.ToString("O"),
request.PageNumber,
request.PageSize));

if (candidatesResponse is not { Candidates.Count: > 0 })
return new GetCandidateByActivityQueryResult
return new GetInactiveCandidatesQueryResult
{
PageSize = candidatesResponse.PageSize,
PageIndex = candidatesResponse.PageIndex,
Expand All @@ -28,9 +28,9 @@ public async Task<GetCandidateByActivityQueryResult> Handle(GetCandidateByActivi
Candidates = []
};

return new GetCandidateByActivityQueryResult
return new GetInactiveCandidatesQueryResult
{
Candidates = candidatesResponse.Candidates.Select(candidate => (GetCandidateByActivityQueryResult.Candidate)candidate).ToList(),
Candidates = candidatesResponse.Candidates.Select(candidate => (GetInactiveCandidatesQueryResult.Candidate)candidate).ToList(),
PageSize = candidatesResponse.PageSize,
PageIndex = candidatesResponse.PageIndex,
TotalPages = candidatesResponse.TotalPages,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using SFA.DAS.FindApprenticeshipJobs.Domain.Models;
using SFA.DAS.FindApprenticeshipJobs.InnerApi.Responses;

namespace SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetCandidatesByActivity
namespace SFA.DAS.FindApprenticeshipJobs.Application.Queries.SavedSearch.GetInactiveCandidates
{
public record GetCandidateByActivityQueryResult
public record GetInactiveCandidatesQueryResult
{
public List<Candidate> Candidates { get; set; } = [];
public int TotalCount { get; set; }
public int PageIndex { get; set; }
public int PageSize { get; set; }
public int TotalPages { get; set; }

public static implicit operator GetCandidateByActivityQueryResult(GetCandidatesByActivityApiResponse source)
public static implicit operator GetInactiveCandidatesQueryResult(GetInactiveCandidatesApiResponse source)
{
return new GetCandidateByActivityQueryResult
return new GetInactiveCandidatesQueryResult
{
Candidates = source.Candidates.Select(candidate => (Candidate)candidate).ToList()
};
Expand All @@ -37,7 +37,7 @@ public class Candidate
public Guid Id { get; set; }
public Guid? MigratedCandidateId { get; set; }

public static implicit operator Candidate(GetCandidatesByActivityApiResponse.Candidate source)
public static implicit operator Candidate(GetInactiveCandidatesApiResponse.Candidate source)
{
return new Candidate
{
Expand Down Expand Up @@ -73,7 +73,7 @@ public class Address
public double Longitude { get; set; }
public Guid CandidateId { get; set; }

public static implicit operator Address(GetCandidatesByActivityApiResponse.Address source)
public static implicit operator Address(GetInactiveCandidatesApiResponse.Address source)
{
return new Address
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using SFA.DAS.SharedOuterApi.Interfaces;

namespace SFA.DAS.FindApprenticeshipJobs.InnerApi.Requests
{
public class GetInactiveCandidatesApiRequest(string cutOffDateTime, int pageNumber, int pageSize) : IGetApiRequest
{
public string GetUrl => $"api/candidates/GetInactiveCandidates?cutOffDateTime={cutOffDateTime}&pageNumber={pageNumber}&pageSize={pageSize}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace SFA.DAS.FindApprenticeshipJobs.InnerApi.Responses
{
public class GetCandidatesByActivityApiResponse
public class GetInactiveCandidatesApiResponse
{
[JsonProperty("candidates")]
public List<Candidate> Candidates { get; set; } = [];
Expand Down

0 comments on commit 8191c72

Please sign in to comment.