Skip to content

Commit ecb3321

Browse files
author
Sourabh Jajoria
committed
Test setup
1 parent 2b42a8f commit ecb3321

File tree

5 files changed

+50
-1
lines changed

5 files changed

+50
-1
lines changed

config/test.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"smart-docs-parser": {
3+
"api_keys": {
4+
"google-vision": "TEST_KEY"
5+
}
6+
}
7+
}

jestconfig.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"transform": {
3+
"^.+\\.(t|j)sx?$": "ts-jest"
4+
},
5+
"testRegex": "(/__tests__/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$",
6+
"moduleFileExtensions": ["ts", "tsx", "js", "jsx", "json", "node"]
7+
}

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"main": "lib/index.js",
66
"typings": "lib/index.d.ts",
77
"scripts": {
8-
"test": "echo \"Error: no test specified\" && exit 1",
8+
"test": "jest --config jestconfig.json",
99
"build": "tsc",
1010
"lint": "tslint -p tsconfig.json"
1111
},
@@ -35,8 +35,11 @@
3535
"request-promise": "^4.2.0"
3636
},
3737
"devDependencies": {
38+
"@types/jest": "^25.1.1",
3839
"@types/node": "^13.7.0",
40+
"jest": "^25.1.0",
3941
"prettier": "^1.19.1",
42+
"ts-jest": "^25.2.0",
4043
"tslint": "^6.0.0",
4144
"tslint-config-prettier": "^1.18.0",
4245
"tslint-plugin-prettier": "^2.1.0",

src/_tests_/custom_ocr.mock.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Mock for test
2+
// ******************************************************* //
3+
// Logic for API handlers starts here //
4+
// ******************************************************* //
5+
const extractDocumentText = ({ document_url: documentURL }) => {
6+
return {
7+
raw_text: [documentURL]
8+
};
9+
};
10+
// ******************************************************* //
11+
// Logic for API handlers ends here //
12+
// ******************************************************* //
13+
14+
module.exports = { extractDocumentText };

src/_tests_/custom_ocr.test.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import SmartDocuments from "../index";
2+
3+
test("Custom OCR", async () => {
4+
const extractedDetails = await SmartDocuments.extractDocumentDetailsFromImage(
5+
{
6+
document_url:
7+
"https://avatars2.githubusercontent.com/u/20634933?s=40&v=4",
8+
document_type: "PAN_CARD",
9+
ocr_library: "custom-library",
10+
custom_ocr_path: __dirname + "/custom_ocr.mock.js"
11+
}
12+
);
13+
expect(extractedDetails).toStrictEqual({
14+
raw_text: ["https://avatars2.githubusercontent.com/u/20634933?s=40&v=4"],
15+
is_document_valid: false,
16+
document_details: {}
17+
});
18+
});

0 commit comments

Comments
 (0)