Skip to content

Commit

Permalink
Merge branch 'master' into TM-15-Transfer-Allowance
Browse files Browse the repository at this point in the history
  • Loading branch information
mmiddleton3301 authored Jun 4, 2021
2 parents 2b6d3bc + 9f3a133 commit 784497d
Show file tree
Hide file tree
Showing 24 changed files with 510 additions and 107 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -274,3 +274,6 @@ App.Debug.config

# Local configs
src/**/appsettings.Development.json

#nservicebus
*.learningtransport*
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ Background:

Scenario: New apprenticeship is recieved and is valid
When the following apprenticeship is posted
| ApprenticeshipId | Email | Employer Name | Employer Account Legal Entity Id | Training Provider Id | Approved On |
| 1 | Test@Test.com | Apple | 123 | 1002 | 2015-04-20 |
| Commitments ApprenticeshipId | Email | Employer Name | Employer Account Legal Entity Id | Training Provider Id | Commitments Approved On |
| 1 | Test@Test.com | Apple | 123 | 1002 | 2015-04-20 |
Then the inner API has received the posted values
And the Training Provider Name should be 'My Only Name'
And the course should be `Artificial Intelligence` level 1
And the invitation was sent successfully

Scenario: New apprenticeship is recieved and is valid and there is a trading name for provider
When the following apprenticeship is posted
| ApprenticeshipId | Email | Employer Name | Employer Account Legal Entity Id | Training Provider Id | Approved On |
| 2 | SomeOther@Test.com | Apple | 123 | 1001 | 2019-03-31 |
| Commitments ApprenticeshipId | Email | Employer Name | Employer Account Legal Entity Id | Training Provider Id | Commitments Approved On |
| 2 | SomeOther@Test.com | Apple | 123 | 1001 | 2019-03-31 |
Then the inner API has received the posted values
And the Training Provider Name should be 'My Trading Name'
And the invitation was sent successfully

Scenario: New apprenticeship is recieved and is Not valid
When the following apprenticeship is posted
| ApprenticeshipId | Email | Employer Name | Employer Account Legal Entity Id | Training Provider Id |
| 1 | invalidemail | Apple | 123 | 1002 |
| Commitments ApprenticeshipId | Email | Employer Name | Employer Account Legal Entity Id | Training Provider Id |
| 1 | invalidemail | Apple | 123 | 1002 |
Then the inner API should return these errors
| field | error |
| email | Not valid |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ Feature: ChangeApprenticeship

Background:
Given the following apprenticeships have been approved
| Id | First Name | Last Name | Course Name | Course Code | ProviderId | AccountLegalEntityId | Employer Name |
| 1 | Alexa | Armstrong | Artificial Intelligence | 9001 | 1001 | 8001 | Apple |
| 2 | Zachary | Zimmerman | Zoology | 9002 | 1002 | 8002 | Google |
| Id | First Name | Last Name | Course Name | Course Code | ProviderId | AccountLegalEntityId | Employer Name | Email |
| 1 | Alexa | Armstrong | Artificial Intelligence | 9001 | 1001 | 8001 | Apple | a@a |
| 2 | Zachary | Zimmerman | Zoology | 9002 | 1002 | 8002 | Google | b@b |
| 3 | Zachary | Zimmerman | Zoology | 9002 | 1002 | 8002 | Google | c@c |
| 4 | Zachary | Zimmerman | Zoology | 9002 | 1002 | 8002 | Google | |

Given the following training providers exist
| Ukprn | Legal Name | Trading Name |
Expand All @@ -22,18 +24,30 @@ Background:

Scenario: Apprenticeship update is recieved and is valid
When the following apprenticeship update is posted
| ApprenticeshipId | Email | Approved On |
| 1 | Test@Test.com | 2015-04-20 |
| Commitments ApprenticeshipId | Commitments Approved On |
| 1 | 2015-04-20 |
Then the inner API has received the posted values
And the Employer should be Legal Entity 8001 named 'Apple'
And the Training Provider should be 'My Only Name'
And the course should be `Artificial Intelligence` level 1

