Skip to content

chore(functions): deprecation warnings for v8 API ahead of future major release #8564

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 12 commits into
base: main
Choose a base branch
from
10 changes: 10 additions & 0 deletions packages/app/lib/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,16 @@ const mapOfDeprecationReplacements = {
nanoseconds: NO_REPLACEMENT,
},
},
functions: {
default: {
useEmulator: 'connectFirestoreEmulator()',
httpsCallable: 'httpsCallable()',
httpsCallableFromUrl: 'httpsCallableFromUrl()',
},
statics: {
HttpsErrorCode: 'HttpsErrorCode',
},
},
};

const modularDeprecationMessage =
Expand Down
67 changes: 66 additions & 1 deletion packages/functions/__tests__/functions.test.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 () {
Expand Down Expand Up @@ -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',
);
});
});
});
});
8 changes: 4 additions & 4 deletions packages/functions/e2e/functions.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -461,15 +461,15 @@ 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);
});

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);
Expand All @@ -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');
Expand Down
17 changes: 14 additions & 3 deletions packages/functions/lib/modular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
}

/**
Expand All @@ -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,
);
}

/**
Expand All @@ -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';
Loading