diff --git a/packages/app/lib/common/index.js b/packages/app/lib/common/index.js index e979845e17..e46007d785 100644 --- a/packages/app/lib/common/index.js +++ b/packages/app/lib/common/index.js @@ -366,6 +366,16 @@ const mapOfDeprecationReplacements = { TaskState: 'TaskState', }, }, + functions: { + default: { + useEmulator: 'connectFirestoreEmulator()', + httpsCallable: 'httpsCallable()', + httpsCallableFromUrl: 'httpsCallableFromUrl()', + }, + statics: { + HttpsErrorCode: 'HttpsErrorCode', + }, + }, }; const modularDeprecationMessage = diff --git a/packages/functions/__tests__/functions.test.ts b/packages/functions/__tests__/functions.test.ts index 2797e0ab92..0e1af414a8 100644 --- a/packages/functions/__tests__/functions.test.ts +++ b/packages/functions/__tests__/functions.test.ts @@ -1,4 +1,4 @@ -import { afterAll, beforeAll, describe, expect, it } from '@jest/globals'; +import { afterAll, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals'; import functions, { firebase, @@ -9,6 +9,14 @@ import functions, { HttpsErrorCode, } from '../lib'; +import { + createCheckV9Deprecation, + CheckV9DeprecationFunction, +} from '../../app/lib/common/unitTestUtils'; + +// @ts-ignore test +import FirebaseModule from '../../app/lib/internal/FirebaseModule'; + describe('Cloud Functions', function () { describe('namespace', function () { beforeAll(async function () { @@ -85,4 +93,61 @@ describe('Cloud Functions', function () { expect(HttpsErrorCode).toBeDefined(); }); }); + + describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () { + let functionsRefV9Deprecation: CheckV9DeprecationFunction; + + beforeEach(function () { + functionsRefV9Deprecation = createCheckV9Deprecation(['functions']); + + // @ts-ignore test + jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => { + return new Proxy( + {}, + { + get: () => + jest.fn().mockResolvedValue({ + source: 'cache', + changes: [], + documents: [], + metadata: {}, + path: 'foo', + } as never), + }, + ); + }); + }); + + describe('Cloud Functions', function () { + it('useFunctionsEmulator()', function () { + const app = firebase.app(); + const functions = app.functions(); + functionsRefV9Deprecation( + () => connectFunctionsEmulator(functions, 'localhost', 8080), + () => functions.useEmulator('localhost', 8080), + 'useEmulator', + ); + }); + + it('httpsCallable()', function () { + const app = firebase.app(); + const functions = app.functions(); + functionsRefV9Deprecation( + () => httpsCallable(functions, 'example'), + () => functions.httpsCallable('example'), + 'httpsCallable', + ); + }); + + it('httpsCallableFromUrl()', function () { + const app = firebase.app(); + const functions = app.functions(); + functionsRefV9Deprecation( + () => httpsCallableFromUrl(functions, 'https://example.com/example'), + () => functions.httpsCallableFromUrl('https://example.com/example'), + 'httpsCallableFromUrl', + ); + }); + }); + }); }); diff --git a/packages/functions/e2e/functions.e2e.js b/packages/functions/e2e/functions.e2e.js index ccc15faf97..f2f81a1d1e 100644 --- a/packages/functions/e2e/functions.e2e.js +++ b/packages/functions/e2e/functions.e2e.js @@ -448,7 +448,7 @@ describe('functions() modular', function () { it('accepts passing in a region string as first arg to an app', async function () { const { getApp } = modular; - const { getFunctions } = functionsModular; + const { getFunctions, httpsCallable } = functionsModular; const region = 'europe-west1'; const functionsForRegion = getFunctions(getApp(), region); @@ -461,7 +461,7 @@ describe('functions() modular', function () { getApp().functions(region)._customUrlOrRegion.should.equal(region); - const functionRunner = functionsForRegion.httpsCallable('testFunctionCustomRegion'); + const functionRunner = httpsCallable(functionsForRegion, 'testFunctionCustomRegion'); const response = await functionRunner(); response.data.should.equal(region); @@ -469,7 +469,7 @@ describe('functions() modular', function () { it('accepts passing in a custom url string as first arg to an app', async function () { const { getApp } = modular; - const { getFunctions } = functionsModular; + const { getFunctions, httpsCallable } = functionsModular; const customUrl = 'https://us-central1-react-native-firebase-testing.cloudfunctions.net'; const functionsForCustomUrl = getFunctions(getApp(), customUrl); @@ -482,7 +482,7 @@ describe('functions() modular', function () { functionsForCustomUrl._customUrlOrRegion.should.equal(customUrl); - const functionRunner = functionsForCustomUrl.httpsCallable('testFunctionDefaultRegionV2'); + const functionRunner = httpsCallable(functionsForCustomUrl, 'testFunctionDefaultRegionV2'); const response = await functionRunner(); response.data.should.equal('null'); diff --git a/packages/functions/lib/modular/index.js b/packages/functions/lib/modular/index.js index 366687514a..96a076a28b 100644 --- a/packages/functions/lib/modular/index.js +++ b/packages/functions/lib/modular/index.js @@ -22,6 +22,7 @@ */ import { getApp } from '@react-native-firebase/app'; +import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common'; /** * Returns a Functions instance for the given app. @@ -46,7 +47,7 @@ export function getFunctions(app, regionOrCustomDomain) { * @returns {void} */ export function connectFunctionsEmulator(functionsInstance, host, port) { - return functionsInstance.useEmulator(host, port); + return functionsInstance.useEmulator.call(functionsInstance, host, port, MODULAR_DEPRECATION_ARG); } /** @@ -57,7 +58,12 @@ export function connectFunctionsEmulator(functionsInstance, host, port) { * @returns {HttpsCallable} */ export function httpsCallable(functionsInstance, name, options) { - return functionsInstance.httpsCallable(name, options); + return functionsInstance.httpsCallable.call( + functionsInstance, + name, + options, + MODULAR_DEPRECATION_ARG, + ); } /** @@ -68,7 +74,12 @@ export function httpsCallable(functionsInstance, name, options) { * @returns {HttpsCallable} */ export function httpsCallableFromUrl(functionsInstance, url, options) { - return functionsInstance.httpsCallableFromUrl(url, options); + return functionsInstance.httpsCallableFromUrl.call( + functionsInstance, + url, + options, + MODULAR_DEPRECATION_ARG, + ); } export { HttpsErrorCode } from '../index';