From 2741a4a4e62bd1ebfc8ac52837e3bfc4e4ee1cdf Mon Sep 17 00:00:00 2001 From: Dharm Date: Tue, 10 Dec 2024 12:15:38 +0000 Subject: [PATCH] Update the tenant/lookup endpoint to return the organisation type --- Frontend/CO.CDP.OrganisationApp.Tests/AuthorizationTests.cs | 1 + Frontend/CO.CDP.OrganisationApp.Tests/LocalizationTests.cs | 6 ++++-- .../CO.CDP.OrganisationApp.Tests/UserInfoServiceTest.cs | 5 ++++- .../CO.CDP.Organisation.Authority.Tests/TokenServiceTest.cs | 1 + .../DatabasePersonTenantLookupTest.cs | 3 +++ .../DatabaseTenantRepository.cs | 1 + .../TenantLookup.cs | 1 + Services/CO.CDP.OrganisationInformation/TenantLookup.cs | 2 ++ Services/CO.CDP.Tenant.WebApi.Tests/Api/TenantLookupTest.cs | 1 + .../UseCase/LookupTenantUseCaseTest.cs | 2 ++ 10 files changed, 20 insertions(+), 3 deletions(-) diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/AuthorizationTests.cs b/Frontend/CO.CDP.OrganisationApp.Tests/AuthorizationTests.cs index 86ad634f6..21ca88909 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/AuthorizationTests.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/AuthorizationTests.cs @@ -32,6 +32,7 @@ private HttpClient BuildHttpClient(List userOrganisationScopes, List s.Get(Session.RegistrationDetailsKey)) - .Returns(new RegistrationDetails() { OrganisationType = OrganisationType.Supplier, OrganisationScheme = "Whatever" }); + .Returns(new RegistrationDetails() { OrganisationType = Constants.OrganisationType.Supplier, OrganisationScheme = "Whatever" }); var antiforgery = new Mock(); @@ -60,7 +60,8 @@ private HttpClient BuildHttpClient() services.AddSingleton(antiforgery.Object); services.AddSingleton(tenantClient.Object); services.AddTransient(); - services.Configure(OpenIdConnectDefaults.AuthenticationScheme, options => { + services.Configure(OpenIdConnectDefaults.AuthenticationScheme, options => + { options.ClientId = "123"; options.Authority = "https://whatever"; }); @@ -189,6 +190,7 @@ public async Task OrganisationNamePage_DisplaysErrorMessageCorrectly_WhenLanguag new UserOrganisation( id: Guid.NewGuid(), name: "Acme Ltd", + type: Tenant.WebApiClient.OrganisationType.Organisation, roles: [PartyRole.Tenderer], pendingRoles: [], scopes: ["ADMIN"], diff --git a/Frontend/CO.CDP.OrganisationApp.Tests/UserInfoServiceTest.cs b/Frontend/CO.CDP.OrganisationApp.Tests/UserInfoServiceTest.cs index 1f76df8ac..5a58e660b 100644 --- a/Frontend/CO.CDP.OrganisationApp.Tests/UserInfoServiceTest.cs +++ b/Frontend/CO.CDP.OrganisationApp.Tests/UserInfoServiceTest.cs @@ -3,6 +3,7 @@ using FluentAssertions; using Microsoft.AspNetCore.Http; using Moq; +using OrganisationType = CO.CDP.Tenant.WebApiClient.OrganisationType; namespace CO.CDP.OrganisationApp.Tests; @@ -242,11 +243,13 @@ private static UserOrganisation GivenUserOrganisation( string? name = null, ICollection? scopes = null, ICollection? roles = null, - ICollection? pendingRoles = null) + ICollection? pendingRoles = null, + OrganisationType type = OrganisationType.Organisation) { return new UserOrganisation( id: id ?? Guid.NewGuid(), name: name, + type: type, pendingRoles: pendingRoles, roles: roles, scopes: scopes, diff --git a/Services/CO.CDP.Organisation.Authority.Tests/TokenServiceTest.cs b/Services/CO.CDP.Organisation.Authority.Tests/TokenServiceTest.cs index 898037b1f..65c4543e8 100644 --- a/Services/CO.CDP.Organisation.Authority.Tests/TokenServiceTest.cs +++ b/Services/CO.CDP.Organisation.Authority.Tests/TokenServiceTest.cs @@ -257,6 +257,7 @@ private TenantLookup GetTenantLookup(int numberOfTenant = 1, int numberOfOrgsPer { Id = Guid.NewGuid(), Name = $"Test Org{x}{y}", + Type = OrganisationInformation.OrganisationType.Organisation, Roles = [OrganisationInformation.PartyRole.Buyer], PendingRoles = [], Scopes = ["Admin"] diff --git a/Services/CO.CDP.OrganisationInformation.Persistence.Tests/DatabasePersonTenantLookupTest.cs b/Services/CO.CDP.OrganisationInformation.Persistence.Tests/DatabasePersonTenantLookupTest.cs index b7d40e1fe..398ccc5ed 100644 --- a/Services/CO.CDP.OrganisationInformation.Persistence.Tests/DatabasePersonTenantLookupTest.cs +++ b/Services/CO.CDP.OrganisationInformation.Persistence.Tests/DatabasePersonTenantLookupTest.cs @@ -81,6 +81,7 @@ public async Task ItFindsThePersonWithAllTheirTenants() { Id = acmeCoOrganisation.Guid, Name = acmeCoOrganisation.Name, + Type = acmeCoOrganisation.Type, Roles = acmeCoOrganisation.Roles, PendingRoles = acmeCoOrganisation.PendingRoles, Scopes = adminPersonScopes @@ -113,6 +114,7 @@ public async Task ItFindsThePersonWithAllTheirTenants() { Id = widgetCoOrganisation.Guid, Name = widgetCoOrganisation.Name, + Type = widgetCoOrganisation.Type, Roles = widgetCoOrganisation.Roles, PendingRoles = widgetCoOrganisation.PendingRoles, Scopes = userPersonScopes @@ -159,6 +161,7 @@ public async Task ItFindsThePersonWithAllTheirTenants() { Id = acmeCoOrganisation.Guid, Name = acmeCoOrganisation.Name, + Type = acmeCoOrganisation.Type, Roles = acmeCoOrganisation.Roles, PendingRoles = acmeCoOrganisation.PendingRoles, Scopes = [] diff --git a/Services/CO.CDP.OrganisationInformation.Persistence/DatabaseTenantRepository.cs b/Services/CO.CDP.OrganisationInformation.Persistence/DatabaseTenantRepository.cs index a90697f34..befd9996e 100644 --- a/Services/CO.CDP.OrganisationInformation.Persistence/DatabaseTenantRepository.cs +++ b/Services/CO.CDP.OrganisationInformation.Persistence/DatabaseTenantRepository.cs @@ -51,6 +51,7 @@ public void Save(Tenant tenant) { Id = o.Guid, Name = o.Name, + Type = o.Type, Roles = o.Roles, PendingRoles = o.PendingRoles, // ReSharper disable once NullCoalescingConditionIsAlwaysNotNullAccordingToAPIContract diff --git a/Services/CO.CDP.OrganisationInformation.Persistence/TenantLookup.cs b/Services/CO.CDP.OrganisationInformation.Persistence/TenantLookup.cs index dd534da4b..e3f04fcd5 100644 --- a/Services/CO.CDP.OrganisationInformation.Persistence/TenantLookup.cs +++ b/Services/CO.CDP.OrganisationInformation.Persistence/TenantLookup.cs @@ -25,6 +25,7 @@ public class Organisation { public required Guid Id { get; init; } public required string Name { get; init; } + public required OrganisationType Type { get; init; } public required List Roles { get; init; } public required List PendingRoles { get; init; } public required List Scopes { get; init; } diff --git a/Services/CO.CDP.OrganisationInformation/TenantLookup.cs b/Services/CO.CDP.OrganisationInformation/TenantLookup.cs index c1aeba0ec..bab0c95e8 100644 --- a/Services/CO.CDP.OrganisationInformation/TenantLookup.cs +++ b/Services/CO.CDP.OrganisationInformation/TenantLookup.cs @@ -41,6 +41,8 @@ public record UserOrganisation /// "Acme Group Ltd" public required string Name { get; init; } + public required OrganisationType Type { get; init; } + public required List Roles { get; init; } public required List PendingRoles { get; init; } diff --git a/Services/CO.CDP.Tenant.WebApi.Tests/Api/TenantLookupTest.cs b/Services/CO.CDP.Tenant.WebApi.Tests/Api/TenantLookupTest.cs index 41e447036..3bb7563f1 100644 --- a/Services/CO.CDP.Tenant.WebApi.Tests/Api/TenantLookupTest.cs +++ b/Services/CO.CDP.Tenant.WebApi.Tests/Api/TenantLookupTest.cs @@ -97,6 +97,7 @@ private static TenantLookup GivenTenantLookup() { Id = Guid.Parse("dfd0c5d3-0740-4be4-aa42-e42ec9c00bad"), Name = "Acme Ltd", + Type = OrganisationType.Organisation, Roles = [PartyRole.Tenderer], PendingRoles = [], Scopes = ["ADMIN"], diff --git a/Services/CO.CDP.Tenant.WebApi.Tests/UseCase/LookupTenantUseCaseTest.cs b/Services/CO.CDP.Tenant.WebApi.Tests/UseCase/LookupTenantUseCaseTest.cs index 1505c9016..34c89a6f1 100644 --- a/Services/CO.CDP.Tenant.WebApi.Tests/UseCase/LookupTenantUseCaseTest.cs +++ b/Services/CO.CDP.Tenant.WebApi.Tests/UseCase/LookupTenantUseCaseTest.cs @@ -54,6 +54,7 @@ public async Task Execute_IfTenantIsFound_ReturnsTenant() { Id = Guid.Parse("dfd0c5d3-0740-4be4-aa42-e42ec9c00bad"), Name = "Acme Ltd", + Type= OrganisationType.Organisation, Roles = [PartyRole.Tenderer], PendingRoles = [PartyRole.Buyer], Scopes = ["ADMIN"] @@ -89,6 +90,7 @@ public async Task Execute_IfTenantIsFound_ReturnsTenant() { Id = Guid.Parse("dfd0c5d3-0740-4be4-aa42-e42ec9c00bad"), Name = "Acme Ltd", + Type = OrganisationType.Organisation, Roles = [PartyRole.Tenderer], PendingRoles = [PartyRole.Buyer], Scopes = ["ADMIN"],