Skip to content

Commit

Permalink
DP-724: Expose PendingRoles in the Organisation response
Browse files Browse the repository at this point in the history
  • Loading branch information
jakzal committed Oct 17, 2024
1 parent 4a44dd7 commit 02dc5e2
Show file tree
Hide file tree
Showing 28 changed files with 104 additions and 85 deletions.
17 changes: 9 additions & 8 deletions Frontend/CO.CDP.OrganisationApp.Tests/AuthorizationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,15 @@ [ organisation ]
organisationClient.Setup(client => client.GetOrganisationAsync(testOrganisationId))
.ReturnsAsync(
new CO.CDP.Organisation.WebApiClient.Organisation(
[],
[],
null,
new ContactPoint("[email protected]", "Contact", "123", new Uri("http://whatever")),
testOrganisationId,
new Identifier("asd", "asd", "asd", new Uri("http://whatever")),
"Org name",
[ CO.CDP.Organisation.WebApiClient.PartyRole.Supplier, CO.CDP.Organisation.WebApiClient.PartyRole.Tenderer ]
additionalIdentifiers: [],
addresses: [],
approvedOn: null,
contactPoint: new ContactPoint("[email protected]", "Contact", "123", new Uri("http://whatever")),
id: testOrganisationId,
identifier: new Identifier("asd", "asd", "asd", new Uri("http://whatever")),
name: "Org name",
roles: [ Organisation.WebApiClient.PartyRole.Supplier, Organisation.WebApiClient.PartyRole.Tenderer ],
details: new Details(approval: null, pendingRoles: [])
)
);

Expand Down
2 changes: 1 addition & 1 deletion Frontend/CO.CDP.OrganisationApp.Tests/FormsEngineTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ public async Task GetFormSectionAsync_ShouldFetchChoicesFromCustomChoiceProvider
null
));
_organisationClientMock.Setup(c => c.GetOrganisationAsync(organisationId))
.ReturnsAsync(new Organisation.WebApiClient.Organisation([], [], null, null, organisationId, null, "User's current organisation", []));
.ReturnsAsync(new Organisation.WebApiClient.Organisation(additionalIdentifiers: [], addresses: [], approvedOn: null, contactPoint: null, id: organisationId, identifier: null, name: "User's current organisation", roles: [], details: new Details(approval: null, pendingRoles: [])));
_userInfoServiceMock.Setup(u => u.GetOrganisationId()).Returns(organisationId);
_tempDataServiceMock.Setup(t => t.Peek<SectionQuestionsResponse>(sessionKey))
.Returns((SectionQuestionsResponse?)null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public async Task OnGet_ValidSession_ReturnsOrganisationDetailsAsync()

private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel(Guid? id)
{
return new CO.CDP.Organisation.WebApiClient.Organisation(null, null,null, new ContactPoint("Main Contact", "[email protected]", "123456789", null), id!.Value, null, null, []);
return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: null,approvedOn: null, contactPoint: new ContactPoint("Main Contact", "[email protected]", "123456789", null), id: id ?? Guid.NewGuid(), identifier: null, name: null, roles: [], details: new Details(approval: null, pendingRoles: []));
}

private OrganisationEmailModel GivenOrganisationEmailModel()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
using Xunit;
using Moq;
using FluentAssertions;
using CO.CDP.Organisation.WebApiClient;
using CO.CDP.OrganisationApp.Pages.Organisation;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CO.CDP.OrganisationApp.Tests.Pages;
using Moq;

