Skip to content

Commit

Permalink
test: update tests to typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
tokebe committed Oct 6, 2023
1 parent f7ae525 commit b03eaab
Show file tree
Hide file tree
Showing 28 changed files with 1,804 additions and 1,270 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const BatchEdgeQueryHandler = require('../../src/batch_edge_query');
const meta_kg = require('@biothings-explorer/smartapi-kg');
import BatchEdgeQueryHandler from '../../src/batch_edge_query';
import MetaKG from '@biothings-explorer/smartapi-kg';

describe('Testing BatchEdgeQueryHandler Module', () => {
const kg = new meta_kg.default();
const kg = new MetaKG();
kg.constructMetaKGSync();

describe('Testing query function', () => {
Expand Down
166 changes: 0 additions & 166 deletions __test__/integration/KnowledgeGraph.test.js

This file was deleted.

156 changes: 156 additions & 0 deletions __test__/integration/KnowledgeGraph.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
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';

describe('Testing KnowledgeGraph Module', () => {
const nodeInput = new KGNode('PUBCHEM.COMPOUND:2662-n0', {
primaryCurie: 'PUBCHEM.COMPOUND:2662',
qNodeID: 'n0',
curies: [
'PUBCHEM.COMPOUND:2662',
'CHEMBL.COMPOUND:CHEMBL118',
'UNII:JCX84Q7J1L',
'CHEBI:41423',
'DRUGBANK:DB00482',
'MESH:C105934',
'MESH:D000068579',
'CAS:169590-42-5',
'CAS:184007-95-2',
'CAS:194044-54-7',
'DrugCentral:568',
'GTOPDB:2892',
'HMDB:HMDB0005014',
'KEGG.COMPOUND:C07589',
'INCHIKEY:RZEKVGVHFLEQIL-UHFFFAOYSA-N',
],
names: ['Celecoxib', 'CELECOXIB', 'celecoxib', '[OBSOLETE] celecoxib'],
semanticType: ['biolink:SmallMolecule'],
label: 'Celecoxib',
});

const trapiEdgeInput = new KGEdge('PUBCHEM.COMPOUND:2662-biolink:activity_decreased_by-NCBIGene:771', {
predicate: 'biolink:activity_decreased_by',
subject: 'PUBCHEM.COMPOUND:2662',
object: 'NCBIGene:771',
});

trapiEdgeInput.addAdditionalAttributes('edge-attributes', [
{
attribute_type_id: 'biolink:Attribute',
value: 'Ki',
value_type_id: 'EDAM:data_0006',
original_attribute_name: 'affinity_parameter',
value_url: null,
attribute_source: null,
description: null,
},
{
attribute_type_id: 'biolink:knowledge_source',
value: ['PHAROS_1_norm_edges.jsonl'],
value_type_id: 'EDAM:data_0006',
original_attribute_name: 'knowledge_source',
value_url: null,
attribute_source: null,
description: null,
},
{
attribute_type_id: 'biolink:aggregator_knowledge_source',
value: ['infores:pharos'],
value_type_id: 'biolink:InformationResource',
original_attribute_name: 'biolink:aggregator_knowledge_source',
value_url: null,
attribute_source: null,
description: null,
},
{
attribute_type_id: 'biolink:Attribute',
value: 7.75,
value_type_id: 'EDAM:data_0006',
original_attribute_name: 'affinity',
value_url: null,
attribute_source: null,
description: null,
},
{
attribute_type_id: 'biolink:publications',
value: [
'PMID:20605094',
'PMID:21852133',
'PMID:16290146',
'PMID:23965175',
'PMID:23965175',
'PMID:24513184',
'PMID:25766630',
'PMID:23067387',
],
value_type_id: 'EDAM:data_0006',
original_attribute_name: 'publications',
value_url: null,
attribute_source: null,
description: null,
},
{
attribute_type_id: 'biolink:relation',
value: 'GAMMA:ki',
value_type_id: 'EDAM:data_0006',
original_attribute_name: 'relation',
value_url: null,
attribute_source: null,
description: null,
},
{
attribute_type_id: 'biolink:aggregator_knowledge_source',
value: 'infores:automat.pharos',
value_type_id: 'biolink:InformationResource',
original_attribute_name: 'biolink:aggregator_knowledge_source',
value_url: null,
attribute_source: null,
description: null,
},
]);

describe('Testing _createNode function', () => {
test('test creating node', () => {
const kg = new KnowledgeGraph();
const res = kg._createNode(nodeInput);
expect(res).toHaveProperty('name', 'Celecoxib');
expect(res).toHaveProperty('categories');
expect(res.categories[0]).toBe('biolink:SmallMolecule');
expect(res).toHaveProperty('attributes');
});
});

describe('Testing _createAttributes function', () => {
test('test edge attributes', () => {
const kg = new KnowledgeGraph();
const res = kg._createAttributes(trapiEdgeInput);
expect(res.length).toBeGreaterThan(0);
for (const res_obj of res) {
expect(res_obj).toHaveProperty('attribute_type_id');
expect(res_obj).toHaveProperty('value');
if (res_obj.attribute_type_id.includes('biolink:')) {
expect(res_obj).toHaveProperty('value_type_id');
}
}
});
});

describe('Testing _createEdge function', () => {
test('test creating edge', () => {
const kg = new KnowledgeGraph();
const res = kg._createEdge(trapiEdgeInput);
expect(res).toHaveProperty('predicate', 'biolink:activity_decreased_by');
expect(res).toHaveProperty('subject', 'PUBCHEM.COMPOUND:2662');
expect(res).toHaveProperty('object', 'NCBIGene:771');
expect(res).toHaveProperty('attributes');
for (const res_obj of res.attributes as TrapiAttribute[]) {
expect(res_obj).toHaveProperty('attribute_type_id');
expect(res_obj).toHaveProperty('value');
if (res_obj.attribute_type_id.includes('biolink:')) {
expect(res_obj).toHaveProperty('value_type_id');
}
}
});
});
});
Loading

0 comments on commit b03eaab

Please sign in to comment.