Scenario: Apprenticeship update is recieved and is valid and there is a trading name for provider
When the following apprenticeship update is posted
| ApprenticeshipId | Email | Approved On |
| 2 | Other@Test.com | 2015-04-20 |
| Commitments ApprenticeshipId | Commitments Approved On |
| 2 | 2015-04-20 |
Then the inner API has received the posted values
And the Employer should be Legal Entity 8002 named 'Google'
And the Training Provider should be 'My Trading Name'
And the course should be `Zoology` level 3

Scenario: Apprenticeship update is recieved and is a continuation apprenticeship
When the following apprenticeship update is posted
| Commitments Continuation Of ApprenticeshipId | Commitments ApprenticeshipId | Commitments Approved On |
| 1 | 3 | 2015-04-20 |
Then the inner API has received the posted values

Scenario: Apprenticeship update is recieved but without an email
When the following apprenticeship update is posted
| Commitments ApprenticeshipId | Commitments Approved On |
| 4 | 2015-04-20 |
Then the inner API will not receive any values
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
using FluentAssertions;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
using Newtonsoft.Json;

namespace SFA.DAS.ApprenticeCommitments.Api.AcceptanceTests
{
public static class JsonConvertExtensions
{
public static AndWhichConstraint<JsonConvertAssertions, T> ShouldBeJson<T>(this string instance)
{
return new JsonConvertAssertions(instance).DeserialiseTo<T>();
}

public static AndWhichConstraint<JsonConvertAssertions, T> ShouldBeJson<T>(this StringAssertions instance)
{
return new JsonConvertAssertions(instance.Subject).DeserialiseTo<T>();
}

public class JsonConvertAssertions :
ReferenceTypeAssertions<string, JsonConvertAssertions>
{
public JsonConvertAssertions(string instance)
{
Subject = instance;
}

protected override string Identifier => "string";

public AndWhichConstraint<JsonConvertAssertions, T> DeserialiseTo<T>(
string because = "", params object[] becauseArgs)
{
var deserialised = JsonConvert.DeserializeObject<T>(Subject);

Execute.Assertion
.ForCondition(deserialised != null)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:string} to contain deserilise to {0}{reason}, but found.",
typeof(T).Name);

return new AndWhichConstraint<JsonConvertAssertions, T>(this, deserialised);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public async Task WhenTheFollowingApprenticeshipIsPosted(Table table)
public void ThenTheRequestToTheInnerApiWasMappedCorrectly()
{
var expectedCommitment = _approvedApprenticeships.First(
x => x.Id == _request.ApprenticeshipId);
x => x.Id == _request.CommitmentsApprenticeshipId);

_context.OuterApiClient.Response.StatusCode
.Should().Be(HttpStatusCode.Accepted);
Expand All @@ -158,8 +158,8 @@ public void ThenTheRequestToTheInnerApiWasMappedCorrectly()
innerApiRequest.Should().NotBeNull();
innerApiRequest.ApprenticeId.Should().NotBe(Guid.Empty);
innerApiRequest.Email.Should().Be(_request.Email);
innerApiRequest.ApprenticeshipId.Should().Be(_request.ApprenticeshipId);
innerApiRequest.ApprovedOn.Should().Be(_request.CommitmentsApprovedOn);
innerApiRequest.CommitmentsApprenticeshipId.Should().Be(_request.CommitmentsApprenticeshipId);
innerApiRequest.CommitmentsApprovedOn.Should().Be(_request.CommitmentsApprovedOn);
innerApiRequest.EmployerName.Should().Be(_request.EmployerName);
innerApiRequest.EmployerAccountLegalEntityId.Should().Be(_request.EmployerAccountLegalEntityId);
innerApiRequest.TrainingProviderId.Should().Be(_request.TrainingProviderId);
Expand Down Expand Up @@ -208,7 +208,7 @@ public async Task ThenTheInnerAPIShouldReturnTheseErrors(Table table)
public void ThenTheInvitationWasSentSuccessfully()
{
var expectedCommitment = _approvedApprenticeships.First(
x => x.Id == _request.ApprenticeshipId);
x => x.Id == _request.CommitmentsApprenticeshipId);

var logs = _context.LoginApi.MockServer.LogEntries;
logs.Should().HaveCount(1);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
using FluentAssertions;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
using Newtonsoft.Json;
using SFA.DAS.ApprenticeCommitments.Apis.InnerApi;
using SFA.DAS.ApprenticeCommitments.Apis.TrainingProviderApi;
using SFA.DAS.ApprenticeCommitments.Application.Commands.ChangeApprenticeship;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
using SFA.DAS.ApprenticeCommitments.Application.Commands.UpdateApprenticeship;
using TechTalk.SpecFlow;
using TechTalk.SpecFlow.Assist;
using WireMock.Matchers;
using WireMock.RequestBuilders;
using WireMock.ResponseBuilders;

Expand All @@ -22,7 +19,7 @@ namespace SFA.DAS.ApprenticeCommitments.Api.AcceptanceTests.Steps
public class ChangeApprenticeshipSteps
{
private readonly TestContext _context;
private ChangeApprenticeshipCommand _request;
private UpdateApprenticeshipCommand _request;
private IEnumerable<Apis.CommitmentsV2InnerApi.ApprenticeshipResponse> _approvedApprenticeships;
private IEnumerable<Apis.TrainingProviderApi.TrainingProviderResponse> _trainingProviderResponses;
private IEnumerable<Apis.Courses.StandardResponse> _courseResponses;
Expand All @@ -41,15 +38,6 @@ public ChangeApprenticeshipSteps(TestContext context)
Response.Create()
.WithStatusCode((int)HttpStatusCode.Accepted)
);

_context.LoginApi.MockServer
.Given(
Request.Create().WithPath($"/invitations/{_context.LoginConfig.IdentityServerClientId}")
.UsingPost())
.RespondWith(
Response.Create()
.WithStatusCode((int)HttpStatusCode.OK)
);
}

[Given("the following apprenticeships have been approved")]
Expand Down Expand Up @@ -120,15 +108,15 @@ public void GivenTheFollowingCoursesExist(Table table)
[When("the following apprenticeship update is posted")]
public async Task WhenTheFollowingApprenticeshipIsPosted(Table table)
{
_request = table.CreateInstance<ChangeApprenticeshipCommand>();
await _context.OuterApiClient.Post("apprenticeships/change", _request);
_request = table.CreateInstance<UpdateApprenticeshipCommand>();
await _context.OuterApiClient.Post("apprenticeships/update", _request);
}

[Then("the inner API has received the posted values")]
public void ThenTheRequestToTheInnerApiWasMappedCorrectly()
{
var expectedCommitment = _approvedApprenticeships.First(
x => x.Id == _request.ApprenticeshipId);
x => x.Id == _request.CommitmentsApprenticeshipId);

_context.OuterApiClient.Response.StatusCode
.Should().Be(HttpStatusCode.Accepted);
Expand All @@ -137,19 +125,25 @@ public void ThenTheRequestToTheInnerApiWasMappedCorrectly()
.And.ShouldBeJson<ChangeApprenticeshipRequestData>()
.Which.Should().BeEquivalentTo(new
{
_request.ApprenticeshipId,
expectedCommitment.Email,
ApprovedOn = _request.ApprovedOn,
_request.CommitmentsContinuedApprenticeshipId,
_request.CommitmentsApprenticeshipId,
_request.CommitmentsApprovedOn,
expectedCommitment.CourseName,
PlannedStartDate = expectedCommitment.StartDate,
});
}

