@enface/js
Version:
Biometric researches
70 lines (60 loc) • 2.06 kB
JavaScript
import path from 'path';
import * as constants from './__mocks__/constants';
import { readFile } from './__utils__';
import { createEnfaceApi } from '../src';
/* >>>>>>>>> ADD YOUR REAL API KEY >>>>>>>>> */
// const realApiKey = '';
const realApiKey = '5489e05d-b62c-4384-87ec-808a749e3370';
/* <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< */
const version = 1;
const pathToMockedImage = path.resolve(__dirname, './__mocks__/image.jpg');
jest.setTimeout(30000);
describe('EnfaceApi real network tests', () => {
if (!realApiKey) {
console.log(
`\n\n!!!!!!!!!! ADD YOUR REAL API KEY TO TEST API METHODS !!!!!!!!!!
SET VALUE OF VARIABLE "realApiKey" in "__tests__/api.js"
`);
return;
}
let mockedFile1;
let mockedFile2;
let mockedFile3;
const api = createEnfaceApi({
version,
apiKey: realApiKey,
});
beforeAll(async done => {
mockedFile1 = await readFile(pathToMockedImage);
mockedFile2 = mockedFile1;
mockedFile3 = mockedFile1;
done();
});
test('Recognition request using bad api key, expecting rejection', async () => {
const apiLocal = createEnfaceApi({
version,
apiKey: constants.INVALID_KEY,
});
await expect(apiLocal.recognize({ images: [mockedFile1.buffer] }))
.rejects
.toBeInstanceOf(Object);
});
test('Recognition request, should succeed', async () => {
const result = await api.recognize({
images: [mockedFile1],
});
expect(result).toHaveProperty('sessionId');
});
test('Liveness request, should succeed', async () => {
const result = await api.liveness({
images: [mockedFile1.buffer, mockedFile2, mockedFile3],
});
expect(result).toHaveProperty('sessionId');
});
test('Recognize & liveness request, should succeed', async () => {
const result = await api.recognizeLiveness({
images: [mockedFile1.buffer, mockedFile2.buffer, mockedFile3.buffer],
});
expect(result).toHaveProperty('sessionId');
});
});