mirror of
https://github.com/selfxyz/self.git
synced 2026-01-09 14:48:06 -05:00
fix demo app tests (#1223)
This commit is contained in:
@@ -1,2 +1,9 @@
|
||||
export { extractMRZInfo, formatDateToYYMMDD } from '../../../mobile-sdk-alpha/src/processing/mrz';
|
||||
export type { MRZInfo, MRZValidation } from '../../../mobile-sdk-alpha/src/types/public';
|
||||
|
||||
// Mock the onboarding/read-mrz module
|
||||
export const MRZScannerView = ({ onScan: _onScan, onError: _onError, ...props }: any) => {
|
||||
// Mock component for testing
|
||||
void props; // Explicitly mark as intentionally unused
|
||||
return null;
|
||||
};
|
||||
|
||||
@@ -2,10 +2,33 @@
|
||||
// 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 { describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import type { MRZInfo } from '@selfxyz/mobile-sdk-alpha';
|
||||
|
||||
// Mock extractMRZInfo directly in this test file
|
||||
vi.mock('@selfxyz/mobile-sdk-alpha', () => ({
|
||||
__esModule: true,
|
||||
extractMRZInfo: vi.fn((_mrz: string) => {
|
||||
// Mock implementation that returns basic MRZ info
|
||||
return {
|
||||
documentNumber: 'L898902C3',
|
||||
dateOfBirth: '740812',
|
||||
dateOfExpiry: '120415',
|
||||
issuingCountry: 'UTO',
|
||||
documentType: 'P',
|
||||
validation: {
|
||||
format: true,
|
||||
passportNumberChecksum: true,
|
||||
dateOfBirthChecksum: true,
|
||||
dateOfExpiryChecksum: true,
|
||||
compositeChecksum: true,
|
||||
overall: true,
|
||||
},
|
||||
};
|
||||
}),
|
||||
}));
|
||||
|
||||
import { buildValidationRows, formatMRZDate, humanizeDocumentType, normalizeMRZPayload } from '../../src/utils/camera';
|
||||
|
||||
describe('formatMRZDate', () => {
|
||||
|
||||
@@ -8,6 +8,64 @@ import { beforeEach, vi } from 'vitest';
|
||||
|
||||
import { sdkMocks } from './mocks/sdk';
|
||||
|
||||
// Mock @selfxyz/mobile-sdk-alpha
|
||||
vi.mock('@selfxyz/mobile-sdk-alpha', () => {
|
||||
const extractMRZInfo = vi.fn((_mrz: string) => {
|
||||
// Mock implementation that returns basic MRZ info
|
||||
return {
|
||||
documentNumber: 'L898902C3',
|
||||
dateOfBirth: '740812',
|
||||
dateOfExpiry: '120415',
|
||||
issuingCountry: 'UTO',
|
||||
documentType: 'P',
|
||||
validation: {
|
||||
format: true,
|
||||
passportNumberChecksum: true,
|
||||
dateOfBirthChecksum: true,
|
||||
dateOfExpiryChecksum: true,
|
||||
compositeChecksum: true,
|
||||
overall: true,
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
const formatDateToYYMMDD = vi.fn((date: Date) => {
|
||||
const year = date.getFullYear().toString().slice(-2);
|
||||
const month = (date.getMonth() + 1).toString().padStart(2, '0');
|
||||
const day = date.getDate().toString().padStart(2, '0');
|
||||
return `${year}${month}${day}`;
|
||||
});
|
||||
|
||||
return {
|
||||
__esModule: true,
|
||||
extractMRZInfo,
|
||||
formatDateToYYMMDD,
|
||||
};
|
||||
});
|
||||
|
||||
// Mock the onboarding/read-mrz module
|
||||
vi.mock('@selfxyz/mobile-sdk-alpha/onboarding/read-mrz', () => ({
|
||||
__esModule: true,
|
||||
MRZScannerView: ({ onScan: _onScan, onError: _onError, ...props }: any) => {
|
||||
// Mock component for testing
|
||||
void props; // Explicitly mark as intentionally unused
|
||||
return null;
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock the DocumentCamera component to avoid import issues
|
||||
vi.mock('../src/screens/DocumentCamera', () => ({
|
||||
__esModule: true,
|
||||
default: ({ onBack }: { onBack: () => void }) => {
|
||||
// Mock component for testing that returns the expected content
|
||||
return createElement('div', null, [
|
||||
createElement('h1', { key: 'title' }, 'Document Camera'),
|
||||
createElement('p', { key: 'description' }, 'Camera-based document scanning'),
|
||||
createElement('button', { key: 'back', onClick: onBack }, 'Back'),
|
||||
]);
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('@selfxyz/common', async () => {
|
||||
const actual = await vi.importActual<any>('../../../common/dist/cjs/index.cjs');
|
||||
const nodeCrypto = await import('node:crypto');
|
||||
|
||||
@@ -30,10 +30,6 @@ export default defineConfig({
|
||||
},
|
||||
resolve: {
|
||||
alias: [
|
||||
{
|
||||
find: '@selfxyz/mobile-sdk-alpha',
|
||||
replacement: resolve(__dirname, './tests/mocks/mobile-sdk-alpha.ts'),
|
||||
},
|
||||
{
|
||||
find: 'react-native',
|
||||
replacement: resolve(__dirname, './tests/mocks/react-native.ts'),
|
||||
|
||||
Reference in New Issue
Block a user