Skip to content

Commit

Permalink
Merge branch 'main' into parallel-creative
Browse files Browse the repository at this point in the history
  • Loading branch information
rjawesome committed Sep 6, 2024
2 parents 657cddc + 273b866 commit fa427b6
Show file tree
Hide file tree
Showing 10 changed files with 160 additions and 50 deletions.
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/[email protected]

- 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
1 change: 1 addition & 0 deletions __test__/data/mygene_example_edge.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"api_name": "MyGene.info API",
"smartapi": {},
"x-translator": {
"infores": "infores:mygene-info",
"component": "KP",
"team": ["Service Provider"]
}
Expand Down
20 changes: 16 additions & 4 deletions __test__/unittest/query_builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,10 @@ describe("test query builder class", () => {
// @ts-expect-error TODO: change after APIEdge split from query_graph_handler
const builder = new qb(edge);
const res = builder.needPagination(response);
expect(res).toBeFalsy();
expect(res).toMatchObject({
paginationStart: 0,
paginationSize: 0
});
});

test("biothings tagged api with post method should return false", () => {
Expand All @@ -316,7 +319,10 @@ describe("test query builder class", () => {
// @ts-expect-error TODO: change after APIEdge split from query_graph_handler
const builder = new qb(edge);
const res = builder.needPagination(response);
expect(res).toBeFalsy();
expect(res).toMatchObject({
paginationStart: 0,
paginationSize: 0
});
});

test("biothings tagged api with get method and needs pagniation should return true", () => {
Expand All @@ -333,7 +339,10 @@ describe("test query builder class", () => {
// @ts-expect-error TODO: change after APIEdge split from query_graph_handler
const builder = new qb(edge);
const res = builder.needPagination(response);
expect(res).toBeTruthy();
expect(res).not.toMatchObject({
paginationStart: 0,
paginationSize: 0
});
});

test("biothings tagged api with get method and doesn't need pagniation should return false", () => {
Expand All @@ -350,7 +359,10 @@ describe("test query builder class", () => {
// @ts-expect-error TODO: change after APIEdge split from query_graph_handler
const builder = new qb(edge);
const res = builder.needPagination(response);
expect(res).toBeFalsy();
expect(res).toMatchObject({
paginationStart: 0,
paginationSize: 0
});
});
});
});
87 changes: 61 additions & 26 deletions __test__/unittest/template_query_builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import qb from "../../src/builder/template_query_builder";
import path from "path";
import fs from "fs";
import { QueryHandlerOptions } from "../../src/types";

describe("test query builder class", () => {
describe("test _getUrl function", () => {
Expand All @@ -15,8 +16,9 @@ describe("test query builder class", () => {
path: "/query",
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getUrl(edge, "hello");
expect(res).toBe("https://google.com/query");
Expand All @@ -29,8 +31,9 @@ describe("test query builder class", () => {
path: "/query",
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getUrl(edge, "hello");
expect(res).toBe("https://google.com/query");
Expand All @@ -48,8 +51,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getUrl(edge, "hello");
expect(res).toBe("https://google.com/1017/query");
Expand All @@ -67,8 +71,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getUrl(edge, { queryInputs: "hello" });
expect(res).toBe("https://google.com/hello/json/query");
Expand All @@ -77,7 +82,8 @@ describe("test query builder class", () => {
test("if _getUrl nunjucks templates are filled", () => {
const edge_path = path.resolve(__dirname, "../data/multi_input_edge.json");
const edge = JSON.parse(fs.readFileSync(edge_path, { encoding: "utf8" }));
const builder = new qb(edge);
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
const builder = new qb(edge, queryHandlerOptions);
const res = builder._getUrl(edge, {
specialpath: "/querytest",
id: "MONDO:0005252",
Expand All @@ -96,8 +102,9 @@ describe("test query builder class", () => {
supportBatch: true,
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getInput(edge);
expect(res).toEqual(edge.input);
Expand All @@ -110,8 +117,9 @@ describe("test query builder class", () => {
supportBatch: true,
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getInput(edge);
expect(res).toEqual(["kevin", "xin"]);
Expand All @@ -124,8 +132,9 @@ describe("test query builder class", () => {
supportBatch: false,
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getInput(edge);
expect(res).toEqual(edge.input);
Expand All @@ -144,8 +153,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getParams(edge, { queryInputs: "1017" });
expect(res).toHaveProperty("geneid");
Expand All @@ -164,8 +174,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getParams(edge, "1017");
expect(res).not.toHaveProperty("geneid");
Expand All @@ -184,8 +195,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getParams(edge, { queryInputs: "1017" });
expect(res).not.toHaveProperty("geneid");
Expand All @@ -204,8 +216,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getParams(edge, "1017");
expect(res.output).toEqual(1);
Expand All @@ -215,7 +228,8 @@ describe("test query builder class", () => {
const edge_path = path.resolve(__dirname, "../data/multi_input_edge.json");
const edge = JSON.parse(fs.readFileSync(edge_path, { encoding: "utf8" }));

const builder = new qb(edge);
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
const builder = new qb(edge, queryHandlerOptions);
const res = builder._getParams(edge, {
specialpath: "/querytest",
id: "MONDO:0005252",
Expand Down Expand Up @@ -243,8 +257,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getRequestBody(edge, "1017");
expect(res).toBeUndefined;
Expand All @@ -263,8 +278,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getRequestBody(edge, "1017");
expect(res).toEqual("geneid=hello&output=1");
Expand All @@ -283,8 +299,9 @@ describe("test query builder class", () => {
},
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const res = builder._getRequestBody(edge, { queryInputs: "1017" });
expect(res).toEqual("geneid=hello&output=1017");
Expand All @@ -294,7 +311,8 @@ describe("test query builder class", () => {
const edge_path = path.resolve(__dirname, "../data/multi_input_edge.json");
const edge = JSON.parse(fs.readFileSync(edge_path, { encoding: "utf8" }));

const builder = new qb(edge);
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
const builder = new qb(edge, queryHandlerOptions);
const res = builder._getRequestBody(edge, {
specialpath: "/querytest",
id: "MONDO:0005252",
Expand All @@ -320,8 +338,9 @@ describe("test query builder class", () => {
method: "get",
},
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
const res = builder.constructAxiosRequestConfig();
expect(res.url).toEqual("https://google.com/1017/query");
expect(res.params).not.toHaveProperty("geneid");
Expand All @@ -343,10 +362,14 @@ describe("test query builder class", () => {
total: 1000,
hits: new Array(400),
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
const res = builder.needPagination(response);
expect(res).toBeFalsy();
expect(res).toMatchObject({
paginationStart: 0,
paginationSize: 0
});
});

test("biothings tagged api with post method should return false", () => {
Expand All @@ -361,10 +384,14 @@ describe("test query builder class", () => {
total: 1000,
hits: new Array(400),
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
const res = builder.needPagination(response);
expect(res).toBeFalsy();
expect(res).toMatchObject({
paginationStart: 0,
paginationSize: 0
});
});

test("biothings tagged api with get method and needs pagniation should return true", () => {
Expand All @@ -378,10 +405,14 @@ describe("test query builder class", () => {
total: 1000,
hits: new Array(400),
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
const res = builder.needPagination(response);
expect(res).toBeTruthy();
expect(res).not.toMatchObject({
paginationStart: 0,
paginationSize: 0
});
});

test("biothings tagged api with get method and doesn't need pagniation should return false", () => {
Expand All @@ -395,10 +426,14 @@ describe("test query builder class", () => {
total: 1000,
hits: new Array(1000),
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new qb(edge);
const builder = new qb(edge, queryHandlerOptions);
const res = builder.needPagination(response);
expect(res).toBeFalsy();
expect(res).toMatchObject({
paginationStart: 0,
paginationSize: 0
});
});
});
});
4 changes: 3 additions & 1 deletion __test__/unittest/trapi_query_builder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
*/

import TRAPIQueryBuilder from "../../src/builder/trapi_query_builder";
import { QueryHandlerOptions } from "../../src/types";

describe("test trapi query builder class", () => {
describe("test getConfig function", () => {
Expand All @@ -19,8 +20,9 @@ describe("test trapi query builder class", () => {
},
input: ["123", "456"],
};
const queryHandlerOptions: QueryHandlerOptions = {caching: false};
// @ts-expect-error TODO: change after extracting APIEdge from query_graph_handler
const builder = new TRAPIQueryBuilder(edge);
const builder = new TRAPIQueryBuilder(edge, queryHandlerOptions);
const res = builder.getConfig();
expect(res).toHaveProperty("url", "https://google.com/query");
expect(res.data.message.query_graph.nodes.n0.ids).toEqual(["123", "456"]);
Expand Down
4 changes: 2 additions & 2 deletions src/builder/base_query_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ export default class BaseQueryBuilder {
return config;
}

needPagination(apiResponse: unknown): number {
needPagination(apiResponse: unknown): {paginationStart: number, paginationSize: number} {
// implemented in subclasses
return 0;
return {paginationSize: 0, paginationStart: 0};
}

getNext(): AxiosRequestConfig {
Expand Down
Loading

0 comments on commit fa427b6

Please sign in to comment.