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

Update tests and GitHub Workflow #209

Merged
merged 5 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 11 additions & 1 deletion .github/workflows/test_ws_codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,21 @@ jobs:
id: branch-name
uses: tj-actions/branch-names@v6

- uses: actions/checkout@v3
- name: Checkout to specific branch
uses: actions/checkout@v3
id: specific-checkout
continue-on-error: true
with:
repository: biothings/biothings_explorer
ref: ${{ steps.branch-name.outputs.current_branch }}

- name: Checkout to main if above failed
if: steps.specific-checkout.outcome == 'failure'
uses: actions/checkout@v3
with:
repository: biothings/biothings_explorer
ref: main

- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
Expand Down
2 changes: 1 addition & 1 deletion __test__/integration/KnowledgeGraph.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import KGEdge from '../../src/graph/kg_edge';
import KGNode from '../../src/graph/kg_node';
import KnowledgeGraph from '../../src/graph/knowledge_graph';
import { TrapiAttribute } from '../../src/types';
import { TrapiAttribute } from '@biothings-explorer/types';

describe('Testing KnowledgeGraph Module', () => {
const nodeInput = new KGNode('PUBCHEM.COMPOUND:2662-n0', {
Expand Down
1 change: 0 additions & 1 deletion __test__/integration/QueryEdge.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ describe('Testing QueryEdge Module', () => {
expect(res).toContain('contributes_to');
expect(res).toContain('causes');
expect(res).toContain('ameliorates');
expect(res).toContain('treats');
});

test('Predicates not in biolink model should return itself', () => {
Expand Down
35 changes: 35 additions & 0 deletions __test__/integration/QueryResult.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ describe('Testing QueryResults Module', () => {
predicate: 'biolink:physically_interacts_with',
source: 'DGIdb',
api_name: 'BioThings DGIDB API',
"x-translator": {
infores: "infores:biothings-dgidb",
component: "KP",
team: ["Service Provider"]
}
},
edge1,
);
Expand Down Expand Up @@ -98,6 +103,11 @@ describe('Testing QueryResults Module', () => {
{
predicate: 'biolink:gene_associated_with_condition',
api_name: 'Automat Pharos',
"x-translator": {
infores: "infores:automat-pharos",
component: "KP",
team: ["Ranking Agent"]
}
},
edge1,
);
Expand Down Expand Up @@ -197,6 +207,11 @@ describe('Testing QueryResults Module', () => {
{
predicate: 'biolink:gene_associated_with_condition',
api_name: 'Automat Pharos',
"x-translator": {
infores: "infores:automat-pharos",
component: "KP",
team: ["Ranking Agent"]
}
},
edge1,
);
Expand Down Expand Up @@ -295,6 +310,11 @@ describe('Testing QueryResults Module', () => {
{
predicate: 'biolink:gene_associated_with_condition',
api_name: 'Automat Pharos',
"x-translator": {
infores: "infores:automat-pharos",
component: "KP",
team: ["Ranking Agent"]
}
},
edge1,
);
Expand Down Expand Up @@ -393,6 +413,11 @@ describe('Testing QueryResults Module', () => {
{
predicate: 'biolink:gene_associated_with_condition',
api_name: 'Automat Pharos',
"x-translator": {
infores: "infores:automat-pharos",
component: "KP",
team: ["Ranking Agent"]
}
},
edge1,
);
Expand Down Expand Up @@ -493,6 +518,11 @@ describe('Testing QueryResults Module', () => {
{
predicate: 'biolink:gene_associated_with_condition',
api_name: 'Automat Pharos',
"x-translator": {
infores: "infores:automat-pharos",
component: "KP",
team: ["Ranking Agent"]
}
},
edge1,
);
Expand Down Expand Up @@ -594,6 +624,11 @@ describe('Testing QueryResults Module', () => {
{
predicate: 'biolink:gene_associated_with_condition',
api_name: 'Automat Pharos',
"x-translator": {
infores: "infores:automat-pharos",
component: "KP",
team: ["Ranking Agent"]
}
},
edge1,
);
Expand Down
66 changes: 33 additions & 33 deletions __test__/integration/graph/graph.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ describe('Test graph class', () => {
expect(g.nodes['inputPrimaryCurie'].qNodeID).toEqual('qg1');
expect(Array.from(g.nodes['inputPrimaryCurie'].targetNodes)).toEqual(['outputPrimaryCurie']);
expect(Array.from(g.nodes['inputPrimaryCurie'].targetQNodeIDs)).toEqual(['qg2']);
expect(g.edges).toHaveProperty('95fe2a8089c0d79ea093b97c5991f7ba');
expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].apis)).toEqual(['API1']);
expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].sources).toHaveProperty('source1');
expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].publications)).toEqual(['PMID:1', 'PMID:2']);
expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].attributes).toHaveProperty('relation', new Set(['relation1']));
expect(g.edges).toHaveProperty('2c826c3663b91f65a1cba70f06c7fc65');
expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].apis)).toEqual(['API1']);
expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].sources).toHaveProperty('source1');
expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].publications)).toEqual(['PMID:1', 'PMID:2']);
expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].attributes).toHaveProperty('relation', new Set(['relation1']));
});

