From 27d067c180f16dc1f708d7263ced2d32a582175e Mon Sep 17 00:00:00 2001 From: Evi Nova <66773372+Tranquil-Flow@users.noreply.github.com> Date: Mon, 26 Jan 2026 16:04:53 +1000 Subject: [PATCH] fix: implemented fix for skipped nfcScanner tests on ios and android (#1628) * fix: implemented fix for skipped nfcScanner tests on ios and android * chore: yarn prettier --- .../src/integrations/nfc/nfcScanner.test.ts | 28 +++++++++++++++++-- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/app/tests/src/integrations/nfc/nfcScanner.test.ts b/app/tests/src/integrations/nfc/nfcScanner.test.ts index 66dc7ac22..0d9381b6e 100644 --- a/app/tests/src/integrations/nfc/nfcScanner.test.ts +++ b/app/tests/src/integrations/nfc/nfcScanner.test.ts @@ -37,6 +37,23 @@ jest.mock('react-native', () => ({ // Ensure the Node Buffer implementation is available to the module under test global.Buffer = Buffer; +// The static import above captures Platform.OS at load time. To test different platforms, +// we need to clear the module cache and re-import with the current global.mockPlatformOS. +const getFreshParseScanResponse = () => { + jest.resetModules(); + jest.doMock('react-native', () => ({ + Platform: { + get OS() { + return global.mockPlatformOS; + }, + Version: 14, + select: (obj: Record) => + obj[global.mockPlatformOS] || obj.default, + }, + })); + return require('@/integrations/nfc/nfcScanner').parseScanResponse; +}; + describe('parseScanResponse', () => { beforeEach(() => { jest.clearAllMocks(); @@ -44,8 +61,9 @@ describe('parseScanResponse', () => { global.mockPlatformOS = 'ios'; }); - it.skip('parses iOS response', () => { + it('parses iOS response', () => { // Platform.OS is already mocked as 'ios' by default + const parseScanResponse = getFreshParseScanResponse(); const mrz = 'P { `"{"dataGroupHashes":"{\\"DG1\\":{\\"sodHash\\":\\"abcd\\"},\\"DG2\\":{\\"sodHash\\":\\"1234\\"}}","eContentBase64":"ZWM=","signedAttributes":"c2E=","passportMRZ":"P { expect(result.dg2Hash).toEqual([18, 52]); }); - it.skip('parses Android response', () => { + it('parses Android response', () => { // Set Platform.OS to android for this test global.mockPlatformOS = 'android'; + const parseScanResponse = getFreshParseScanResponse(); const mrz = 'P { it('handles malformed iOS response', () => { // Platform.OS is already mocked as 'ios' by default + const parseScanResponse = getFreshParseScanResponse(); const response = '{"invalid": "json"'; expect(() => parseScanResponse(response)).toThrow(); @@ -186,6 +205,7 @@ describe('parseScanResponse', () => { it('handles malformed Android response', () => { // Set Platform.OS to android for this test global.mockPlatformOS = 'android'; + const parseScanResponse = getFreshParseScanResponse(); const response = { mrz: 'valid_mrz', @@ -198,6 +218,7 @@ describe('parseScanResponse', () => { it('handles missing required fields', () => { // Platform.OS is already mocked as 'ios' by default + const parseScanResponse = getFreshParseScanResponse(); const response = JSON.stringify({ // Providing minimal data but missing critical passportMRZ field dataGroupHashes: JSON.stringify({ @@ -217,6 +238,7 @@ describe('parseScanResponse', () => { it('handles invalid hex data in dataGroupHashes', () => { // Platform.OS is already mocked as 'ios' by default + const parseScanResponse = getFreshParseScanResponse(); const response = JSON.stringify({ dataGroupHashes: JSON.stringify({ DG1: { sodHash: 'invalid_hex' },