Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

least ancestral entity constraint tests #1695

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"@veupathdb/tsconfig": "^2.0.0",
"@veupathdb/wdk-client": "^0.9.29",
"assert": "^2.0.0",
"babel-jest": "^29.5.0",
"bubleify": "^2.0.0",
"buffer": "^6.0.3",
"http-proxy-middleware": "^2.0.6",
Expand Down
76 changes: 76 additions & 0 deletions src/lib/core/__test__/utils/data-element-constraints.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { StudyEntity } from '../../types/study';
import { leastAncestralEntity } from '../../utils/data-element-constraints';
import { entityTreeToArray } from '../../utils/study-metadata';

const mockStudyTree: StudyEntity = {
id: 'root',
idColumnName: 'colname',
displayName: 'nice label',
description: 'none',
variables: [],
children: [
{
id: 'branchA',
idColumnName: 'colname',
displayName: 'nice label',
description: 'none',
variables: [],
children: [
{
id: 'leafA1',
idColumnName: 'colname',
displayName: 'nice label',
description: 'none',
variables: [],
},
{
id: 'leafA2',
idColumnName: 'colname',
displayName: 'nice label',
description: 'none',
variables: [],
},
],
},
{
id: 'branchB',
idColumnName: 'colname',
displayName: 'nice label',
description: 'none',
variables: [],
children: [
{
id: 'leafB1',
idColumnName: 'colname',
displayName: 'nice label',
description: 'none',
variables: [],
},
{
id: 'leafB2',
idColumnName: 'colname',
displayName: 'nice label',
description: 'none',
variables: [],
},
],
},
],
};

const studyEntities = entityTreeToArray(mockStudyTree);

const branchA = studyEntities.find((e) => (e.id = 'branchA'))!;
const branchB = studyEntities.find((e) => (e.id = 'branchB'))!;
const leafA1 = studyEntities.find((e) => (e.id = 'leafA1'))!;
const leafA2 = studyEntities.find((e) => (e.id = 'leafA2'))!;
const leafB1 = studyEntities.find((e) => (e.id = 'leafB1'))!;
const leafB2 = studyEntities.find((e) => (e.id = 'leafB2'))!;

describe('leastAncestralEntity', () => {
it('should find leafA1 to be least ancestral in [branchA, leafA1]', () => {
expect(leastAncestralEntity([branchA, leafA1], studyEntities)).toEqual(
leafA1
);
});
});
Loading