Skip to content

Commit

Permalink
Merge branch 'main' into feature/single-choice-field-type
Browse files Browse the repository at this point in the history
  • Loading branch information
andymantell authored Sep 27, 2024
2 parents 9b03f8f + fbfa297 commit 9666446
Show file tree
Hide file tree
Showing 129 changed files with 6,607 additions and 3,957 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
using Amazon.S3;
using CO.CDP.Organisation.WebApiClient;
using CO.CDP.OrganisationApp.Constants;
using CO.CDP.OrganisationApp.Pages.ApiKeyManagement;
using FluentAssertions;
using FluentAssertions.Equivalency;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,14 @@ public void SetAnswer_SetsExpectedTextInput(string? input, string? expected)
}

[Theory]
[InlineData(true, null, "All information is required on this page")]
[InlineData(true, " ", "All information is required on this page")]
[InlineData(false, null, null)]
[InlineData(false, "Some value", null)]
public void Validate_ReturnsExpectedResults(bool isRequired, string? textInput, string? expectedErrorMessage)
[InlineData(true, null, null, "Enter a value")]
[InlineData(true, null, " ", "Enter a value")]
[InlineData(false, false, null, null)]
[InlineData(false, true, "Some value", null)]
public void Validate_ReturnsExpectedResults(bool isRequired, bool? hasValue, string? textInput, string? expectedErrorMessage)
{
_model.IsRequired = isRequired;
_model.HasValue = hasValue;
_model.CurrentFormQuestionType = FormQuestionType.Text;
_model.TextInput = textInput;

Expand All @@ -85,7 +86,7 @@ public void Validate_ReturnsExpectedResults(bool isRequired, string? textInput,
[InlineData("[email protected]", null)]
public void Validate_EmailValidation_ReturnsExpectedResults(string? email, string? expectedErrorMessage)
{
_model.IsRequired = false;
_model.IsRequired = true;
_model.CurrentFormQuestionType = FormQuestionType.Text;
_model.Heading = "Email Address";
_model.TextInput = email;
Expand All @@ -104,15 +105,16 @@ public void Validate_EmailValidation_ReturnsExpectedResults(string? email, strin
}

[Theory]
[InlineData(true, "Email Address", null, "All information is required on this page")]
[InlineData(true, "Email Address", "invalid-email", "Enter an email address in the correct format, like [email protected].")]
[InlineData(true, "Email Address", "[email protected]", null)]
[InlineData(false, "Email Address", "somevalue", "Enter an email address in the correct format, like [email protected].")]
[InlineData(false, "Email Address", null, null)]
[InlineData(false, "Name", "invalid-email", null)]
public void Validate_EmailFieldValidationBasedOnHeading_ReturnsExpectedResults(bool isRequired, string heading, string? textInput, string? expectedErrorMessage)
[InlineData(true, null, "Email Address", null, "Enter an email address in the correct format, like [email protected].")]
[InlineData(true, null, "Email Address", "invalid-email", "Enter an email address in the correct format, like [email protected].")]
[InlineData(true, null, "Email Address", "[email protected]", null)]
[InlineData(false, true, "Email Address", "somevalue", "Enter an email address in the correct format, like [email protected].")]
[InlineData(false, false, "Email Address", null, null)]
[InlineData(false, true, "Name", "invalid-email", null)]
public void Validate_EmailFieldValidationBasedOnHeading_ReturnsExpectedResults(bool isRequired, bool? hasValue, string heading, string? textInput, string? expectedErrorMessage)
{
_model.IsRequired = isRequired;
_model.HasValue = hasValue;
_model.CurrentFormQuestionType = FormQuestionType.Text;
_model.Heading = heading;
_model.TextInput = textInput;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using CO.CDP.OrganisationApp.Pages.Forms;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Moq;

namespace CO.CDP.OrganisationApp.Tests.Pages.Forms;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using CO.CDP.Organisation.WebApiClient;
using CO.CDP.OrganisationApp.Models;
using CO.CDP.OrganisationApp.Pages;
using CO.CDP.OrganisationApp.Pages.Organisation;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
using CO.CDP.Organisation.WebApiClient;
using CO.CDP.OrganisationApp.Constants;
using CO.CDP.OrganisationApp.Models;
using CO.CDP.OrganisationApp.Pages.Organisation;
using CO.CDP.OrganisationApp.Pages.Shared;
using CO.CDP.OrganisationApp.Tests.Pages.Supplier;
using FluentAssertions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.HttpResults;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.RazorPages;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using CO.CDP.Organisation.WebApiClient;
using CO.CDP.OrganisationApp.Constants;
using CO.CDP.OrganisationApp.Models;
using CO.CDP.OrganisationApp.Pages.Registration;
using CO.CDP.OrganisationApp.ThirdPartyApiClients;
using CO.CDP.OrganisationApp.ThirdPartyApiClients.CompaniesHouse;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
Expand All @@ -9,87 +13,156 @@ namespace CO.CDP.OrganisationApp.Tests.Pages.Registration;
public class CompanyHouseNumberQuestionTests
{
private readonly Mock<ISession> sessionMock;
private readonly Mock<ITempDataService> tempDataServiceMock;
private readonly Mock<ICompaniesHouseApi> companiesHouseApiMock;
private readonly Mock<IOrganisationClient> organisationClientMock;

public CompanyHouseNumberQuestionTests()
{
sessionMock = new Mock<ISession>();
sessionMock.Setup(session => session.Get<UserDetails>(Session.UserDetailsKey))
.Returns(new UserDetails { UserUrn = "urn:test" });
tempDataServiceMock = new Mock<ITempDataService>();
companiesHouseApiMock = new Mock<ICompaniesHouseApi>();
organisationClientMock = new Mock<IOrganisationClient>();
}

[Theory]
[InlineData(null)]
[InlineData(false)]
public void OnPost_WhenOptionIsNullOrEmpty_ShouldReturnPageWithModelStateError(bool? hasNumber)
public async Task OnPost_WhenOptionIsNullOrEmpty_ShouldReturnPageWithModelStateError(bool? hasNumber)
{
var model = GivenCompaniesHouseQuestionModel();

var model = new CompanyHouseNumberQuestionModel(sessionMock.Object)
{
HasCompaniesHouseNumber = hasNumber
};
model.HasCompaniesHouseNumber = hasNumber;
model.ModelState.AddModelError("Question", "Please select an option");

var result = model.OnPost();
var result = await model.OnPost();

result.Should().BeOfType<PageResult>();
model.ModelState.IsValid.Should().BeFalse();
}

[Fact]
public void OnPost_WhenModelStateIsValid_ShouldRedirectToOrganisationIdentification()
public async Task OnPost_WhenModelStateIsValid_ShouldRedirectToOrganisationIdentification()
{
var model = new CompanyHouseNumberQuestionModel(sessionMock.Object)
{
HasCompaniesHouseNumber = false,
CompaniesHouseNumber = "12345678"
};
var model = GivenCompaniesHouseQuestionModel();

model.HasCompaniesHouseNumber = false;
model.CompaniesHouseNumber = "12345678";

GivenRegistrationIsInProgress(model.HasCompaniesHouseNumber, model.CompaniesHouseNumber);

var result = model.OnPost();
var result = await model.OnPost();
result.Should().BeOfType<RedirectToPageResult>();
(result as RedirectToPageResult)?.PageName.Should().Be("OrganisationIdentification");
}

[Fact]
public void OnPost_WhenModelStateIsValid_And_CompaniesNumber_Provided_ShouldRedirectToOrganisationName()
public async Task OnPost_WhenModelStateIsValid_And_CompaniesNumber_Provided_ShouldRedirectToOrganisationName()
{
var model = new CompanyHouseNumberQuestionModel(sessionMock.Object)
{
HasCompaniesHouseNumber = true,
CompaniesHouseNumber = "12345678"
};
var model = GivenCompaniesHouseQuestionModel();

model.HasCompaniesHouseNumber = true;
model.CompaniesHouseNumber = "12345678";

GivenRegistrationIsInProgress(model.HasCompaniesHouseNumber, model.CompaniesHouseNumber);

var result = model.OnPost();
organisationClientMock.Setup(o => o.LookupOrganisationAsync(string.Empty, It.IsAny<string>()))
.Throws(new ApiException(string.Empty, 404, string.Empty, null, null));

var profile = GivenProfileOnCompaniesHouse(organisationName: "Acme Ltd");
companiesHouseApiMock.Setup(ch => ch.GetProfile(model.CompaniesHouseNumber))
.ReturnsAsync(profile);

var result = await model.OnPost();
result.Should().BeOfType<RedirectToPageResult>();
(result as RedirectToPageResult)?.PageName.Should().Be("OrganisationName");
}

[Fact]
public void OnPost_WhenModelStateIsValidAndRedirectToSummary_ShouldRedirectToOrganisationDetailSummaryPage()
public async Task OnPost_WhenModelStateIsValidAndRedirectToSummary_ShouldRedirectToOrganisationDetailSummaryPage()
{
var model = new CompanyHouseNumberQuestionModel(sessionMock.Object)
{
HasCompaniesHouseNumber = true,
RedirectToSummary = true,
CompaniesHouseNumber = "123456"
};
var model = GivenCompaniesHouseQuestionModel();

model.HasCompaniesHouseNumber = true;
model.RedirectToSummary = true;
model.CompaniesHouseNumber = "123456";

GivenRegistrationIsInProgress(model.HasCompaniesHouseNumber, model.CompaniesHouseNumber);

var result = model.OnPost();
organisationClientMock.Setup(o => o.LookupOrganisationAsync(string.Empty, It.IsAny<string>()))
.Throws(new ApiException(string.Empty, 404, string.Empty, null, null));

var profile = GivenProfileOnCompaniesHouse(organisationName: "Acme Ltd");
companiesHouseApiMock.Setup(ch => ch.GetProfile(model.CompaniesHouseNumber))
.ReturnsAsync(profile);

var result = await model.OnPost();
result.Should().BeOfType<RedirectToPageResult>();
(result as RedirectToPageResult)?.PageName.Should().Be("OrganisationDetailsSummary");
}

[Fact]
public async Task OnPost_WhenModelStateIsValidAndOrganisationAlreadyExists_ShouldShowNotificationBanner()
{
var model = GivenCompaniesHouseQuestionModel();

model.HasCompaniesHouseNumber = true;
model.RedirectToSummary = true;
model.CompaniesHouseNumber = "123456";

GivenRegistrationIsInProgress(model.HasCompaniesHouseNumber, model.CompaniesHouseNumber);

var result = await model.OnPost();

tempDataServiceMock.Verify(api => api.Put(
FlashMessageTypes.Important,
CompanyHouseNumberQuestionModel.NotificationBannerCompanyAlreadyRegistered), Times.Once);
result.Should().BeOfType<PageResult>();
}

[Fact]
public async Task OnPost_WhenModelStateIsValidAndCompanyNotFoundAtComapniesHouse_ShouldShowNotificationBanner()
{
var model = GivenCompaniesHouseQuestionModel();

model.HasCompaniesHouseNumber = true;
model.RedirectToSummary = true;
model.CompaniesHouseNumber = "123456";

GivenRegistrationIsInProgress(model.HasCompaniesHouseNumber, model.CompaniesHouseNumber);

organisationClientMock.Setup(o => o.LookupOrganisationAsync(string.Empty, It.IsAny<string>()))
.Throws(new ApiException(string.Empty, 404, string.Empty, null, null));

var result = await model.OnPost();

tempDataServiceMock.Verify(api => api.Put(
FlashMessageTypes.Important,
CompanyHouseNumberQuestionModel.NotificationBannerCompanyNotFound), Times.Once);
result.Should().BeOfType<PageResult>();
}

private void GivenRegistrationIsInProgress(bool? hasNumber, string companyHouseNumber)
{
RegistrationDetails registrationDetails = DummyRegistrationDetails(hasNumber, companyHouseNumber);
sessionMock.Setup(s => s.Get<RegistrationDetails>(Session.RegistrationDetailsKey))
.Returns(registrationDetails);
}

private CompanyProfile GivenProfileOnCompaniesHouse(string organisationName = "")
{
return new CompanyProfile() { CompanyName = organisationName };
}

private CompanyHouseNumberQuestionModel GivenCompaniesHouseQuestionModel()
{
return new CompanyHouseNumberQuestionModel(sessionMock.Object,
companiesHouseApiMock.Object,
organisationClientMock.Object,
tempDataServiceMock.Object);
}
private static RegistrationDetails DummyRegistrationDetails(bool? hasNumber, string companyHouseNumber)
{
var registrationDetails = new RegistrationDetails
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Amazon;
using CO.CDP.OrganisationApp.Constants;
using CO.CDP.OrganisationApp.Models;
using CO.CDP.OrganisationApp.Pages.Registration;
using CO.CDP.OrganisationApp.ThirdPartyApiClients;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Amazon;
using Amazon.S3;
using CO.CDP.OrganisationApp.Constants;
using CO.CDP.OrganisationApp.Models;
using CO.CDP.OrganisationApp.Pages.Registration;
Expand All @@ -11,7 +9,6 @@
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.AspNetCore.Routing;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion.Internal;
using Moq;

namespace CO.CDP.OrganisationApp.Tests.Pages.Registration;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,24 +150,6 @@ public async Task OnPost_ShouldUpdateSupplierCompletedConnectedPerson_WhenNoConn
new(Guid.NewGuid(), ConnectedEntityType.Organisation, "e2", It.IsAny<Uri>()),
];

private static SupplierInformation SupplierInformationClientModel => new(
organisationName: "FakeOrg",
supplierType: SupplierType.Organisation,
operationTypes: null,
completedRegAddress: true,
completedPostalAddress: false,
completedVat: false,
completedWebsiteAddress: false,
completedEmailAddress: true,
completedQualification: false,
completedTradeAssurance: false,
completedOperationType: false,
completedLegalForm: false,
completedConnectedPerson: false,
tradeAssurances: null,
legalForm: null,
qualifications: null);

private static CO.CDP.Organisation.WebApiClient.Organisation OrganisationClientModel(Guid id) =>
new(
additionalIdentifiers: [new Identifier(id: "FakeId", legalName: "FakeOrg", scheme: "VAT", uri: null)],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using CO.CDP.Organisation.WebApiClient;
using CO.CDP.OrganisationApp.Pages.Supplier;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using Moq;
using OrganisationWebApiClient = CO.CDP.Organisation.WebApiClient;

namespace CO.CDP.OrganisationApp.Tests.Pages.Supplier.ConnectedEntity;

Expand Down Expand Up @@ -110,38 +108,4 @@ private ConnectedEntityState DummyConnectedPersonDetails()

return connectedPersonDetails;
}

private static List<ConnectedEntityLookup> ConnectedEntities =>
[
new(Guid.NewGuid(), ConnectedEntityType.Organisation, "e1", It.IsAny<Uri>()),
new(Guid.NewGuid(), ConnectedEntityType.Organisation, "e2", It.IsAny<Uri>()),
];

private static SupplierInformation SupplierInformationClientModel => new(
organisationName: "FakeOrg",
supplierType: SupplierType.Organisation,
operationTypes: null,
completedRegAddress: true,
completedPostalAddress: false,
completedVat: false,
completedWebsiteAddress: false,
completedEmailAddress: true,
completedQualification: false,
completedTradeAssurance: false,
completedOperationType: false,
completedLegalForm: false,
completedConnectedPerson: false,
tradeAssurances: null,
legalForm: null,
qualifications: null);

private static OrganisationWebApiClient.Organisation OrganisationClientModel(Guid id) =>
new(
additionalIdentifiers: [new Identifier(id: "FakeId", legalName: "FakeOrg", scheme: "VAT", uri: null)],
addresses: null,
contactPoint: new ContactPoint(email: "[email protected]", name: null, telephone: null, url: new Uri("https://xyz.com")),
id: id,
identifier: null,
name: "Test Org",
roles: [PartyRole.Supplier]);
}
Loading

0 comments on commit 9666446

Please sign in to comment.