test('Multiple query results are correctly updated for two edges having same input, predicate and output', () => {
Expand All @@ -130,17 +130,17 @@ describe('Test graph class', () => {
expect(Array.from(g.nodes['inputPrimaryCurie'].targetNodes)).toEqual(['outputPrimaryCurie']);
expect(Array.from(g.nodes['inputPrimaryCurie'].targetQNodeIDs)).toEqual(['qg2']);

expect(g.edges).toHaveProperty('95fe2a8089c0d79ea093b97c5991f7ba');
expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].apis)).toEqual(['API1']);
expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].sources).toHaveProperty('source1');
expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].publications)).toEqual(['PMID:1', 'PMID:2']);
expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].attributes).toHaveProperty('relation', new Set(['relation1']));
expect(g.edges).toHaveProperty('2c826c3663b91f65a1cba70f06c7fc65');
expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].apis)).toEqual(['API1']);
expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].sources).toHaveProperty('source1');
expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].publications)).toEqual(['PMID:1', 'PMID:2']);
expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].attributes).toHaveProperty('relation', new Set(['relation1']));

expect(g.edges).toHaveProperty('9d334cb674d5671364c45cc8403184c6');
expect(Array.from(g.edges['9d334cb674d5671364c45cc8403184c6'].apis)).toEqual(['API2']);
expect(g.edges['9d334cb674d5671364c45cc8403184c6'].sources).toHaveProperty('source2');
expect(Array.from(g.edges['9d334cb674d5671364c45cc8403184c6'].publications)).toEqual(['PMC:1', 'PMC:2']);
expect(g.edges['9d334cb674d5671364c45cc8403184c6'].attributes).toHaveProperty('relation', new Set(['relation2']));
expect(g.edges).toHaveProperty('827c366e2e3088b3f4a90dd88a524f15');
expect(Array.from(g.edges['827c366e2e3088b3f4a90dd88a524f15'].apis)).toEqual(['API2']);
expect(g.edges['827c366e2e3088b3f4a90dd88a524f15'].sources).toHaveProperty('source2');
expect(Array.from(g.edges['827c366e2e3088b3f4a90dd88a524f15'].publications)).toEqual(['PMC:1', 'PMC:2']);
expect(g.edges['827c366e2e3088b3f4a90dd88a524f15'].attributes).toHaveProperty('relation', new Set(['relation2']));
});

test('Multiple query results for different edges are correctly updated', () => {
Expand All @@ -157,37 +157,37 @@ describe('Test graph class', () => {
expect(Array.from(g.nodes['inputPrimaryCurie'].targetNodes)).toEqual(['outputPrimaryCurie']);
expect(Array.from(g.nodes['inputPrimaryCurie'].targetQNodeIDs)).toEqual(['qg2']);

expect(g.edges).toHaveProperty('95fe2a8089c0d79ea093b97c5991f7ba');
expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].apis)).toEqual(['API1']);
expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].sources).toHaveProperty('source1');
expect(Array.from(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].publications)).toEqual(['PMID:1', 'PMID:2']);
expect(g.edges['95fe2a8089c0d79ea093b97c5991f7ba'].attributes).toHaveProperty('relation', new Set(['relation1']));
expect(g.edges).toHaveProperty('2c826c3663b91f65a1cba70f06c7fc65');
expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].apis)).toEqual(['API1']);
expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].sources).toHaveProperty('source1');
expect(Array.from(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].publications)).toEqual(['PMID:1', 'PMID:2']);
expect(g.edges['2c826c3663b91f65a1cba70f06c7fc65'].attributes).toHaveProperty('relation', new Set(['relation1']));

