// SPDX-License-Identifier: BUSL-1.1; Copyright (c) 2025 Social Connect Labs, Inc.; Licensed under BUSL-1.1 (see LICENSE); Apache-2.0 from 2029-06-11 import { Platform } from 'react-native'; import { parseScanResponse } from '../../src/utils/nfcScanner'; describe('parseScanResponse', () => { beforeEach(() => { jest.clearAllMocks(); }); it('parses iOS response', () => { Object.defineProperty(Platform, 'OS', { value: 'ios', writable: true, }); const mrz = 'P { Object.defineProperty(Platform, 'OS', { value: 'android', writable: true, }); const mrz = 'P { Object.defineProperty(Platform, 'OS', { value: 'ios', writable: true, }); const response = '{"invalid": "json"'; expect(() => parseScanResponse(response)).toThrow(); }); it('handles malformed Android response', () => { Object.defineProperty(Platform, 'OS', { value: 'android', writable: true, }); const response = { mrz: 'valid_mrz', eContent: 'invalid_json_string', dataGroupHashes: JSON.stringify({ '1': 'abcd' }), }; expect(() => parseScanResponse(response)).toThrow(); }); it('handles missing required fields', () => { Object.defineProperty(Platform, 'OS', { value: 'ios', writable: true, }); const response = JSON.stringify({ // Providing minimal data but missing critical passportMRZ field dataGroupHashes: JSON.stringify({ DG1: { sodHash: '00' }, // Minimal valid hex DG2: { sodHash: '00' }, // Minimal valid hex }), eContentBase64: Buffer.from('').toString('base64'), signedAttributes: Buffer.from('').toString('base64'), signatureBase64: Buffer.from('').toString('base64'), dataGroupsPresent: [], documentSigningCertificate: JSON.stringify({ PEM: 'CERT' }), // Missing passportMRZ which should cause an error }); expect(() => parseScanResponse(response)).toThrow(); }); it('handles invalid hex data in dataGroupHashes', () => { Object.defineProperty(Platform, 'OS', { value: 'ios', writable: true, }); const response = JSON.stringify({ dataGroupHashes: JSON.stringify({ DG1: { sodHash: 'invalid_hex' }, }), passportMRZ: 'valid_mrz', }); expect(() => parseScanResponse(response)).toThrow(); }); });