public class OrganisationIdentificationModelTest
{
private readonly Mock<IOrganisationClient> _organisationClientMock;
private readonly OrganisationIdentificationModel _pageModel;

public OrganisationIdentificationModelTest()
{
{
_organisationClientMock = new Mock<IOrganisationClient>();

_pageModel = new OrganisationIdentificationModel(_organisationClientMock.Object)
{
Id = Guid.NewGuid(),
Expand All @@ -28,32 +23,26 @@ public OrganisationIdentificationModelTest()
[Fact]
public async Task OnGet_Should_ReturnPageResult_When_OrganisationIsValid()
{

var id = Guid.NewGuid();
_pageModel.Id = id;
_pageModel.CharityCommissionEnglandWalesNumber = "Charity Org";
_organisationClientMock.Setup(x => x.GetOrganisationAsync(It.IsAny<Guid>()))
.ReturnsAsync(GivenOrganisationClientModel(id));


var result = await _pageModel.OnGet();


result.Should().BeOfType<PageResult>();
_pageModel.CharityCommissionEnglandWalesNumber.Should().Be("Charity Org");
}

[Fact]
public async Task OnGet_Should_RedirectToPageNotFound_When_OrganisationIsNotFound()
{

_organisationClientMock.Setup(x => x.GetOrganisationAsync(It.IsAny<Guid>()))
.ReturnsAsync((Organisation?)null);


var result = await _pageModel.OnGet();


result.Should().BeOfType<RedirectResult>()
.Which.Url.Should().Be("/page-not-found");
}
Expand Down Expand Up @@ -105,7 +94,7 @@ public async Task OnPost_Should_RedirectToPageNotFound_When_OrganisationIsNotFou
.Which.Url.Should().Be("/page-not-found");
}

private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel(Guid? id)
private static Organisation GivenOrganisationClientModel(Guid? id)
{
var identifier = new Identifier("asd", "asd", "asd", new Uri("http://whatever"));
var additionalIdentifiers = new List<Identifier>
Expand All @@ -118,6 +107,6 @@ private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationCl
)
};

return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers, null, null, null, id!.Value, identifier, "Test Org", []);
return new Organisation(additionalIdentifiers: additionalIdentifiers, addresses: null, approvedOn: null, contactPoint: null, id: id ?? Guid.NewGuid(), identifier: identifier, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,9 @@ public async Task OnGet_ValidSession_ReturnsOrganisationDetailsAsync()
organisationClientMock.Verify(c => c.GetOrganisationAsync(id), Times.Once);
}


private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel(Guid? id)
{
return new CO.CDP.Organisation.WebApiClient.Organisation(null, null,null, null, id!.Value, null, "Test Org", []);
return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: null,approvedOn: null, contactPoint: null, id: id ?? Guid.NewGuid(), identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}

private OrganisationNameModel GivenOrganisationNameModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ public async Task OnPost_WhenValidModel_ShouldSaveRegistratedAddress()
var result = await _model.OnPost();

result.Should().BeOfType<RedirectToPageResult>()
.Which.PageName.Should().Be("OrganisationOverview");
}
.Which.PageName.Should().Be("OrganisationOverview");
}

[Fact]
public async Task OnGet_ValidSession_ReturnsRegistrationDetails()
Expand Down Expand Up @@ -169,7 +169,7 @@ private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationCl
streetAddress: "1 street lane",
type: CDP.Organisation.WebApiClient.AddressType.Registered));

return new CO.CDP.Organisation.WebApiClient.Organisation(null, addresses,null, null, id!.Value, null, null, []);
return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: addresses,approvedOn: null, contactPoint: null, id: id ?? Guid.NewGuid(), identifier: null, name: null, roles: [], details: new Details(approval: null, pendingRoles: []));
}

private OrganisationRegisteredAddressModel GivenOrganisationAddressModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public async Task OnGet_PageNotFound()

