Skip to content

Commit

Permalink
dp-836 create consortium using create organisation endpoint (#1018)
Browse files Browse the repository at this point in the history
* dp-836 create consortium using create organisation endpoint

* Fixed unit test

* PR update

* remove warning
  • Loading branch information
dharmverma authored Dec 6, 2024
1 parent 3d86871 commit 8da7808
Show file tree
Hide file tree
Showing 70 changed files with 2,306 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public async Task ShouldRedirectToSupplierToBuyerOrganisationType_WhenOrganisati

var initialState = new SupplierToBuyerDetails
{
OrganisationType = OrganisationType.Supplier
OrganisationType = Constants.OrganisationType.Supplier
};
tempDataServiceMock
.Setup(t => t.PeekOrDefault<SupplierToBuyerDetails>(It.IsAny<string>()))
Expand All @@ -39,7 +39,7 @@ public async Task ShouldRedirectToSupplierToBuyerOrganisationType_WhenOrganisati
var result = await _model.OnGet(orgGuid);

tempDataServiceMock.Verify(t => t.Put(It.IsAny<string>(), It.Is<SupplierToBuyerDetails>(state =>
state.OrganisationType == OrganisationType.Supplier
state.OrganisationType == Constants.OrganisationType.Supplier
)), Times.Once);

var redirectResult = result.Should().BeOfType<RedirectToPageResult>().Subject;
Expand Down Expand Up @@ -78,7 +78,7 @@ public async Task ShouldUpdateStateCorrectly_WhenOrganisationIsTenderer()
await _model.OnGet(orgGuid);

tempDataServiceMock.Verify(t => t.Put(It.IsAny<string>(), It.Is<SupplierToBuyerDetails>(state =>
state.OrganisationType == OrganisationType.Supplier
state.OrganisationType == Constants.OrganisationType.Supplier
)), Times.Once);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public void OnGet_ShouldReturnPage_WhenStateIsValid()
{
var supplierToBuyerDetails = new SupplierToBuyerDetails
{
OrganisationType = OrganisationType.Supplier,
OrganisationType = Constants.OrganisationType.Supplier,
BuyerOrganisationType = "CentralGovernment",
BuyerOrganisationOtherValue = null,
Devolved = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ private RegistrationDetails DummyRegistrationDetails()
OrganisationName = "TestOrg",
OrganisationScheme = "TestType",
OrganisationEmailAddress = "[email protected]",
OrganisationType = OrganisationType.Supplier,
OrganisationType = Constants.OrganisationType.Supplier,
};

return registrationDetails;
Expand Down
3 changes: 1 addition & 2 deletions Frontend/CO.CDP.OrganisationApp/Pages/ContactUs.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
using CO.CDP.Localization;
using CO.CDP.Organisation.WebApiClient;
using CO.CDP.Mvc.Validation;
using CO.CDP.Organisation.WebApiClient;
using CO.CDP.OrganisationApp.Constants;
using CO.CDP.OrganisationApp.Models;
using CO.CDP.OrganisationApp.WebApiClients;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using CO.CDP.OrganisationApp.Models;

namespace CO.CDP.OrganisationApp.Pages;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public async Task<IActionResult> OnGet(Guid id)
if (!orgInfo.Roles.Contains(PartyRole.Buyer))
{
var state = tempDataService.PeekOrDefault<SupplierToBuyerDetails>(SupplierToBuyerStateKey);
state.OrganisationType = orgInfo.IsTenderer() ? OrganisationType.Supplier : OrganisationType.Buyer;
state.OrganisationType = orgInfo.IsTenderer() ? Constants.OrganisationType.Supplier : Constants.OrganisationType.Buyer;

tempDataService.Put(SupplierToBuyerStateKey, state);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ public async Task<IActionResult> OnPost()
legalName: details.OrganisationName,
scheme: details.OrganisationScheme),
name: details.OrganisationName,
type: OrganisationWebApiClient.OrganisationType.Organisation,
roles: [details.OrganisationType!.Value.AsPartyRole()],
personId: user.PersonId.Value
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Model.RedirectToSummary = true;
}

string IsSelected(OrganisationType radioValue)
string IsSelected(Constants.OrganisationType radioValue)
{
return Model.OrganisationType == radioValue ? "checked='checked'" : string.Empty;
}
Expand Down Expand Up @@ -54,8 +54,8 @@
<div class="govuk-radios" data-module="govuk-radios">
<div class="govuk-radios__item">
<input class="govuk-radios__input" id="buyer" name="OrganisationType"
type="radio" value="@OrganisationType.Buyer"
aria-describedby="buyer-hint" @IsSelected(OrganisationType.Buyer)>
type="radio" value="@Constants.OrganisationType.Buyer"
aria-describedby="buyer-hint" @IsSelected(Constants.OrganisationType.Buyer)>
<label class="govuk-label govuk-radios__label" for="buyer">
@StaticTextResource.OrganisationRegistration_OrganisationType_Buyer
</label>
Expand All @@ -66,8 +66,8 @@

<div class="govuk-radios__item">
<input class="govuk-radios__input" id="supplier" name="OrganisationType"
type="radio" value="@OrganisationType.Supplier"
aria-describedby="supplier-hint" @IsSelected(OrganisationType.Supplier)>
type="radio" value="@Constants.OrganisationType.Supplier"
aria-describedby="supplier-hint" @IsSelected(Constants.OrganisationType.Supplier)>
<label class="govuk-label govuk-radios__label" for="supplier">
@StaticTextResource.OrganisationRegistration_OrganisationType_Supplier
</label>
Expand Down
5 changes: 4 additions & 1 deletion Libraries/CO.CDP.Authentication.Tests/ApiKeyValidatorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,10 @@ public async Task Validate_ValidApiKeyWithOrganisation_ReturnsTrue()
Name = "FTS",
Key = ValidApiKey,
OrganisationId = 42,
Organisation = new Organisation { Guid = orgId, Name = "", Tenant = new Tenant { Guid = Guid.NewGuid(), Name = "" } },
Organisation = new Organisation {
Guid = orgId, Name = "",
Type = OrganisationInformation.OrganisationType.Organisation,
Tenant = new Tenant { Guid = Guid.NewGuid(), Name = "" } },
Scopes = ["ADMIN"] });

