Skip to content

Commit

Permalink
Merge pull request #57 from biothings/typescript
Browse files Browse the repository at this point in the history
Support workspace/typescript migration
  • Loading branch information
tokebe authored Oct 24, 2023
2 parents d6723f5 + d7c096e commit e8a3085
Show file tree
Hide file tree
Showing 32 changed files with 1,248 additions and 15,491 deletions.
35 changes: 0 additions & 35 deletions .github/workflows/test_and_coverage.yml

This file was deleted.

22 changes: 14 additions & 8 deletions .github/workflows/test_ws_codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,24 @@ jobs:
- uses: actions/checkout@v3
with:
repository: biothings/biothings_explorer
ref: ${{ steps.branch-name.outputs.current_branch }}

- name: Use Node.js 16.x
uses: actions/setup-node@v1
- name: Use Node.js 18.x
uses: actions/setup-node@v3
with:
node-version: 16.x
node-version: 18.x

- name: npm install, generate coverage report
- name: Use pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: pnpm install, generate coverage report
run: |
npm run clone
npm run git checkout ${{ steps.branch-name.outputs.current_branch }}
npm i || true && npm i
npm run test-cov --workspace=@biothings-explorer/api-response-transform
pnpm run clone
pnpm run git checkout ${{ steps.branch-name.outputs.current_branch }}
pnpm i
pnpm --filter api-response-transform test-cov
- name: Send coverage report to codecov for visualization
uses: codecov/codecov-action@v3
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ typings/
# TypeScript cache
*.tsbuildinfo

# Turbo cache
.turbo

# Optional npm cache directory
.npm

Expand Down Expand Up @@ -105,4 +108,4 @@ dist

kevin.js

/built
/built
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ A NodeJS module to transform the JSON output from APIs into BioLink-compatible J
## Install

```sh
npm i @biothings-explorer/api-response-transform
pnpm i @biothings-explorer/api-response-transform
```

