Skip to content

Commit

Permalink
fix: bug that results in wrong required field presence detection
Browse files Browse the repository at this point in the history
  • Loading branch information
Dominick Leppich committed Oct 24, 2024
1 parent fac87e3 commit d50cdfc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public final boolean equals(Object o) {
return false;
}
FieldDefinitionEntity that = (FieldDefinitionEntity) o;
return id != that.id;
return id == that.id;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class RecordValidationTests {
private VocabularyEntity vocabulary;
private FieldTypeEntity ftText;
private FieldDefinitionEntity fdName;
private FieldDefinitionEntity fdOther;


@BeforeEach
Expand All @@ -47,6 +48,7 @@ public void setUp() {
vocabulary.setName("Test vocabulary");

fdName = new FieldDefinitionEntity();
fdName.setId(1L);
fdName.setSchema(schema);
fdName.setName("Name");
fdName.setType(ftText);
Expand All @@ -55,17 +57,41 @@ public void setUp() {
fdName.setUnique(true);
fdName.setRequired(true);

schema.setDefinitions(List.of(fdName));
fdOther = new FieldDefinitionEntity();
fdOther.setId(2L);
fdOther.setSchema(schema);
fdOther.setName("Other");
fdOther.setType(ftText);
fdOther.setMainEntry(false);
fdOther.setTitleField(true);
fdOther.setUnique(false);
fdOther.setRequired(true);

schema.setDefinitions(List.of(fdName, fdOther));
}

@Test
void missingRequiredField_fails() {
void missingAllRequiredFields_fails() {
VocabularyRecordEntity record = new VocabularyRecordEntity();
record.setVocabulary(vocabulary);

assertThrows(VocabularyException.class, () -> validator.validate(record));
}

@Test
void missingOneRequiredField_fails() {
VocabularyRecordEntity record = new VocabularyRecordEntity();
record.setVocabulary(vocabulary);

FieldInstanceEntity name = new FieldInstanceEntity();
name.setVocabularyRecord(record);
name.setDefinition(fdName);

record.setFields(List.of(name));

assertThrows(VocabularyException.class, () -> validator.validate(record));
}

@Test
void insertingUnspecifiedField_fails() {
VocabularyRecordEntity record = new VocabularyRecordEntity();
Expand Down Expand Up @@ -129,15 +155,23 @@ void hierarchicalRecordsIfEnabled_success() {
parentNameField.setId(1L);
parentNameField.setDefinition(fdName);
parentNameField.setVocabularyRecord(parent);
parent.setFields(List.of(parentNameField));
FieldInstanceEntity parentOtherField = new FieldInstanceEntity();
parentOtherField.setId(2L);
parentOtherField.setDefinition(fdOther);
parentOtherField.setVocabularyRecord(parent);
parent.setFields(List.of(parentNameField, parentOtherField));

VocabularyRecordEntity child = new VocabularyRecordEntity();
child.setVocabulary(vocabulary);
FieldInstanceEntity childNameField = new FieldInstanceEntity();
childNameField.setId(2L);
childNameField.setId(3L);
childNameField.setDefinition(fdName);
childNameField.setVocabularyRecord(child);
child.setFields(List.of(childNameField));
FieldInstanceEntity childOtherField = new FieldInstanceEntity();
childOtherField.setId(4L);
childOtherField.setDefinition(fdOther);
childOtherField.setVocabularyRecord(child);
child.setFields(List.of(childNameField, childOtherField));
child.setParentRecord(parent);
parent.setChildren(List.of(child));

Expand Down

0 comments on commit d50cdfc

Please sign in to comment.