diff --git a/backend/FwLite/LcmCrdt.Tests/Data/VerifyRegeneratedSnapshotsAfterMigrationFromScriptedDb.v2.verified.json b/backend/FwLite/LcmCrdt.Tests/Data/VerifyRegeneratedSnapshotsAfterMigrationFromScriptedDb.v2.verified.json index 8b7c997c09..e3132fbc9f 100644 --- a/backend/FwLite/LcmCrdt.Tests/Data/VerifyRegeneratedSnapshotsAfterMigrationFromScriptedDb.v2.verified.json +++ b/backend/FwLite/LcmCrdt.Tests/Data/VerifyRegeneratedSnapshotsAfterMigrationFromScriptedDb.v2.verified.json @@ -688,6 +688,13 @@ "en": "Fruit", "fr": "fr" }, + "PartOfSpeech": { + "Id": "Guid_36", + "Name": { + "en": "Adverb" + }, + "Predefined": true + }, "PartOfSpeechId": "Guid_36", "SemanticDomains": [ { diff --git a/backend/FwLite/LcmCrdt/Changes/CreateSenseChange.cs b/backend/FwLite/LcmCrdt/Changes/CreateSenseChange.cs index 3e139e9f55..1043da4912 100644 --- a/backend/FwLite/LcmCrdt/Changes/CreateSenseChange.cs +++ b/backend/FwLite/LcmCrdt/Changes/CreateSenseChange.cs @@ -35,6 +35,8 @@ private CreateSenseChange(Guid entityId, Guid entryId) : base(entityId) public override async ValueTask NewEntity(Commit commit, IChangeContext context) { + var partOfSpeech = PartOfSpeechId is null ? null : await context.GetCurrent(PartOfSpeechId.Value); + partOfSpeech = partOfSpeech is { DeletedAt: null } ? partOfSpeech : null; return new Sense { Id = EntityId, @@ -42,7 +44,8 @@ public override async ValueTask NewEntity(Commit commit, IChangeContext c Order = Order, Definition = Definition ?? new(), Gloss = Gloss ?? new MultiString(), - PartOfSpeechId = await context.DeletedAsNull(PartOfSpeechId), + PartOfSpeech = partOfSpeech, + PartOfSpeechId = partOfSpeech?.Id, SemanticDomains = await context.FilterDeleted(SemanticDomains ?? []).ToArrayAsync(), DeletedAt = await context.IsObjectDeleted(EntryId) ? commit.DateTime : (DateTime?)null }; diff --git a/backend/FwLite/LcmCrdt/Changes/SetPartOfSpeechChange.cs b/backend/FwLite/LcmCrdt/Changes/SetPartOfSpeechChange.cs index 4e3f9b53e1..2e79232068 100644 --- a/backend/FwLite/LcmCrdt/Changes/SetPartOfSpeechChange.cs +++ b/backend/FwLite/LcmCrdt/Changes/SetPartOfSpeechChange.cs @@ -13,6 +13,7 @@ public override async ValueTask ApplyChange(Sense entity, IChangeContext context if (PartOfSpeechId is null) { entity.PartOfSpeechId = null; + entity.PartOfSpeech = null; return; } @@ -24,7 +25,6 @@ public override async ValueTask ApplyChange(Sense entity, IChangeContext context return; } entity.PartOfSpeechId = partOfSpeech.Id; - //don't set the part of speech, it may trigger an insert of that part of speech - //I wasn't able to figure out how to write a test to cover this sadly, I only saw it live. + entity.PartOfSpeech = partOfSpeech; } } diff --git a/backend/FwLite/MiniLcm.Tests/SenseTestsBase.cs b/backend/FwLite/MiniLcm.Tests/SenseTestsBase.cs index 78d4d93e35..4d957b276b 100644 --- a/backend/FwLite/MiniLcm.Tests/SenseTestsBase.cs +++ b/backend/FwLite/MiniLcm.Tests/SenseTestsBase.cs @@ -4,10 +4,13 @@ public abstract class SenseTestsBase : MiniLcmTestBase { private static readonly Guid _entryId = Guid.NewGuid(); private static readonly Guid _senseId = Guid.NewGuid(); + private static readonly Guid _nounPosId = Guid.NewGuid(); public override async Task InitializeAsync() { await base.InitializeAsync(); + var nounPos = new PartOfSpeech() { Id = _nounPosId, Name = { { "en", "Noun" } } }; + await Api.CreatePartOfSpeech(nounPos); await Api.CreateEntry(new Entry() { Id = _entryId, @@ -15,7 +18,9 @@ await Api.CreateEntry(new Entry() Senses = [new() { Id = _senseId, - Gloss = { { "en", "new-sense-gloss" } } + Gloss = { { "en", "new-sense-gloss" } }, + PartOfSpeech = nounPos, + PartOfSpeechId = _nounPosId, }] }); } @@ -33,6 +38,10 @@ public async Task Get_ExistingSense_ReturnsSense() var sense = await Api.GetSense(_entryId, _senseId); sense.Should().NotBeNull(); sense.Gloss["en"].Should().Be("new-sense-gloss"); + sense.PartOfSpeech.Should().NotBeNull(); + sense.PartOfSpeech.Name["en"].Should().Be("Noun"); + sense.PartOfSpeech.Id.Should().Be(_nounPosId); + sense.PartOfSpeechId.Should().Be(_nounPosId); } /// diff --git a/backend/FwLite/MiniLcm/Models/Sense.cs b/backend/FwLite/MiniLcm/Models/Sense.cs index dc6b301277..3c4016f13e 100644 --- a/backend/FwLite/MiniLcm/Models/Sense.cs +++ b/backend/FwLite/MiniLcm/Models/Sense.cs @@ -31,7 +31,10 @@ public void RemoveReference(Guid id, DateTimeOffset time) if (id == EntryId) DeletedAt = time; if (id == PartOfSpeechId) + { PartOfSpeechId = null; + PartOfSpeech = null; + } SemanticDomains = [..SemanticDomains.Where(sd => sd.Id != id)]; } diff --git a/backend/harmony b/backend/harmony index 0998577a4e..1ac746273d 160000 --- a/backend/harmony +++ b/backend/harmony @@ -1 +1 @@ -Subproject commit 0998577a4e98acac2e33571a02a5c676abe143a0 +Subproject commit 1ac746273dd4e46f68a7dc3006cd23c30cf9ae81