This repository has been archived by the owner on Oct 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from regulaforensics/develop
The tests are redesigned to work on the server (with the directory wi…
- Loading branch information
Showing
33 changed files
with
744 additions
and
151,425 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
PROCESS_RESPONSE_JSONS_DIR=/Users/cooler/Projects/Regula/document-reader-recipes/testdata |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 33 additions & 6 deletions
39
...cipes/authenticity/get-authenticity-check-list/get-authenticity-check-list.recipe.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,44 @@ | ||
import { ProcessResponse } from '@regulaforensics/document-reader-typings' | ||
import { readdirSync, readFileSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
import rawDocReaderResponse from '@/test-data/1.json' | ||
import { getAuthenticityCheckList } from './get-authenticity-check-list.recipe' | ||
|
||
|
||
const DIRECTORY = String(process.env.PROCESS_RESPONSE_JSONS_DIR) | ||
|
||
describe('getAuthenticityCheckList', () => { | ||
const docReaderResponse = ProcessResponse.fromPlain(rawDocReaderResponse) | ||
const files = readdirSync(DIRECTORY) | ||
|
||
files.forEach((file) => { | ||
const filePath = join(DIRECTORY, file) | ||
|
||
if (!filePath.endsWith('.json')) { | ||
return | ||
} | ||
|
||
const fileContent = readFileSync(filePath, 'utf-8') | ||
|
||
let isValidJSON = true | ||
let response = '' | ||
|
||
try { | ||
response = JSON.parse(fileContent) | ||
} catch (e) { | ||
isValidJSON = false | ||
} | ||
|
||
test(`file '${file}': should be a valid JSON`, () => { | ||
expect(isValidJSON).toBe(true) | ||
}) | ||
|
||
const docReaderResponse = ProcessResponse.fromPlain(response) | ||
|
||
test('should valid result', () => { | ||
const result = getAuthenticityCheckList(docReaderResponse) | ||
|
||
console.log(JSON.stringify(result)) | ||
test(`file '${file}': should return authenticity check list`, () => { | ||
const result = getAuthenticityCheckList(docReaderResponse) | ||
|
||
expect(result).toBeDefined() | ||
expect(result).toBeDefined() | ||
}) | ||
}) | ||
}) |
43 changes: 34 additions & 9 deletions
43
src/recipes/barcode/document-barcodes/get-document-barcodes.recipe.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,45 @@ | ||
import { ProcessResponse } from '@regulaforensics/document-reader-typings' | ||
import { readdirSync, readFileSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
import rawDocReaderResponse from '@/test-data/7.json' | ||
import { RDocumentBarcode } from './models' | ||
import { getDocumentBarcodes } from './get-document-barcodes.recipe' | ||
|
||
|
||
const DIRECTORY = String(process.env.PROCESS_RESPONSE_JSONS_DIR) | ||
|
||
describe('getDocumentBarcodes', () => { | ||
const docReaderResponse = ProcessResponse.fromPlain(rawDocReaderResponse) | ||
const result = getDocumentBarcodes(docReaderResponse) | ||
const isValid = RDocumentBarcode.isValid(result) | ||
const files = readdirSync(DIRECTORY) | ||
|
||
test('should return non-empty array of images', () => { | ||
expect(result.length).toBeGreaterThan(0) | ||
}) | ||
files.forEach((file) => { | ||
const filePath = join(DIRECTORY, file) | ||
|
||
if (!filePath.endsWith('.json')) { | ||
return | ||
} | ||
|
||
const fileContent = readFileSync(filePath, 'utf-8') | ||
|
||
let isValidJSON = true | ||
let response = '' | ||
|
||
try { | ||
response = JSON.parse(fileContent) | ||
} catch (e) { | ||
isValidJSON = false | ||
} | ||
|
||
test(`file '${file}': should be a valid JSON`, () => { | ||
expect(isValidJSON).toBe(true) | ||
}) | ||
|
||
|
||
const docReaderResponse = ProcessResponse.fromPlain(response) | ||
const result = getDocumentBarcodes(docReaderResponse) | ||
const isValid = RDocumentBarcode.isValid(result) | ||
|
||
test('should return valid array of images', () => { | ||
expect(isValid).toBe(true) | ||
test(`file '${file}': should return valid array of images`, () => { | ||
expect(isValid).toBe(true) | ||
}) | ||
}) | ||
}) |
53 changes: 42 additions & 11 deletions
53
src/recipes/image/document-images/get-document-images.recipe.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,54 @@ | ||
import 'reflect-metadata' | ||
import { join } from 'path' | ||
import { readdirSync, readFileSync } from 'fs' | ||
import { ProcessResponse } from '@regulaforensics/document-reader-typings' | ||
|
||
import rawDocReaderResponse from '@/test-data/2.json' | ||
import { RDocumentImage } from './models' | ||
import { getDocumentImages } from './get-document-images.recipe' | ||
|
||
|
||
const DIRECTORY = String(process.env.PROCESS_RESPONSE_JSONS_DIR) | ||
|
||
describe('getDocumentImage', () => { | ||
const docReaderResponse = ProcessResponse.fromPlain(rawDocReaderResponse) | ||
let result: RDocumentImage[] = [] | ||
const files = readdirSync(DIRECTORY) | ||
|
||
for (let i = 0; i < files.length; i++) { | ||
const file = files[i] | ||
const filePath = join(DIRECTORY, file) | ||
|
||
if (!filePath.endsWith('.json')) { | ||
continue | ||
} | ||
|
||
const fileContent = readFileSync(filePath, 'utf-8') | ||
|
||
let isValidJSON = true | ||
let response = '' | ||
|
||
try { | ||
response = JSON.parse(fileContent) | ||
} catch (e) { | ||
isValidJSON = false | ||
} | ||
|
||
test(`file '${file}': should be a valid JSON`, () => { | ||
expect(isValidJSON).toBe(true) | ||
}) | ||
|
||
const docReaderResponse = ProcessResponse.fromPlain(response) | ||
|
||
test('should return non-empty array of images', async () => { | ||
result = await getDocumentImages(docReaderResponse) | ||
test(`file '${file}': should return non-empty array of images`, async() => { | ||
let result: RDocumentImage[] = await getDocumentImages(docReaderResponse) | ||
|
||
expect(result.length).toBeGreaterThan(0) | ||
}) | ||
expect(result.length).toBeGreaterThan(0) | ||
}) | ||
|
||
test('should return valid array of images', () => { | ||
const isValid = RDocumentImage.isValid(result) | ||
/* | ||
test('should return valid array of images', () => { | ||
const isValid = RDocumentImage.isValid(result) | ||
expect(isValid).toBe(true) | ||
}) | ||
expect(isValid).toBe(true) | ||
}) | ||
*/ | ||
} | ||
}) |
60 changes: 47 additions & 13 deletions
60
src/recipes/image/graphic-field/get-document-front.recipe.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,59 @@ | ||
import 'reflect-metadata' | ||
import { readdirSync, readFileSync } from 'fs' | ||
import { join } from 'path' | ||
import { ProcessResponse } from '@regulaforensics/document-reader-typings' | ||
|
||
import rawDocReaderResponse from '@/test-data/0.json' | ||
import { RGraphicField } from './models' | ||
import { getDocumentFront } from './get-document-front.recipe' | ||
|
||
|
||
const DIRECTORY = String(process.env.PROCESS_RESPONSE_JSONS_DIR) | ||
|
||
describe('getDocumentFront', () => { | ||
let result: RGraphicField | ||
const docReaderResponse = ProcessResponse.fromPlain(rawDocReaderResponse) | ||
const files = readdirSync(DIRECTORY) | ||
|
||
test('should be defined', async () => { | ||
result = await getDocumentFront(docReaderResponse) | ||
expect(result).toBeDefined() | ||
}) | ||
files.forEach(async (file) => { | ||
const filePath = join(DIRECTORY, file) | ||
|
||
test('should return valid image', () => { | ||
expect(result.src).toMatch(/^data:image\/jpeg;base64/) | ||
}) | ||
if (!filePath.endsWith('.json')) { | ||
return | ||
} | ||
|
||
const fileContent = readFileSync(filePath, 'utf-8') | ||
|
||
let isValidJSON = true | ||
let response = '' | ||
|
||
try { | ||
response = JSON.parse(fileContent) | ||
} catch (e) { | ||
isValidJSON = false | ||
} | ||
|
||
test(`file '${file}': should be a valid JSON`, () => { | ||
expect(isValidJSON).toBe(true) | ||
}) | ||
|
||
const docReaderResponse = ProcessResponse.fromPlain(response) | ||
|
||
|
||
test(`file '${file}': should be defined`, async () => { | ||
let result: RGraphicField = await getDocumentFront(docReaderResponse) | ||
|
||
expect(result).toBeDefined() | ||
}) | ||
|
||
test(`file '${file}': should return valid image`, async () => { | ||
let result: RGraphicField = await getDocumentFront(docReaderResponse) | ||
|
||
expect(result.src).toMatch(/^data:image\/jpeg;base64/) | ||
}) | ||
|
||
test(`file '${file}': should return valid model`, async () => { | ||
let result: RGraphicField = await getDocumentFront(docReaderResponse) | ||
|
||
test('should return valid model', () => { | ||
const isValid = RGraphicField.isValid(result) | ||
expect(isValid).toBeTruthy() | ||
const isValid = RGraphicField.isValid(result) | ||
expect(isValid).toBeTruthy() | ||
}) | ||
}) | ||
}) |
71 changes: 50 additions & 21 deletions
71
src/recipes/image/graphic-field/get-graphic-field.recipe.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,68 @@ | ||
import { eGraphicFieldType, eLights, ProcessResponse } from '@regulaforensics/document-reader-typings' | ||
import { readdirSync, readFileSync } from 'fs' | ||
import { join } from 'path' | ||
|
||
import rawDocReaderResponse from '@/test-data/0.json' | ||
import { RGraphicField } from './models' | ||
import { getGraphicField } from './get-graphic-field.recipe' | ||
|
||
|
||
const DIRECTORY = String(process.env.PROCESS_RESPONSE_JSONS_DIR) | ||
|
||
describe('getGraphicField', () => { | ||
const docReaderResponse = ProcessResponse.fromPlain(rawDocReaderResponse) | ||
let result: RGraphicField | ||
const files = readdirSync(DIRECTORY) | ||
|
||
test('should be defined', async () => { | ||
result = await getGraphicField(docReaderResponse, eGraphicFieldType.DOCUMENT_FRONT) | ||
files.forEach(async (file) => { | ||
const filePath = join(DIRECTORY, file) | ||
|
||
expect(result).toBeDefined() | ||
}) | ||
if (!filePath.endsWith('.json')) { | ||
return | ||
} | ||
|
||
test('should return valid image', async () => { | ||
expect(result.src).toMatch(/^data:image\/jpeg;base64/) | ||
}) | ||
const fileContent = readFileSync(filePath, 'utf-8') | ||
|
||
test('should be able to return default image', async () => { | ||
const result = await getGraphicField(docReaderResponse, eGraphicFieldType.DOCUMENT_FRONT, true, [eLights.HOLO]) | ||
let isValidJSON = true | ||
let response = '' | ||
|
||
expect(result.src).toMatch(/^data:image\/png;base64/) | ||
}) | ||
try { | ||
response = JSON.parse(fileContent) | ||
} catch (e) { | ||
isValidJSON = false | ||
} | ||
|
||
test('should return undefined if no image found', async () => { | ||
const result = await getGraphicField(docReaderResponse, eGraphicFieldType.PORTRAIT, false, [eLights.HOLO]) | ||
test(`file '${file}': should be a valid JSON`, () => { | ||
expect(isValidJSON).toBe(true) | ||
}) | ||
|
||
expect(result).toBeUndefined() | ||
}) | ||
const docReaderResponse = ProcessResponse.fromPlain(response) | ||
|
||
let result: RGraphicField | ||
|
||
test(`file '${file}': should be defined`, async () => { | ||
result = await getGraphicField(docReaderResponse, eGraphicFieldType.DOCUMENT_FRONT) | ||
|
||
expect(result).toBeDefined() | ||
}) | ||
|
||
test(`file '${file}': should return valid image`, async () => { | ||
expect(result.src).toMatch(/^data:image\/jpeg;base64/) | ||
}) | ||
|
||
test(`file '${file}': should be able to return default image`, async () => { | ||
const result = await getGraphicField(docReaderResponse, eGraphicFieldType.DOCUMENT_FRONT, true, [eLights.HOLO]) | ||
|
||
expect(result.src).toMatch(/^data:image\/png;base64/) | ||
}) | ||
|
||
test(`file '${file}': should return undefined if no image found`, async () => { | ||
const result = await getGraphicField(docReaderResponse, eGraphicFieldType.PORTRAIT, false, [eLights.HOLO]) | ||
|
||
expect(result).toBeUndefined() | ||
}) | ||
|
||
test('should return valid model', async () => { | ||
const isValid = RGraphicField.isValid(result) | ||
test(`file '${file}': should return valid model`, async () => { | ||
const isValid = RGraphicField.isValid(result) | ||
|
||
expect(isValid).toBe(true) | ||
expect(isValid).toBe(true) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.