## Usage
Expand Down Expand Up @@ -144,7 +144,7 @@ This package is desgined to be used as a downstream consumer of [@biothings-expl
## Run tests

```sh
npm run test
pnpm run test
```

## Author
Expand Down
205 changes: 101 additions & 104 deletions __test__/base_transformer.test.ts
Original file line number Diff line number Diff line change
@@ -1,121 +1,118 @@
import {describe, expect, test} from '@jest/globals';

import base_tf from "../src/transformers/transformer";
import fs from "fs";
import path from "path";
import { JSONDoc } from '../src/json_transform/types';
import { JSONDoc } from "../src/json_transform/types";

describe("test base transformer", () => {
let response;
let input;

let response;
let input;

beforeEach(() => {
const response_path = path.resolve(__dirname, './data/ols/response.json');
response = JSON.parse(fs.readFileSync(response_path, { encoding: 'utf8' }));
const edge_path = path.resolve(__dirname, './data/ols/edge.json');
const edge = JSON.parse(fs.readFileSync(edge_path, { encoding: 'utf8' }));
input = {
response,
edge
}
})
beforeEach(() => {
const response_path = path.resolve(__dirname, "./data/ols/response.json");
response = JSON.parse(fs.readFileSync(response_path, { encoding: "utf8" }));
const edge_path = path.resolve(__dirname, "./data/ols/edge.json");
const edge = JSON.parse(fs.readFileSync(edge_path, { encoding: "utf8" }));
input = {
response,
edge,
};
});

test("Test pairInputWithAPIResponse function", () => {
const tf = new base_tf(input, {});
const res = tf.pairCurieWithAPIResponse();
expect(res).toHaveProperty("DOID:9562");
expect(res["DOID:9562"]).toHaveLength(1);
})
test("Test pairInputWithAPIResponse function", () => {
const tf = new base_tf(input, {});
const res = tf.pairCurieWithAPIResponse();
expect(res).toHaveProperty("DOID:9562");
expect(res["DOID:9562"]).toHaveLength(1);
});

test("Test wrap function if response is not an array", () => {
const tf = new base_tf(input, {});
const res = tf.wrap(response);
expect(res).toHaveProperty("_embedded");
})
test("Test wrap function if response is not an array", () => {
const tf = new base_tf(input, {});
const res = tf.wrap(response);
expect(res).toHaveProperty("_embedded");
});

test("Test wrap function if response is an array", () => {
const tf = new base_tf(input, {});
const fake = ["1"]
const res = tf.wrap(fake);
expect(res).toHaveProperty("data");
expect(res.data).toEqual(["1"])
})
test("Test wrap function if response is an array", () => {
const tf = new base_tf(input, {});
const fake = ["1"];
const res = tf.wrap(fake);
expect(res).toHaveProperty("data");
expect(res.data).toEqual(["1"]);
});

test("Test jsonTransform function", () => {
const tf = new base_tf(input, {});
const res: JSONDoc = tf.jsonTransform(response);
expect(res).toHaveProperty("has_subclass");
expect(res.has_subclass[0]).toHaveProperty("DOID");
expect(res.has_subclass[0].DOID).toEqual("DOID:0110596");
expect(res.has_subclass[0].name).toEqual("primary ciliary dyskinesia 21");
expect(res.has_subclass[0].description).toEqual([
"A primary ciliary dyskinesia that is characterized by autosomal recessive inheritance with a missing Nexin link, infantile onset of chronic sinopulmonary infections, and has_material_basis_in homozygous mutation in the DRC1 gene on chromosome 2p23."
]);
})
test("Test jsonTransform function", () => {
const tf = new base_tf(input, {});
const res: JSONDoc = tf.jsonTransform(response);
expect(res).toHaveProperty("has_subclass");
expect(res.has_subclass[0]).toHaveProperty("DOID");
expect(res.has_subclass[0].DOID).toEqual("DOID:0110596");
expect(res.has_subclass[0].name).toEqual("primary ciliary dyskinesia 21");
expect(res.has_subclass[0].description).toEqual([
"A primary ciliary dyskinesia that is characterized by autosomal recessive inheritance with a missing Nexin link, infantile onset of chronic sinopulmonary infections, and has_material_basis_in homozygous mutation in the DRC1 gene on chromosome 2p23.",
]);
});

test("Test _updatePublications function if pubmed id is prefixed", () => {
const tf = new base_tf(input, {});
const fake = {
ref_pmid: "PMID:1233"
}
const res = tf._updatePublications(fake);
expect(res).not.toHaveProperty('ref_pmid');
expect(res.publications).toEqual(["PMID:1233"]);
})
test("Test _updatePublications function if pubmed id is prefixed", () => {
const tf = new base_tf(input, {});
const fake = {
ref_pmid: "PMID:1233",
};
const res = tf._updatePublications(fake);
expect(res).not.toHaveProperty("ref_pmid");
expect(res.publications).toEqual(["PMID:1233"]);
});

test("Test _updatePublications function if pubmed id is NOT prefixed", () => {
const tf = new base_tf(input, {});
const fake = {
ref_pmid: 1233
}
const res = tf._updatePublications(fake);
expect(res).not.toHaveProperty('ref_pmid');
expect(res.publications).toEqual(["PMID:1233"])
})
test("Test _updatePublications function if pubmed id is NOT prefixed", () => {
const tf = new base_tf(input, {});
const fake = {
ref_pmid: 1233,
};
const res = tf._updatePublications(fake);
expect(res).not.toHaveProperty("ref_pmid");
expect(res.publications).toEqual(["PMID:1233"]);
});

test("Test _updatePublications function if pmc id is prefixed", () => {
const tf = new base_tf(input, {});
const fake = {
ref_pmcid: "PMCID:1233"
}
const res = tf._updatePublications(fake);
expect(res).not.toHaveProperty('ref_pmcid');
expect(res.publications).toEqual(["PMCID:1233"]);
})
test("Test _updatePublications function if pmc id is prefixed", () => {
const tf = new base_tf(input, {});
const fake = {
ref_pmcid: "PMCID:1233",
};
const res = tf._updatePublications(fake);
expect(res).not.toHaveProperty("ref_pmcid");
expect(res.publications).toEqual(["PMCID:1233"]);
});

test("Test _updatePublications function if pmc id is NOT prefixed", () => {
const tf = new base_tf(input, {});
const fake = {
ref_pmcid: 123
}
const res = tf._updatePublications(fake);
expect(res).not.toHaveProperty('ref_pmcid');
expect(res.publications).toEqual(["PMCID:123"])
})
test("Test _updatePublications function if pmc id is NOT prefixed", () => {
const tf = new base_tf(input, {});
const fake = {
ref_pmcid: 123,
};
const res = tf._updatePublications(fake);
expect(res).not.toHaveProperty("ref_pmcid");
expect(res.publications).toEqual(["PMCID:123"]);
});

test("Test extractObjectIDs function if output id type not in result", () => {
const tf = new base_tf(input, {});
const fake = {
kk: 1
};
const res = tf.extractObjectIDs(fake);
expect(res).toEqual([]);
})
test("Test extractObjectIDs function if output id type not in result", () => {
const tf = new base_tf(input, {});
const fake = {
kk: 1,
};
const res = tf.extractObjectIDs(fake);
expect(res).toEqual([]);
});

test("Test extractObjectIDs function if output id type is in result", () => {
const tf = new base_tf(input, {});
const fake = {
DOID: 1
};
const res = tf.extractObjectIDs(fake);
expect(res).toEqual(["DOID:1"]);
})
test("Test extractObjectIDs function if output id type is in result", () => {
const tf = new base_tf(input, {});
const fake = {
DOID: 1,
};
const res = tf.extractObjectIDs(fake);
expect(res).toEqual(["DOID:1"]);
});

test("Test formatRecords function if result is empty", async () => {
const tf = new base_tf(input, {});
const fake = {};
const res = await tf.formatRecords("NCBIGene:1017", fake);
expect(res).toEqual([]);
})
})
test("Test formatRecords function if result is empty", async () => {
const tf = new base_tf(input, {});
const fake = {};
const res = await tf.formatRecords("NCBIGene:1017", fake);
expect(res).toEqual([]);
});
});
Loading

0 comments on commit e8a3085

Please sign in to comment.