From fa56386a429d1751498348aedba96ac3a939df2b Mon Sep 17 00:00:00 2001 From: Kevin Hahn Date: Tue, 12 Nov 2024 13:12:57 +0700 Subject: [PATCH] write test for creating a complex form type, upgrade lcm so we can use the new Create(Guid id) api when creating the complex form type (#1223) --- .../FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs | 5 ++--- .../FwDataMiniLcmBridge/FwDataMiniLcmBridge.csproj | 4 ++-- backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs | 2 +- backend/FwLite/LocalWebApp/LocalWebApp.csproj | 2 +- .../MiniLcm.Tests/ComplexFormComponentTestsBase.cs | 9 +++++++++ 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs index 50f2a2aa6..e9d8fbe69 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs +++ b/backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs @@ -337,7 +337,7 @@ private ComplexFormType ToComplexFormType(ICmPossibility t) public Task CreateComplexFormType(ComplexFormType complexFormType) { - if (complexFormType.Id != default) throw new InvalidOperationException("Complex form type id must be empty"); + if (complexFormType.Id == default) complexFormType.Id = Guid.NewGuid(); UndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW("Create complex form type", "Remove complex form type", Cache.ActionHandlerAccessor, @@ -345,10 +345,9 @@ public Task CreateComplexFormType(ComplexFormType complexFormTy { var lexComplexFormType = Cache.ServiceLocator .GetInstance() - .Create(); + .Create(complexFormType.Id); ComplexFormTypes.PossibilitiesOS.Add(lexComplexFormType); UpdateLcmMultiString(lexComplexFormType.Name, complexFormType.Name); - complexFormType.Id = lexComplexFormType.Guid; }); return Task.FromResult(ToComplexFormType(ComplexFormTypes.PossibilitiesOS.Single(c => c.Guid == complexFormType.Id))); } diff --git a/backend/FwLite/FwDataMiniLcmBridge/FwDataMiniLcmBridge.csproj b/backend/FwLite/FwDataMiniLcmBridge/FwDataMiniLcmBridge.csproj index 2192d7724..5ab11b140 100644 --- a/backend/FwLite/FwDataMiniLcmBridge/FwDataMiniLcmBridge.csproj +++ b/backend/FwLite/FwDataMiniLcmBridge/FwDataMiniLcmBridge.csproj @@ -14,9 +14,9 @@ - + - + diff --git a/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs b/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs index 83261e1d7..c6491705f 100644 --- a/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs +++ b/backend/FwLite/LcmCrdt/CrdtMiniLcmApi.cs @@ -142,7 +142,7 @@ public IAsyncEnumerable GetComplexFormTypes() return ComplexFormTypes.AsAsyncEnumerable(); } - public async Task CreateComplexFormType(MiniLcm.Models.ComplexFormType complexFormType) + public async Task CreateComplexFormType(ComplexFormType complexFormType) { if (complexFormType.Id == default) complexFormType.Id = Guid.NewGuid(); await dataModel.AddChange(ClientId, new CreateComplexFormType(complexFormType.Id, complexFormType.Name)); diff --git a/backend/FwLite/LocalWebApp/LocalWebApp.csproj b/backend/FwLite/LocalWebApp/LocalWebApp.csproj index eedd69c3e..51e42e2a9 100644 --- a/backend/FwLite/LocalWebApp/LocalWebApp.csproj +++ b/backend/FwLite/LocalWebApp/LocalWebApp.csproj @@ -19,7 +19,7 @@ - + diff --git a/backend/FwLite/MiniLcm.Tests/ComplexFormComponentTestsBase.cs b/backend/FwLite/MiniLcm.Tests/ComplexFormComponentTestsBase.cs index 80dac29d2..4f51ca275 100644 --- a/backend/FwLite/MiniLcm.Tests/ComplexFormComponentTestsBase.cs +++ b/backend/FwLite/MiniLcm.Tests/ComplexFormComponentTestsBase.cs @@ -74,4 +74,13 @@ public async Task CreateComplexFormComponent_CanCreateMultipleComponentSenses() component2.ComponentEntryId.Should().Be(_componentEntryId); component2.ComponentSenseId.Should().Be(_componentSenseId2); } + + [Fact] + public async Task CreateComplexFormType_Works() + { + var complexFormType = new ComplexFormType() { Id = Guid.NewGuid(), Name = new() { { "en", "test" } } }; + await Api.CreateComplexFormType(complexFormType); + var types = await Api.GetComplexFormTypes().ToArrayAsync(); + types.Should().ContainSingle(t => t.Id == complexFormType.Id); + } }