var (valid, organisation, scopes) = await _validator.Validate(ValidApiKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public async Task ItTalksToTheOrganisationApi()
contactPoint: contactPoint,
identifier: identifier,
name: "New Organisation",
type: OrganisationType.Organisation,
roles: roles
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public static Organisation CreateOrganisation(
Id = 1,
Guid = Guid.NewGuid(),
Name = "Test Organisation",
Type = OrganisationInformation.OrganisationType.Organisation,
Tenant = new Tenant { Guid = Guid.NewGuid(), Name = "TestTenant" },
Addresses = new List<OrganisationAddress>
{
Expand Down Expand Up @@ -141,7 +142,7 @@ public static BasicInformation CreateMockBasicInformation()
VatNumber = "VAT123456",
WebsiteAddress = "http://example.com",
EmailAddress = "[email protected]",
OrganisationType = OrganisationType.Supplier,
OrganisationType = Model.OrganisationType.Supplier,
LegalForm = new BasicLegalForm
{
RegisteredLegalForm = "Private Limited",
Expand Down
1 change: 1 addition & 0 deletions Services/CO.CDP.DataSharing.WebApi.Tests/EntityFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ public static Organisation GivenOrganisation(
{
Guid = theGuid,
Name = theName,
Type = OrganisationInformation.OrganisationType.Organisation,
Tenant = tenant ?? GivenTenant(name: theName),

Identifiers = identifiers ??
Expand Down
4 changes: 2 additions & 2 deletions Services/CO.CDP.DataSharing.WebApi/DataService/DataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public static BasicInformation MapToBasicInformation(Organisation organisation)
: null;

var organisationType = organisation.Roles.Contains(PartyRole.Tenderer)
? OrganisationType.Supplier
: OrganisationType.Buyer;
? Model.OrganisationType.Supplier
: Model.OrganisationType.Buyer;

return new BasicInformation
{
Expand Down
15 changes: 10 additions & 5 deletions Services/CO.CDP.DataSharing.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using System.Globalization;
using System.Reflection;

Expand Down Expand Up @@ -41,14 +42,18 @@
options.RequestCultureProviders.Insert(0, new AcceptLanguageHeaderRequestCultureProvider());
});

builder.Services.AddHealthChecks()
.AddNpgSql(ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase"));

builder.Services.AddTransient(typeof(LocalizedPropertyResolver<,>));
builder.Services.AddAutoMapper(typeof(DataSharingProfile));

builder.Services.AddDbContext<OrganisationInformationContext>(o =>
o.UseNpgsql(ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase")));
var connectionString = ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase");
builder.Services.AddHealthChecks().AddNpgSql(connectionString);
builder.Services.AddSingleton(new NpgsqlDataSourceBuilder(connectionString).MapEnums().Build());
builder.Services.AddDbContext<OrganisationInformationContext>((sp, options) =>
{
var dataSource = sp.GetRequiredService<NpgsqlDataSource>();
options.UseNpgsql(dataSource);
});

builder.Services.AddScoped<IDataService, DataService>();
builder.Services.AddScoped<IPdfGenerator, PdfGenerator>();
builder.Services.AddScoped<IClaimService, ClaimService>();
Expand Down
15 changes: 10 additions & 5 deletions Services/CO.CDP.Forms.WebApi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using Microsoft.AspNetCore.Localization;
using Microsoft.AspNetCore.Mvc.Localization;
using Microsoft.EntityFrameworkCore;
using Npgsql;
using System.Globalization;
using System.Reflection;

Expand Down Expand Up @@ -40,16 +41,20 @@
options.RequestCultureProviders.Insert(0, new AcceptLanguageHeaderRequestCultureProvider());
});

builder.Services.AddHealthChecks()
.AddNpgSql(ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase"));

builder.Services.AddTransient(typeof(LocalizedPropertyResolver<,>));
builder.Services.AddAutoMapper(typeof(WebApiToPersistenceProfile));

builder.Services.AddProblemDetails();

builder.Services.AddDbContext<OrganisationInformationContext>(o =>
o.UseNpgsql(ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase")));
var connectionString = ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase");
builder.Services.AddHealthChecks().AddNpgSql(connectionString);
builder.Services.AddSingleton(new NpgsqlDataSourceBuilder(connectionString).MapEnums().Build());
builder.Services.AddDbContext<OrganisationInformationContext>((sp, options) =>
{
var dataSource = sp.GetRequiredService<NpgsqlDataSource>();
options.UseNpgsql(dataSource);
});

builder.Services.AddScoped<IFormRepository, DatabaseFormRepository>();
builder.Services.AddScoped<IOrganisationRepository, DatabaseOrganisationRepository>();
builder.Services.AddScoped<IPersonRepository, DatabasePersonRepository>();
Expand Down
14 changes: 10 additions & 4 deletions Services/CO.CDP.Organisation.Authority/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,26 @@
using CO.CDP.Organisation.Authority.AutoMapper;
using CO.CDP.OrganisationInformation.Persistence;
using Microsoft.EntityFrameworkCore;
using Npgsql;

var builder = WebApplication.CreateBuilder(args);

builder.ConfigureForwardedHeaders();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(o => { o.DocumentApi(builder.Configuration); });
builder.Services.AddHealthChecks()
.AddNpgSql(ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase"));
builder.Services.AddProblemDetails();

builder.Services.AddAutoMapper(typeof(WebApiToPersistenceProfile));

builder.Services.AddDbContext<OrganisationInformationContext>(o =>
o.UseNpgsql(ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase")));
var connectionString = ConnectionStringHelper.GetConnectionString(builder.Configuration, "OrganisationInformationDatabase");
builder.Services.AddHealthChecks().AddNpgSql(connectionString);
builder.Services.AddSingleton(new NpgsqlDataSourceBuilder(connectionString).MapEnums().Build());
builder.Services.AddDbContext<OrganisationInformationContext>((sp, options) =>
{
var dataSource = sp.GetRequiredService<NpgsqlDataSource>();
options.UseNpgsql(dataSource);
});

builder.Services.AddScoped<IPersonRepository, DatabasePersonRepository>();
builder.Services.AddScoped<ITenantRepository, DatabaseTenantRepository>();
builder.Services.AddScoped<IAuthorityRepository, DatabaseAuthorityRepository>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ private static RegisterOrganisation GivenRegisterOrganisationCommand()
{
Name = "TheOrganisation",
PersonId = Guid.NewGuid(),
Type = OrganisationType.Organisation,
Identifier = new OrganisationIdentifier
{
Scheme = "ISO9001",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private static OrganisationInformation.Persistence.Organisation GivenOrganisatio
Guid = Guid.NewGuid(),
Tenant = new OrganisationInformation.Persistence.Tenant { Guid = new Guid(), Name = "Tenant" },
Name = "Org name",
Type = OrganisationType.Organisation,
PendingRoles = (pendingRoles != null) ? pendingRoles : [],
ReviewedBy = (reviewedBy != null) ? reviewedBy : null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,7 @@ private Persistence.Organisation GivenOrganisationExist(
var organisation = new Persistence.Organisation
{
Name = "Acme Ltd",
Type = OrganisationInformation.OrganisationType.Organisation,
Guid = organisationId,
Identifiers = identifiers ?? [],
Addresses = [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public CreateOrganisationJoinRequestUseCaseTests()
Id = 1,
Guid = new Guid(),
Name = "Test organisation",
Type = OrganisationType.Organisation,
Tenant = null!
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,13 @@ await act.Should().ThrowAsync<UnknownConnectedEntityException>()

private Persistence.Organisation Organisation()
{
return new Persistence.Organisation { Guid = _organisationId, Name = "Test", Tenant = It.IsAny<Tenant>() };
return new Persistence.Organisation
{
Guid = _organisationId,
Name = "Test",
Type = OrganisationInformation.OrganisationType.Organisation,
Tenant = It.IsAny<Tenant>()
};
}

private Persistence.ConnectedEntity ConnectedEntity(Persistence.Organisation organisation)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ private static OrganisationInformation.Persistence.Organisation FakeOrganisation
Guid = Orgid,
Id = 1,
Name = "FakeOrg",
Type = OrganisationInformation.OrganisationType.Organisation,
Tenant = new Tenant
{
Guid = Guid.NewGuid(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public async Task ItReturnsTheFoundOrganisation()
Id = organisationId,
Guid = organisationGuid,
Name = "Test Organisation",
Type = OrganisationType.Organisation,
Tenant = new Tenant
{
Id = 101,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public async Task ItReturnsTheFoundOrganisation()
Id = 1,
Guid = organisationId,
Name = "Test Organisation",
Type = OrganisationType.Organisation,
Tenant = new Tenant
{
Id = 101,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@ public async Task Execute_WithValidCommand_ReturnsMappedOrganisations()
{
Guid = Guid.NewGuid(),
Name = "Organisation 2",
Type = OrganisationType.Organisation,
Tenant = null!
}
};
organisations.Add(new CO.CDP.OrganisationInformation.Persistence.Organisation
{
Guid = Guid.NewGuid(),
Name = "Organisation 1",
Type = OrganisationType.Organisation,
Tenant = null!
});
var mappedOrganisations = new List<OrganisationExtended>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public async Task Execute_OrganisationExistsAndHasPersons_ReturnsPersonModels()
Id = 1,
Guid = organisationGuid,
Tenant = null!,
Name = null!
Name = null!,
Type = OrganisationInformation.OrganisationType.Organisation
};

var persons = new List<Person>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static OrganisationInformation.Persistence.Organisation GivenOrganisatio
Id = 1,
Guid = organisationId,
Name = "Test Organisation",
Type = OrganisationInformation.OrganisationType.Organisation,
Tenant = new Tenant {
Guid = new Guid(),
Name = "Tenant"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ private static Persistence.Organisation FakeOrganisation(bool? withSupplierInfo
{
Guid = Guid.NewGuid(),
Name = "FakeOrg",
Type = OrganisationInformation.OrganisationType.Organisation,
Tenant = new Tenant
{
Guid = Guid.NewGuid(),
Expand Down
Loading

0 comments on commit 8da7808

Please sign in to comment.