private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel(Guid? id)
{
return new CO.CDP.Organisation.WebApiClient.Organisation(null, null,null, null, id!.Value, null, "Test Org", []);
return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: null,approvedOn: null, contactPoint: null, id: id ?? Guid.NewGuid(), identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ private RegistrationDetails DummyRegistrationDetails()

private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel()
{
return new CO.CDP.Organisation.WebApiClient.Organisation(null, null, null, null, _organisationId, null, "Test Org", []);
return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: null, approvedOn: null, contactPoint: null, id: _organisationId, identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}

private OrganisationDetailsSummaryModel GivenOrganisationDetailModel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public static class OrganisationEntityFactory
{
public static OrganisationWebApiClient.Organisation GivenClientModel()
{
return new OrganisationWebApiClient.Organisation(null, null, null, null, Guid.NewGuid(), null, "Test Org", []);
return new OrganisationWebApiClient.Organisation(additionalIdentifiers: null, addresses: null, approvedOn: null, contactPoint: null, id: Guid.NewGuid(), identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}

public static ProblemDetails GivenProblemDetails(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void OnGet_WhenValidSession_ShouldSaveRegistrationDetails()

case "GB-UKPRN":
model.UKLearningProviderReferenceNumber.Should().Be(registrationDetails.OrganisationIdentificationNumber);
break;
break;
}

}
Expand Down Expand Up @@ -257,7 +257,7 @@ public async Task OnPost_WhenOrganisationTypeIsUKPRNAndUKLearningProviderReferen

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

[Fact]
public async Task OnPost_WhenModelStateIsValid_ShouldRedirectToOrganisationName()
Expand Down Expand Up @@ -294,7 +294,7 @@ public async Task OnPost_WhenSchemeNotOtherAndOrganisationExistsInOganisationSer
{
var model = new OrganisationIdentificationModel(sessionMock.Object, organisationClientMock.Object, _pponClientMock.Object)
{
OrganisationScheme = "JE-FSC",
OrganisationScheme = "JE-FSC",
RedirectToSummary = true
};
GivenRegistrationIsInProgress();
Expand All @@ -313,7 +313,7 @@ public async Task OnPost_WhenSchemeNotOtherAndIdentifierExistsInEntityVerificati
{
var model = new OrganisationIdentificationModel(sessionMock.Object, organisationClientMock.Object, _pponClientMock.Object)
{
OrganisationScheme = "JE-FSC",
OrganisationScheme = "JE-FSC",
RedirectToSummary = true
};
GivenRegistrationIsInProgress();
Expand All @@ -332,7 +332,7 @@ public async Task OnPost_WhenSchemeNotOtherAndEntityVerificationServiceOffLine_S
{
var model = new OrganisationIdentificationModel(sessionMock.Object, organisationClientMock.Object, _pponClientMock.Object)
{
OrganisationScheme = "JE-FSC",
OrganisationScheme = "JE-FSC",
RedirectToSummary = true
};

Expand All @@ -355,7 +355,7 @@ public async Task OnPost_WhenSchemeNotOtherAndEntityVerificationServiceOffLine_S
[InlineData("JE-FSC", "JFSC123")]
[InlineData("IM-CR", "IMCR123")]
[InlineData("GB-NHS", "STUVWX")]
[InlineData("GB-UKPRN", "PRN1234")]
[InlineData("GB-UKPRN", "PRN1234")]
public async Task OnPost_WhenModelStateIsValid_ShouldStoreOrganisationTypeAndIdentificationNumberInSession(string organisationType, string identificationNumber)
{
var model = new OrganisationIdentificationModel(sessionMock.Object, organisationClientMock.Object, _pponClientMock.Object)
Expand Down Expand Up @@ -410,7 +410,7 @@ private static void SetIdentificationNumber(OrganisationIdentificationModel mode

private static OrganisationWebApiClient.Organisation GivenOrganisationClientModel()
{
return new OrganisationWebApiClient.Organisation(null, null, null, null, _organisationId, null, "Test Org", []);
return new OrganisationWebApiClient.Organisation(additionalIdentifiers: null, addresses: null, approvedOn: null, contactPoint: null, id: _organisationId, identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}

private static ICollection<EntityVerificationClient.Identifier> GivenEntityVerificationIdentifiers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,12 @@ private static CO.CDP.Organisation.WebApiClient.Organisation OrganisationClientM
new(
additionalIdentifiers: [new Identifier(id: "FakeId", legalName: "FakeOrg", scheme: "VAT", uri: null)],
addresses: null,
null,
approvedOn: 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]);
roles: [PartyRole.Supplier],
details: new Details(approval: null, pendingRoles: [])
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,6 @@ private void SetFutureDate()

private static OrganisationWebApiClient.Organisation GivenOrganisationClientModel(Guid? id)
{
return new OrganisationWebApiClient.Organisation(null, null, null, null, id!.Value, null, "Test Org", []);
return new OrganisationWebApiClient.Organisation(additionalIdentifiers: null, addresses: null, approvedOn: null, contactPoint: null, id: id ?? Guid.NewGuid(), identifier: null, name: "Test Org", roles: [], details: new OrganisationWebApiClient.Details(approval: null, pendingRoles: []));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ public void OnPost_UpdatesLawRegisteredInTempData_AndRedirects()

private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel(Guid? id)
{
return new CO.CDP.Organisation.WebApiClient.Organisation(null, null, null, null, id!.Value, null, "Test Org", []);
return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: null, approvedOn: null, contactPoint: null, id: id ?? Guid.NewGuid(), identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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 LegalForm = CO.CDP.OrganisationApp.Pages.Supplier.LegalForm;

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

Expand Down Expand Up @@ -108,6 +110,6 @@ public void OrganisationLegalForm_ShouldReturnCorrectDictionary()

private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel(Guid? id)
{
return new CO.CDP.Organisation.WebApiClient.Organisation(null, null, null, null, id!.Value, null, "Test Org", []);
return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: null, approvedOn: null, contactPoint: null, id: id ?? Guid.NewGuid(), identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ public static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationCli
new Address(countryName: "United Kingdom", country: "GB", locality: "London", postalCode: "L1", region: "South", streetAddress: "1 London Street", type: AddressType.Registered),
new Address(countryName: "France", country: "FR", locality: "Paris", postalCode: "F1", region: "North", streetAddress: "1 Paris Street", type: AddressType.Postal)
],
null,
approvedOn: null,
contactPoint: new ContactPoint(email: "[email protected]", name: "fakecontact", telephone: "0123456789", url: new Uri("https://test.com")),
id: id,
identifier: null,
name: "Test Org",
roles: [PartyRole.Supplier]
roles: [PartyRole.Supplier],
details: new Details(approval: null, pendingRoles: [])
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,12 @@ private static CO.CDP.Organisation.WebApiClient.Organisation OrganisationClientM
new(
additionalIdentifiers: [new Identifier(id: "FakeId", legalName: "FakeOrg", scheme: "VAT", uri: null)],
addresses: null,
null,
approvedOn: 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]);
roles: [PartyRole.Supplier],
details: new Details(approval: null, pendingRoles: [])
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public SupplierVatModelQuestionTest()
_organisationClientMock = new Mock<IOrganisationClient>();
_pponClientMock = new Mock<IPponClient>();
_model = new SupplierVatQuestionModel(_organisationClientMock.Object, _pponClientMock.Object, contextAccessor.Object);

_organisationClientMock.Setup(api => api.LookupOrganisationAsync(It.IsAny<string>(), It.IsAny<string>()))
.ThrowsAsync(new CO.CDP.Organisation.WebApiClient.ApiException("Organisation does not exist", 404, "", null, null));
_pponClientMock.Setup(api => api.GetIdentifiersAsync(It.IsAny<string>()))
Expand Down Expand Up @@ -117,8 +117,8 @@ public async Task OnPost_WhenNoChangeToVatNumber_ShouldNotUpdateOrganisationAndR
_organisationClientMock.Setup(client => client.GetOrganisationAsync(id))
.ReturnsAsync(fakeOrg);

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

_organisationClientMock.Verify(o => o.UpdateOrganisationAsync(It.IsAny<Guid>(), It.IsAny<UpdatedOrganisation>()), Times.Never);
_organisationClientMock.Verify(o => o.UpdateSupplierInformationAsync(It.IsAny<Guid>(),
It.Is<UpdateSupplierInformation>(u => u.Type == SupplierInformationUpdateType.CompletedVat)), Times.Never);
Expand Down Expand Up @@ -220,7 +220,7 @@ public async Task OnPost_OrganisationNotFound_ReturnsRedirectToPageNotFound()

private static CO.CDP.Organisation.WebApiClient.Organisation GivenOrganisationClientModel()
{
return new CO.CDP.Organisation.WebApiClient.Organisation(null, null, null, null, _organisationId, null, "Test Org", []);
return new CO.CDP.Organisation.WebApiClient.Organisation(additionalIdentifiers: null, addresses: null, approvedOn: null, contactPoint: null, id: _organisationId, identifier: null, name: "Test Org", roles: [], details: new Details(approval: null, pendingRoles: []));
}

private static ICollection<EntityVerificationClient.Identifier> GivenEntityVerificationIdentifiers()
Expand Down
Loading

0 comments on commit 02dc5e2

Please sign in to comment.