Skip to content

Commit

Permalink
Merge pull request #725 from SkillsFundingAgency/CV-629-ChangeOfParty…
Browse files Browse the repository at this point in the history
…-ViewDetails

Cv 629 change of party view details
  • Loading branch information
Najamuddin-Muhammad authored Apr 27, 2020
2 parents e1ab7d1 + b3242c8 commit 3f30e71
Show file tree
Hide file tree
Showing 30 changed files with 635 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@ public async Task GetApprenticeshipUpdates_WithNullStatus_VerifyUrlAndData()
await _fixture.CommitmentsApiClient.GetApprenticeshipUpdates(1, request);
_fixture.MockRestHttpClient.Verify(x => x.Get<GetApprenticeshipUpdatesResponse>($"api/apprenticeships/{1}/updates", null, CancellationToken.None));
}

[Test]
public async Task GetChangeOfPartyRequests_VerifyUrlAndData()
{
await _fixture.CommitmentsApiClient.GetChangeOfPartyRequests(123);
_fixture.MockRestHttpClient.Verify(x => x.Get<GetChangeOfPartyRequestsResponse>("api/apprenticeships/123/change-of-party-requests", null, CancellationToken.None));
}
}

public class WhenCallingTheEndpointsFixture
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,5 +302,10 @@ public Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPart
{
return _client.PostAsJson($"api/apprenticeships/{apprenticeshipId}/change-of-party-requests", request, cancellationToken);
}

