import { Platform } from 'react-native'; import { beforeEach, describe, expect, test, vi } from 'vitest'; import { HOST_BRIDGE_EXPO_MOBILE_BASE_CAPABILITIES, HOST_BRIDGE_EXPO_MOBILE_IOS_CAPABILITIES, HOST_BRIDGE_PROTOCOL, HOST_BRIDGE_VERSION, type HostBridgeRequest, } from '../../../../packages/shared/src/contracts/hostBridge'; import { MOBILE_SHELL_HOST_VERSION } from '../shell/runtime'; import { getMobileHostBridgeRuntime, getMobileHostBridgeRuntimeResponse, getMobileRuntimePlatform, } from './runtime'; vi.mock('react-native', () => ({ Platform: { OS: 'ios', }, })); function request(): HostBridgeRequest { return { bridge: HOST_BRIDGE_PROTOCOL, version: HOST_BRIDGE_VERSION, id: 'runtime-request', method: 'host.getRuntime', }; } function setPlatformOS(os: 'ios' | 'android') { (Platform as { OS: 'ios' | 'android' }).OS = os; } beforeEach(() => { setPlatformOS('ios'); }); describe('mobile HostBridge runtime helper', () => { test('reports iOS runtime with host version, bridge version and iOS capabilities', () => { expect(getMobileRuntimePlatform()).toBe('ios'); const runtime = getMobileHostBridgeRuntime(); expect(runtime).toEqual( expect.objectContaining({ shell: 'expo_mobile', platform: 'ios', hostVersion: MOBILE_SHELL_HOST_VERSION, bridgeVersion: HOST_BRIDGE_VERSION, }), ); expect(runtime.capabilities).toBe(HOST_BRIDGE_EXPO_MOBILE_IOS_CAPABILITIES); }); test('reports Android runtime without iOS-only app badge capability', () => { setPlatformOS('android'); const runtime = getMobileHostBridgeRuntime(); expect(getMobileRuntimePlatform()).toBe('android'); expect(runtime).toEqual( expect.objectContaining({ shell: 'expo_mobile', platform: 'android', hostVersion: MOBILE_SHELL_HOST_VERSION, bridgeVersion: HOST_BRIDGE_VERSION, }), ); expect(runtime.capabilities).toBe( HOST_BRIDGE_EXPO_MOBILE_BASE_CAPABILITIES, ); expect(runtime.capabilities).not.toContain('app.setBadgeCount'); }); test('wraps runtime metadata in the HostBridge response shape', () => { const response = getMobileHostBridgeRuntimeResponse(request()); expect(response).toEqual({ bridge: HOST_BRIDGE_PROTOCOL, version: HOST_BRIDGE_VERSION, id: 'runtime-request', ok: true, result: getMobileHostBridgeRuntime(), }); }); });