Skip to content

Commit

Permalink
Can now validate PartOfSpeech GUIDs safely
Browse files Browse the repository at this point in the history
  • Loading branch information
rmunn committed Jan 10, 2025
1 parent e4521c5 commit 93bc1b5
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 10 deletions.
8 changes: 1 addition & 7 deletions backend/FwLite/MiniLcm.Tests/CreateEntryTestsBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ public async Task CanCreateEntry_AutoFaker()
var createdEntry = await Api.CreateEntry(entry);
createdEntry.Should().BeEquivalentTo(entry, options => options
.For(e => e.Components).Exclude(e => e.Id)
.For(e => e.ComplexForms).Exclude(e => e.Id)
//predefined is always true in fwdata bridge, so we need to exclude it for now
.For(e => e.Senses).For(s => s.SemanticDomains).Exclude(s => s.Predefined)
// TODO: Figure out how to exclude just PartOfSpeech.Predefined
// .For(e => e.Senses).Exclude(s => s.PartOfSpeech.Predefined)); // rejected because PartOfSpeech could be null
// .For(e => e.Senses).Exclude(s => s.PartOfSpeech?.Predefined)); // not allowed because "An expression tree lambda may not contain a null propagating operator."
.For(e => e.Senses).Exclude(s => s.PartOfSpeech)); // Not ideal but best we can do for now
.For(e => e.ComplexForms).Exclude(e => e.Id));
}

[Fact]
Expand Down
2 changes: 1 addition & 1 deletion backend/FwLite/MiniLcm/Validators/PartOfSpeechValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class PartOfSpeechValidator : AbstractValidator<PartOfSpeech>
{
public PartOfSpeechValidator()
{
// RuleFor(pos => pos.Id).Must(BeCanonicalGuid).When(pos => pos.Predefined); // TODO: Uncomment once PR 1350 is merged
RuleFor(pos => pos.Id).Must(BeCanonicalGuid).When(pos => pos.Predefined);
RuleFor(pos => pos.DeletedAt).Null();
RuleFor(pos => pos.Name).Required();
}
Expand Down
3 changes: 1 addition & 2 deletions backend/FwLite/MiniLcm/Validators/SenseValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public SenseValidator()
RuleFor(s => s.DeletedAt).Null();
RuleFor(s => s.Definition).NoEmptyValues();
RuleFor(s => s.Gloss).NoEmptyValues();
// RuleFor(s => s.PartOfSpeech).Empty(); // TODO: Comment out if we're not yet ready to move away from strings
// RuleFor(s => s.PartOfSpeechId).SetValidator(new IsCanonicalPartOfSpeechGuidValidator()); // Can't do this statelessly, as we'd need a full PartOfSpeech object to check if it's predefined or not
RuleFor(s => s.PartOfSpeech!).SetValidator(new PartOfSpeechValidator()).When(s => s.PartOfSpeech is not null);
RuleForEach(s => s.SemanticDomains).SetValidator(new SemanticDomainValidator());
RuleForEach(s => s.ExampleSentences).SetValidator(sense => new ExampleSentenceValidator(sense));
}
Expand Down

0 comments on commit 93bc1b5

Please sign in to comment.