Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,13 @@
"en": "Fruit",
"fr": "fr"
},
"PartOfSpeech": {
"Id": "Guid_36",
"Name": {
"en": "Adverb"
},
"Predefined": true
},
"PartOfSpeechId": "Guid_36",
"SemanticDomains": [
{
Expand Down
5 changes: 4 additions & 1 deletion backend/FwLite/LcmCrdt/Changes/CreateSenseChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,17 @@ private CreateSenseChange(Guid entityId, Guid entryId) : base(entityId)

public override async ValueTask<Sense> NewEntity(Commit commit, IChangeContext context)
{
var partOfSpeech = PartOfSpeechId is null ? null : await context.GetCurrent<PartOfSpeech>(PartOfSpeechId.Value);
partOfSpeech = partOfSpeech is { DeletedAt: null } ? partOfSpeech : null;
return new Sense
{
Id = EntityId,
EntryId = EntryId,
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
};
Expand Down
4 changes: 2 additions & 2 deletions backend/FwLite/LcmCrdt/Changes/SetPartOfSpeechChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public override async ValueTask ApplyChange(Sense entity, IChangeContext context
if (PartOfSpeechId is null)
{
entity.PartOfSpeechId = null;
entity.PartOfSpeech = null;
return;
}

Expand All @@ -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;
}
}
11 changes: 10 additions & 1 deletion backend/FwLite/MiniLcm.Tests/SenseTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,23 @@ 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,
LexemeForm = { { "en", "new-lexeme-form" } },
Senses = [new()
{
Id = _senseId,
Gloss = { { "en", "new-sense-gloss" } }
Gloss = { { "en", "new-sense-gloss" } },
PartOfSpeech = nounPos,
PartOfSpeechId = _nounPosId,
}]
});
}
Expand All @@ -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);
}

/// <summary>
Expand Down
3 changes: 3 additions & 0 deletions backend/FwLite/MiniLcm/Models/Sense.cs
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️ Should there be a test somewhere for POS reference removal?

Original file line number Diff line number Diff line change
Expand Up @@ -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)];
}

Expand Down
Loading