[Then("the inner API will not receive any values")]
public void ThenTheInnerApiWillNotBeCalled()
{
_context.InnerApi.SingleLogBody.Should().BeNull();
}

[Then("the Employer should be Legal Entity (.*) named '(.*)'")]
public void ThenTheEmployerNameShouldBe(long legalEntityId, string employerName)
{
var expectedCommitment = _approvedApprenticeships.First(
x => x.Id == _request.ApprenticeshipId);
x => x.Id == _request.CommitmentsApprenticeshipId);

_context.InnerApi.SingleLogBody.Should().NotBeEmpty()
.And.ShouldBeJson<ChangeApprenticeshipRequestData>()
Expand Down Expand Up @@ -201,42 +195,4 @@ public async Task ThenTheInnerAPIShouldReturnTheseErrors(Table table)
errors.Should().BeEquivalentTo(expectedErrors);
}
}

public static class JsonConvertExtensions
{
public static AndWhichConstraint<JsonConvertAssertions, T> ShouldBeJson<T>(this string instance)
{
return new JsonConvertAssertions(instance).DeserialiseTo<T>();
}

public static AndWhichConstraint<JsonConvertAssertions, T> ShouldBeJson<T>(this StringAssertions instance)
{
return new JsonConvertAssertions(instance.Subject).DeserialiseTo<T>();
}

public class JsonConvertAssertions :
ReferenceTypeAssertions<string, JsonConvertAssertions>
{
public JsonConvertAssertions(string instance)
{
Subject = instance;
}

protected override string Identifier => "string";

public AndWhichConstraint<JsonConvertAssertions, T> DeserialiseTo<T>(
string because = "", params object[] becauseArgs)
{
var deserialised = JsonConvert.DeserializeObject<T>(Subject);

Execute.Assertion
.ForCondition(deserialised != null)
.BecauseOf(because, becauseArgs)
.FailWith("Expected {context:string} to contain deserilise to {0}{reason}, but found.",
typeof(T).Name);

return new AndWhichConstraint<JsonConvertAssertions, T>(this, deserialised);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using MediatR;
using Microsoft.AspNetCore.Mvc;
using SFA.DAS.ApprenticeCommitments.Apis.InnerApi;
using SFA.DAS.ApprenticeCommitments.Application.Commands.ChangeApprenticeship;
using SFA.DAS.ApprenticeCommitments.Application.Commands.ChangeEmailAddress;
using SFA.DAS.ApprenticeCommitments.Application.Commands.CreateApprenticeship;
using SFA.DAS.ApprenticeCommitments.Configuration;
using SFA.DAS.SharedOuterApi.Interfaces;
using System;
using System.Threading.Tasks;
using SFA.DAS.ApprenticeCommitments.Application.Commands.UpdateApprenticeship;

namespace SFA.DAS.ApprenticeCommitments.Api.Controllers
{
Expand All @@ -32,8 +32,8 @@ public async Task<IActionResult> AddApprenticeship(CreateApprenticeshipCommand r
}

[HttpPost]
[Route("/apprenticeships/change")]
public async Task<IActionResult> UpdateApprenticeship(ChangeApprenticeshipCommand request)
[Route("/apprenticeships/update")]
public async Task<IActionResult> UpdateApprenticeship(UpdateApprenticeshipCommand request)
{
await _mediator.Send(request);
return Accepted();
Expand Down Expand Up @@ -96,7 +96,7 @@ public async Task<IActionResult> RolesAndResponsibilitiesConfirmation(
await _client.Post(
new RolesAndResponsibilitiesConfirmationRequest(
apprenticeId, apprenticeshipId, request.RolesAndResponsibilitiesCorrect));

return Ok();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ApprenticeshipResponse
public string EmployerName { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Email { get; internal set; }
public string Email { get; set; }
public long Uln { get; set; }
public string CourseCode { get; set; }
public string CourseName { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ public class ChangeApprenticeshipRequest : IPostApiRequest<ChangeApprenticeshipR

public class ChangeApprenticeshipRequestData
{
public long ApprenticeshipId { get; set; }
public DateTime ApprovedOn { get; set; }
public string Email { get; set; }
public long? CommitmentsContinuedApprenticeshipId { get; set; }
public long CommitmentsApprenticeshipId { get; set; }
public DateTime CommitmentsApprovedOn { get; set; }
public string EmployerName { get; set; }
public long EmployerAccountLegalEntityId { get; set; }
public long TrainingProviderId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class CreateApprenticeshipRequest : IPostApiRequest<CreateApprenticeshipR
public class CreateApprenticeshipRequestData
{
public Guid ApprenticeId { get; set; }
public long ApprenticeshipId { get; set; }
public DateTime ApprovedOn { get; set; }
public long CommitmentsApprenticeshipId { get; set; }
public DateTime CommitmentsApprovedOn { get; set; }
public string Email { get; set; }
public string EmployerName { get; set; }
public long EmployerAccountLegalEntityId { get; set; }
Expand Down
Loading

0 comments on commit 784497d

Please sign in to comment.