public Task<GetChangeOfPartyRequestsResponse> GetChangeOfPartyRequests(long apprenticeshipId, CancellationToken cancellationToken = default)
{
return _client.Get<GetChangeOfPartyRequestsResponse>($"api/apprenticeships/{apprenticeshipId}/change-of-party-requests", null, cancellationToken);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ public interface ICommitmentsApiClient
Task<GetApprenticeshipUpdatesResponse> GetApprenticeshipUpdates(long apprenticeshipId, GetApprenticeshipUpdatesRequest request, CancellationToken cancellationToken = default);
Task<GetDataLocksResponse> GetApprenticeshipDatalocksStatus(long apprenticeshipId, CancellationToken cancellationToken = default);
Task CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default);
Task<GetChangeOfPartyRequestsResponse> GetChangeOfPartyRequests(long apprenticeshipId, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using SFA.DAS.CommitmentsV2.Types;

namespace SFA.DAS.CommitmentsV2.Api.Types.Responses
{
public class GetChangeOfPartyRequestsResponse
{
public IReadOnlyCollection<ChangeOfPartyRequest> ChangeOfPartyRequests { get; set; }

public class ChangeOfPartyRequest
{
public long Id { get; set; }
public ChangeOfPartyRequestType ChangeOfPartyType { get; set; }
public Party OriginatingParty { get; set; }
public ChangeOfPartyRequestStatus Status { get; set; }
public string EmployerName { get; set; }
public DateTime StarDate { get; set; }
public int Price { get; set; }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Controllers;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest;
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;
using SFA.DAS.Testing.AutoFixture;
Expand Down Expand Up @@ -167,21 +166,5 @@ public async Task ReturnNotFoundIfNullIsReturned()
//Assert
Assert.IsNotNull(result);
}

[Test, MoqAutoData]
public async Task PostChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request)
{
await _controller.CreateChangeOfPartyRequest(apprenticeshipId, request);

//Assert
_mediator.Verify(
m => m.Send(
It.Is<ChangeOfPartyRequestCommand>(p =>
p.ApprenticeshipId == apprenticeshipId &&
p.ChangeOfPartyRequestType == request.ChangeOfPartyRequestType &&
p.NewPartyId == request.NewPartyId && p.NewStartDate == request.NewStartDate &&
p.NewPrice == request.NewPrice && p.UserInfo == request.UserInfo),
It.IsAny<CancellationToken>()), Times.Once);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using MediatR;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Controllers;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;

namespace SFA.DAS.CommitmentsV2.Api.UnitTests.Controllers.ChangeOfPartyControllerTests
{
[TestFixture]
public class CreateTests
{
private CreateTestsFixture _fixture;

[SetUp]
public void Arrange()
{
_fixture = new CreateTestsFixture();
}

[Test]
public async Task PostChangeOfPartyRequest()
{
await _fixture.PostChangeOfPartyRequest();
_fixture.VerifyPost();
}

private class CreateTestsFixture
{
private readonly Mock<IMediator> _mediator;
private readonly Mock<IModelMapper> _mapper;
private readonly ChangeOfPartyController _controller;

private readonly Fixture _autoFixture;
private readonly long _apprenticeshipId;
private readonly CreateChangeOfPartyRequestRequest _postRequest;

public CreateTestsFixture()
{
_mediator = new Mock<IMediator>();
_mapper = new Mock<IModelMapper>();

_autoFixture = new Fixture();
_apprenticeshipId = _autoFixture.Create<long>();
_postRequest = _autoFixture.Create<CreateChangeOfPartyRequestRequest>();

_controller = new ChangeOfPartyController(_mediator.Object, _mapper.Object);
}

public async Task PostChangeOfPartyRequest()
{
await _controller.CreateChangeOfPartyRequest(_apprenticeshipId, _postRequest);
}

public void VerifyPost()
{
_mediator.Verify(
m => m.Send(
It.Is<CreateChangeOfPartyRequestCommand>(p =>
p.ApprenticeshipId == _apprenticeshipId &&
p.ChangeOfPartyRequestType == _postRequest.ChangeOfPartyRequestType &&
p.NewPartyId == _postRequest.NewPartyId && p.NewStartDate == _postRequest.NewStartDate &&
p.NewPrice == _postRequest.NewPrice && p.UserInfo == _postRequest.UserInfo),
It.IsAny<CancellationToken>()), Times.Once);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using AutoFixture;
using MediatR;
using Microsoft.AspNetCore.Mvc;
using Moq;
using NUnit.Framework;
using SFA.DAS.CommitmentsV2.Api.Controllers;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;

namespace SFA.DAS.CommitmentsV2.Api.UnitTests.Controllers.ChangeOfPartyControllerTests
{
[TestFixture]
public class GetAllTests
{
private GetAllTestsFixture _fixture;

[SetUp]
public void Arrange()
{
_fixture = new GetAllTestsFixture();
}

[Test]
public async Task GetAll()
{
await _fixture.GetAll();
_fixture.VerifyResult();
}

private class GetAllTestsFixture
{
private readonly Mock<IMediator> _mediator;
private readonly Mock<IModelMapper> _mapper;
private readonly ChangeOfPartyController _controller;
private readonly GetChangeOfPartyRequestsQueryResult _queryResult;
private readonly GetChangeOfPartyRequestsResponse _mapperResult;

private IActionResult _result;

private readonly Fixture _autoFixture;
private readonly long _apprenticeshipId;

public GetAllTestsFixture()
{
_mediator = new Mock<IMediator>();
_mapper = new Mock<IModelMapper>();

_queryResult = new GetChangeOfPartyRequestsQueryResult();
_mapperResult = new GetChangeOfPartyRequestsResponse();

_autoFixture = new Fixture();

_mediator.Setup(x =>
x.Send(It.Is<GetChangeOfPartyRequestsQuery>(q => q.ApprenticeshipId == _apprenticeshipId),
It.IsAny<CancellationToken>()))
.ReturnsAsync(_queryResult);

_mapper.Setup(x => x.Map<GetChangeOfPartyRequestsResponse>(_queryResult)).ReturnsAsync(_mapperResult);

_apprenticeshipId = _autoFixture.Create<long>();

_controller = new ChangeOfPartyController(_mediator.Object, _mapper.Object);
}

public async Task GetAll()
{
_result = await _controller.GetAll(_apprenticeshipId);
}

public void VerifyResult()
{
Assert.IsNotNull(_result);
var okObject = _result as OkObjectResult;
Assert.IsNotNull(okObject);
var objectValue = okObject.Value as GetChangeOfPartyRequestsResponse;
Assert.IsNotNull(objectValue);

Assert.AreEqual(_mapperResult, objectValue);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Application.Commands.ChangeOfPartyRequest;
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeship;
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeships;
using SFA.DAS.CommitmentsV2.Application.Queries.GetApprenticeshipsFilterValues;
Expand Down Expand Up @@ -102,22 +100,5 @@ public async Task<IActionResult> GetApprenticeshipsFilterValues([FromQuery]GetAp

return Ok(response);
}

[HttpPost]
[Route("{apprenticeshipId}/change-of-party-requests")]
public async Task<IActionResult> CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default)
{
await _mediator.Send(new ChangeOfPartyRequestCommand
{
ApprenticeshipId = apprenticeshipId,
ChangeOfPartyRequestType = request.ChangeOfPartyRequestType,
NewPartyId = request.NewPartyId,
NewStartDate = request.NewStartDate,
NewPrice = request.NewPrice,
UserInfo = request.UserInfo
}, cancellationToken);

return Ok();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using System.Threading;
using System.Threading.Tasks;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using SFA.DAS.CommitmentsV2.Api.Types.Requests;
using SFA.DAS.CommitmentsV2.Api.Types.Responses;
using SFA.DAS.CommitmentsV2.Application.Commands.CreateChangeOfPartyRequest;
using SFA.DAS.CommitmentsV2.Application.Queries.GetChangeOfPartyRequests;
using SFA.DAS.CommitmentsV2.Shared.Interfaces;

namespace SFA.DAS.CommitmentsV2.Api.Controllers
{
[ApiController]
[Authorize]
[Route("api/apprenticeships/{apprenticeshipId}/change-of-party-requests")]
public class ChangeOfPartyController : ControllerBase
{
private readonly IMediator _mediator;
private readonly IModelMapper _modelMapper;

public ChangeOfPartyController(IMediator mediator, IModelMapper modelMapper)
{
_mediator = mediator;
_modelMapper = modelMapper;
}

[HttpGet]
public async Task<IActionResult> GetAll(long apprenticeshipId, CancellationToken cancellationToken = default)
{
var result = await _mediator.Send(new GetChangeOfPartyRequestsQuery(apprenticeshipId), cancellationToken);
var response = await _modelMapper.Map<GetChangeOfPartyRequestsResponse>(result);
return Ok(response);
}

[HttpPost]
public async Task<IActionResult> CreateChangeOfPartyRequest(long apprenticeshipId, CreateChangeOfPartyRequestRequest request, CancellationToken cancellationToken = default)
{
await _mediator.Send(new CreateChangeOfPartyRequestCommand
{
ApprenticeshipId = apprenticeshipId,
ChangeOfPartyRequestType = request.ChangeOfPartyRequestType,
NewPartyId = request.NewPartyId,
NewStartDate = request.NewStartDate,
NewPrice = request.NewPrice,
UserInfo = request.UserInfo
}, cancellationToken);

return Ok();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,26 @@ public void ToGdsFormatReturnsFormattedResultCorrectly(DateTime value, string ex
Assert.AreEqual(expectedResult, value.ToGdsFormat());
}

[TestCase("2019-03-01", "1 March 2019")]
[TestCase("2020-10-20", "20 October 2020")]
public void ToGdsFormatLongMonthReturnsFormattedResultCorrectly(DateTime value, string expectedResult)
{
Assert.AreEqual(expectedResult, value.ToGdsFormatLongMonth());
}

[TestCase("2019-03-01", "Mar 2019")]
[TestCase("2020-10-20", "Oct 2020")]
public void ToGdsFormatWithoutDayReturnsFormattedResultCorrectly(DateTime value, string expectedResult)
{
Assert.AreEqual(expectedResult, value.ToGdsFormatWithoutDay());
}

[TestCase("2019-03-01", "March 2019")]
[TestCase("2020-10-20", "October 2020")]
public void ToGdsFormatLongMonthWithoutDayReturnsFormattedResultCorrectly(DateTime value, string expectedResult)
{
Assert.AreEqual(expectedResult, value.ToGdsFormatLongMonthWithoutDay());
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ public static string ToGdsFormat(this DateTime value)
{
return $"{value:d MMM yyyy}";
}
public static string ToGdsFormatLongMonth(this DateTime value)
{
return $"{value:d MMMM yyyy}";
}
public static string ToGdsFormatWithoutDay(this DateTime value)
{
return $"{value:MMM yyyy}";
}
public static string ToGdsFormatLongMonthWithoutDay(this DateTime value)
{
return $"{value:MMMM yyyy}";
}
}
}
Loading

0 comments on commit 3f30e71

Please sign in to comment.