expect(g.edges).toHaveProperty('9d334cb674d5671364c45cc8403184c6');
expect(Array.from(g.edges['9d334cb674d5671364c45cc8403184c6'].apis)).toEqual(['API2']);
expect(g.edges['9d334cb674d5671364c45cc8403184c6'].sources).toHaveProperty('source2');
expect(Array.from(g.edges['9d334cb674d5671364c45cc8403184c6'].publications)).toEqual(['PMC:1', 'PMC:2']);
expect(g.edges['9d334cb674d5671364c45cc8403184c6'].attributes).toHaveProperty('relation', new Set(['relation2']));
expect(g.edges).toHaveProperty('827c366e2e3088b3f4a90dd88a524f15');
expect(Array.from(g.edges['827c366e2e3088b3f4a90dd88a524f15'].apis)).toEqual(['API2']);
expect(g.edges['827c366e2e3088b3f4a90dd88a524f15'].sources).toHaveProperty('source2');
expect(Array.from(g.edges['827c366e2e3088b3f4a90dd88a524f15'].publications)).toEqual(['PMC:1', 'PMC:2']);
expect(g.edges['827c366e2e3088b3f4a90dd88a524f15'].attributes).toHaveProperty('relation', new Set(['relation2']));

expect(g.edges).toHaveProperty('4fe2d5d3e03e0f78f272745caf6b627d');
expect(Array.from(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].apis)).toEqual(['API3']);
expect(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].sources).toHaveProperty('source3');
expect(Array.from(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].publications)).toEqual(['PMC:3', 'PMC:4']);
expect(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].attributes).toHaveProperty('relation', new Set(['relation3']));
expect(g.edges).toHaveProperty('3138ca0afca791770ed38c243dea2116');
expect(Array.from(g.edges['3138ca0afca791770ed38c243dea2116'].apis)).toEqual(['API3']);
expect(g.edges['3138ca0afca791770ed38c243dea2116'].sources).toHaveProperty('source3');
expect(Array.from(g.edges['3138ca0afca791770ed38c243dea2116'].publications)).toEqual(['PMC:3', 'PMC:4']);
expect(g.edges['3138ca0afca791770ed38c243dea2116'].attributes).toHaveProperty('relation', new Set(['relation3']));
});

test('Multiple attributes with the same name are merged', () => {
const g = new graph();
g.update([record3, record3a]);

expect(g.edges).toHaveProperty('4fe2d5d3e03e0f78f272745caf6b627d');
expect(Array.from(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].publications)).toEqual([
expect(g.edges).toHaveProperty('3138ca0afca791770ed38c243dea2116');
expect(Array.from(g.edges['3138ca0afca791770ed38c243dea2116'].publications)).toEqual([
'PMC:3',
'PMC:4',
'PMC:6',
'PMC:7',
]);
expect(g.edges['4fe2d5d3e03e0f78f272745caf6b627d'].attributes).toHaveProperty(
expect(g.edges['3138ca0afca791770ed38c243dea2116'].attributes).toHaveProperty(
'relation',
new Set(['relation3', 'relation3a', 'relation3b']),
);
Expand Down
5 changes: 3 additions & 2 deletions __test__/unittest/inferred_mode.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ describe('Test InferredQueryHandler', () => {
},
},
template: 'Chem-treats-DoP.json',
qualifiers: {}
},
];

Expand Down Expand Up @@ -549,7 +550,7 @@ describe('Test InferredQueryHandler', () => {
expect(creativeLimitHit).toBeTruthy();
expect(Object.keys(combinedResponse.message.results)).toHaveLength(3);
expect(combinedResponse.message.results['fakeCompound1-fakeDisease1'].analyses[0].score).toEqual(
0.8421052631578949,
0.7836531040612146,
);
expect(combinedResponse.message.results['fakeCompound3-fakeDisease1'].analyses[0].score).toEqual(0.2);
expect(combinedResponse.logs).toHaveLength(3);
Expand Down Expand Up @@ -712,7 +713,7 @@ describe('Test InferredQueryHandler', () => {
expect(Object.keys(mergedResults1)).toHaveLength(1);
expect(creativeLimitHit1).toBeTruthy();
expect(combinedResponse.message.results['fakeCompound1-fakeDisease1'].analyses[0].score).toEqual(
0.8421052631578949,
0.7836531040612146,
);
});

Expand Down
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export { default as QEdge } from './query_edge';
export { default as QNode } from './query_node';
export { default as InvalidQueryGraphError } from './exceptions/invalid_query_graph_error';
export * from './qedge2apiedge';
export {TrapiQueryGraph, TrapiResponse, TrapiResult}; // better readability
tokebe marked this conversation as resolved.
Show resolved Hide resolved

export default class TRAPIQueryHandler {
logs: StampedLog[];
Expand Down
Loading