From 71bdc0045b9937bdc7622a0c0832a11dc34dc98f Mon Sep 17 00:00:00 2001 From: Koen Metsu Date: Mon, 9 Sep 2024 16:27:35 +0200 Subject: [PATCH] feat: or-2353 also add kbo legal entity when coupling --- .../Organisation/KboOrganisationCommandHandlers.cs | 2 ++ src/OrganisationRegistry/Organisation/Organisation.cs | 5 ++++- src/OrganisationRegistry/Organisation/State/KboState.cs | 1 + .../Organisation/Kbo/CoupleOrganisationToKboTests.cs | 2 +- ...CoupleOrganisationToKboWithoutAddressAndLegalFormTests.cs | 2 +- .../Organisation/Kbo/UpdateFromKboTests.cs | 2 +- 6 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/OrganisationRegistry/Organisation/KboOrganisationCommandHandlers.cs b/src/OrganisationRegistry/Organisation/KboOrganisationCommandHandlers.cs index d47cbec9a..9b24fc4d0 100755 --- a/src/OrganisationRegistry/Organisation/KboOrganisationCommandHandlers.cs +++ b/src/OrganisationRegistry/Organisation/KboOrganisationCommandHandlers.cs @@ -348,6 +348,8 @@ public async Task Handle(ICommandEnvelope envelope) AddAddresses(organisation, location, registeredOfficeLocationType); AddLabel(organisation, kboOrganisation); + + organisation.AddKboLegalEntityType(kboOrganisation.LegalEntityType); }); public async Task Handle(ICommandEnvelope envelope) diff --git a/src/OrganisationRegistry/Organisation/Organisation.cs b/src/OrganisationRegistry/Organisation/Organisation.cs index 04e1dbcf8..13d37b357 100755 --- a/src/OrganisationRegistry/Organisation/Organisation.cs +++ b/src/OrganisationRegistry/Organisation/Organisation.cs @@ -993,6 +993,9 @@ public void AddKboLegalFormOrganisationClassification(Guid organisationOrganisat public void AddKboLegalEntityType(IMagdaLegalEntityType kboOrganisationLegalEntityType) { + if (!string.IsNullOrEmpty(KboState.LegalEntityTypeCode)) + return; + ApplyChange( new KboLegalEntityTypeAdded( Id, @@ -3127,6 +3130,6 @@ public void Apply(OrganisationLocationRemoved evnt) public void Apply(KboLegalEntityTypeAdded evnt) { - // no need to keep this in state at time of writing. + KboState.LegalEntityTypeCode = evnt.LegalEntityTypeCode; } } diff --git a/src/OrganisationRegistry/Organisation/State/KboState.cs b/src/OrganisationRegistry/Organisation/State/KboState.cs index 9bd756b04..e9e1d8e72 100644 --- a/src/OrganisationRegistry/Organisation/State/KboState.cs +++ b/src/OrganisationRegistry/Organisation/State/KboState.cs @@ -12,6 +12,7 @@ public class KboState public string? ShortNameBeforeKboCoupling { get; set; } public KboTermination? TerminationInKbo { get; set; } public KboNumber? KboNumber { get; set; } + public string? LegalEntityTypeCode { get; set; } public void Clear() { diff --git a/test/OrganisationRegistry.UnitTests/Organisation/Kbo/CoupleOrganisationToKboTests.cs b/test/OrganisationRegistry.UnitTests/Organisation/Kbo/CoupleOrganisationToKboTests.cs index 8497241ac..a818d0749 100755 --- a/test/OrganisationRegistry.UnitTests/Organisation/Kbo/CoupleOrganisationToKboTests.cs +++ b/test/OrganisationRegistry.UnitTests/Organisation/Kbo/CoupleOrganisationToKboTests.cs @@ -286,5 +286,5 @@ await Given(Events) public async Task PublishesTheCorrectNumberOfEvents() => await Given(Events) .When(CoupleOrganisationToKboCommand, TestUser.AlgemeenBeheerder) - .ThenItPublishesTheCorrectNumberOfEvents(7); + .ThenItPublishesTheCorrectNumberOfEvents(8); } diff --git a/test/OrganisationRegistry.UnitTests/Organisation/Kbo/CoupleOrganisationToKboWithoutAddressAndLegalFormTests.cs b/test/OrganisationRegistry.UnitTests/Organisation/Kbo/CoupleOrganisationToKboWithoutAddressAndLegalFormTests.cs index 7d77eaf66..ff9d8e846 100755 --- a/test/OrganisationRegistry.UnitTests/Organisation/Kbo/CoupleOrganisationToKboWithoutAddressAndLegalFormTests.cs +++ b/test/OrganisationRegistry.UnitTests/Organisation/Kbo/CoupleOrganisationToKboWithoutAddressAndLegalFormTests.cs @@ -218,5 +218,5 @@ await Given(Events) public async Task PublishesTheCorrectNumberOfEvents() => await Given(Events) .When(CoupleOrganisationToKboCommand, TestUser.AlgemeenBeheerder) - .ThenItPublishesTheCorrectNumberOfEvents(4); + .ThenItPublishesTheCorrectNumberOfEvents(5); } diff --git a/test/OrganisationRegistry.UnitTests/Organisation/Kbo/UpdateFromKboTests.cs b/test/OrganisationRegistry.UnitTests/Organisation/Kbo/UpdateFromKboTests.cs index 15c525af9..91032879a 100644 --- a/test/OrganisationRegistry.UnitTests/Organisation/Kbo/UpdateFromKboTests.cs +++ b/test/OrganisationRegistry.UnitTests/Organisation/Kbo/UpdateFromKboTests.cs @@ -220,7 +220,7 @@ protected override KboOrganisationCommandHandlers BuildHandler(ISession session) public async Task PublishesElevenEvents() { await Given(Events).When(SyncOrganisationWithKboCommand, TestUser.AlgemeenBeheerder) - .ThenItPublishesTheCorrectNumberOfEvents(11); + .ThenItPublishesTheCorrectNumberOfEvents(12); } [Fact]