UNPKG

@biothings-explorer/call-apis

Version:

A nodejs module to make api calls for biothings explorer

67 lines (59 loc) 2.59 kB
const q = require("../../src/query"); const fs = require("fs"); const path = require("path"); const axios = require("axios"); describe("Integration test", () => { describe("Integration test using mygene.info gene to biological process association", () => { let edge; beforeEach(() => { const edge_path = path.resolve(__dirname, '../data/mygene_example_edge.json'); edge = JSON.parse(fs.readFileSync(edge_path)); }) test("check response", async () => { const query = new q([edge]); const res = await query.query(); expect(res).toHaveLength(29); }) }) describe("Integration test using text mining co-occurrence KP for disease to chemical association", () => { let edge; beforeEach(() => { const edge_path = path.resolve(__dirname, '../data/cooccurrence_example_edge.json'); edge = JSON.parse(fs.readFileSync(edge_path)); }) test("check response", async () => { const query = new q([edge]); const res = await query.query(false); expect(res).toHaveLength(3762); }) }) describe("Integration test using fake error api query that should return 404 error", () => { let edge; beforeEach(() => { const edge_path = path.resolve(__dirname, '../data/fake_error_edge.json'); edge = JSON.parse(fs.readFileSync(edge_path)); }) test("check response", async () => { const query = new q([edge]); const res = await query.query(false); expect(res).toHaveLength(0); expect(query.logs[query.logs.length - 3]).toHaveProperty('level', 'ERROR'); }) }) describe("Integration test using mydisease superclass_of", () => { let edges; beforeEach(() => { const kg = require("@biothings-explorer/smartapi-kg"); const meta_kg = new kg.default(); meta_kg.constructMetaKGSync(); edges = meta_kg.filter({ api_name: "MyDisease.info API", predicate: "superclass_of" }); edges.map(op => op.input = ["MONDO:0002494"]) }) test("check response", async () => { const query = new q(edges); const res = await query.query(false); const mydisease_res = await axios.get("http://mydisease.info/v1/disease/MONDO:0002494?fields=mondo.descendants&dotfield=true"); expect(res.length).toEqual(mydisease_res.data["mondo.descendants"].length) }) }) })