-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathclient-mrz.test.ts
More file actions
47 lines (37 loc) · 1.8 KB
/
client-mrz.test.ts
File metadata and controls
47 lines (37 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// SPDX-FileCopyrightText: 2025 Social Connect Labs, Inc.
// SPDX-License-Identifier: BUSL-1.1
// NOTE: Converts to Apache-2.0 on 2029-06-11 per LICENSE.
import { describe, expect, it } from 'vitest';
import { createSelfClient, MrzParseError } from '../src/index';
import { badCheckDigitsMRZ, expectedMRZResult, invalidMRZ, mockAdapters, sampleMRZ } from './utils/testHelpers';
describe('createSelfClient API', () => {
it('creates a client instance with expected methods', () => {
const client = createSelfClient({ config: {}, adapters: mockAdapters });
expect(typeof client.extractMRZInfo).toBe('function');
expect(typeof client.registerDocument).toBe('function');
expect(typeof client.validateDocument).toBe('function');
});
it('parses MRZ data correctly', () => {
const client = createSelfClient({ config: {}, adapters: mockAdapters });
const info = client.extractMRZInfo(sampleMRZ);
expect(info.passportNumber).toBe(expectedMRZResult.passportNumber);
expect(info.validation.overall).toBe(expectedMRZResult.validation.overall);
});
it('accepts different adapter configurations', () => {
const clientWithAllAdapters = createSelfClient({
config: {},
adapters: mockAdapters,
});
expect(clientWithAllAdapters).toBeDefined();
expect(typeof clientWithAllAdapters.extractMRZInfo).toBe('function');
});
it('throws MrzParseError for malformed MRZ input', () => {
const client = createSelfClient({ config: {}, adapters: mockAdapters });
expect(() => client.extractMRZInfo(invalidMRZ)).toThrowError(MrzParseError);
});
it('flags invalid check digits', () => {
const client = createSelfClient({ config: {}, adapters: mockAdapters });
const info = client.extractMRZInfo(badCheckDigitsMRZ);
expect(info.validation.overall).toBe(false);
});
});