|
| 1 | +import { afterAll, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals'; |
| 2 | + |
| 3 | +jest.mock('@react-native-firebase/app/dist/module/common', () => { |
| 4 | + const actualCommon = jest.requireActual( |
| 5 | + '@react-native-firebase/app/dist/module/common', |
| 6 | + ) as Record<string, unknown>; |
| 7 | + return { |
| 8 | + ...actualCommon, |
| 9 | + isOther: false, |
| 10 | + isAndroid: true, |
| 11 | + }; |
| 12 | +}); |
| 13 | + |
| 14 | +import { firebase } from '../lib'; |
| 15 | + |
| 16 | +function timeoutFromNativeCall(nativeMock: jest.Mock): number { |
| 17 | + const call = nativeMock.mock.calls[0] as unknown[] | undefined; |
| 18 | + expect(call).toBeDefined(); |
| 19 | + const options = call?.[4] as { timeout?: number } | undefined; |
| 20 | + expect(options?.timeout).toBeDefined(); |
| 21 | + return options?.timeout as number; |
| 22 | +} |
| 23 | + |
| 24 | +describe('httpsCallable timeout units on native platforms', function () { |
| 25 | + let httpsCallableNative: jest.Mock; |
| 26 | + |
| 27 | + beforeAll(function () { |
| 28 | + // @ts-ignore test-only global |
| 29 | + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = true; |
| 30 | + }); |
| 31 | + |
| 32 | + afterAll(function () { |
| 33 | + // @ts-ignore test-only global |
| 34 | + globalThis.RNFB_SILENCE_MODULAR_DEPRECATION_WARNINGS = false; |
| 35 | + }); |
| 36 | + |
| 37 | + beforeEach(function () { |
| 38 | + httpsCallableNative = jest |
| 39 | + .fn<(...args: unknown[]) => Promise<{ data: null }>>() |
| 40 | + .mockResolvedValue({ data: null }); |
| 41 | + |
| 42 | + const functions = firebase.app().functions(); |
| 43 | + // @ts-ignore test-only internal cache |
| 44 | + functions._nativeModule = { |
| 45 | + httpsCallable: ( |
| 46 | + _host: unknown, |
| 47 | + _port: unknown, |
| 48 | + _name: unknown, |
| 49 | + _wrapper: unknown, |
| 50 | + options: { timeout?: number }, |
| 51 | + ) => httpsCallableNative(_host, _port, _name, _wrapper, options), |
| 52 | + }; |
| 53 | + }); |
| 54 | + |
| 55 | + it('converts milliseconds to seconds for httpsCallable (Android/iOS)', async function () { |
| 56 | + const runner = firebase.app().functions().httpsCallable('example', { timeout: 30000 }); |
| 57 | + await runner(); |
| 58 | + |
| 59 | + expect(httpsCallableNative).toHaveBeenCalledTimes(1); |
| 60 | + expect(timeoutFromNativeCall(httpsCallableNative)).toBe(30); |
| 61 | + }); |
| 62 | +}); |
0 commit comments