Skip to content

Commit eb1d1b6

Browse files
MichaelVerdonmikehardy
authored andcommitted
chore(functions): deprecation warnings for v8 API ahead of future major release
1 parent d9cc561 commit eb1d1b6

File tree

4 files changed

+94
-8
lines changed

4 files changed

+94
-8
lines changed

packages/app/lib/common/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,16 @@ const mapOfDeprecationReplacements = {
366366
TaskState: 'TaskState',
367367
},
368368
},
369+
functions: {
370+
default: {
371+
useEmulator: 'connectFirestoreEmulator()',
372+
httpsCallable: 'httpsCallable()',
373+
httpsCallableFromUrl: 'httpsCallableFromUrl()',
374+
},
375+
statics: {
376+
HttpsErrorCode: 'HttpsErrorCode',
377+
},
378+
},
369379
};
370380

371381
const modularDeprecationMessage =

packages/functions/__tests__/functions.test.ts

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { afterAll, beforeAll, describe, expect, it } from '@jest/globals';
1+
import { afterAll, beforeAll, beforeEach, describe, expect, it, jest } from '@jest/globals';
22

33
import functions, {
44
firebase,
@@ -9,6 +9,14 @@ import functions, {
99
HttpsErrorCode,
1010
} from '../lib';
1111

12+
import {
13+
createCheckV9Deprecation,
14+
CheckV9DeprecationFunction,
15+
} from '../../app/lib/common/unitTestUtils';
16+
17+
// @ts-ignore test
18+
import FirebaseModule from '../../app/lib/internal/FirebaseModule';
19+
1220
describe('Cloud Functions', function () {
1321
describe('namespace', function () {
1422
beforeAll(async function () {
@@ -85,4 +93,61 @@ describe('Cloud Functions', function () {
8593
expect(HttpsErrorCode).toBeDefined();
8694
});
8795
});
96+
97+
describe('test `console.warn` is called for RNFB v8 API & not called for v9 API', function () {
98+
let functionsRefV9Deprecation: CheckV9DeprecationFunction;
99+
100+
beforeEach(function () {
101+
functionsRefV9Deprecation = createCheckV9Deprecation(['functions']);
102+
103+
// @ts-ignore test
104+
jest.spyOn(FirebaseModule.prototype, 'native', 'get').mockImplementation(() => {
105+
return new Proxy(
106+
{},
107+
{
108+
get: () =>
109+
jest.fn().mockResolvedValue({
110+
source: 'cache',
111+
changes: [],
112+
documents: [],
113+
metadata: {},
114+
path: 'foo',
115+
} as never),
116+
},
117+
);
118+
});
119+
});
120+
121+
describe('Cloud Functions', function () {
122+
it('useFunctionsEmulator()', function () {
123+
const app = firebase.app();
124+
const functions = app.functions();
125+
functionsRefV9Deprecation(
126+
() => connectFunctionsEmulator(functions, 'localhost', 8080),
127+
() => functions.useEmulator('localhost', 8080),
128+
'useEmulator',
129+
);
130+
});
131+
132+
it('httpsCallable()', function () {
133+
const app = firebase.app();
134+
const functions = app.functions();
135+
functionsRefV9Deprecation(
136+
() => httpsCallable(functions, 'example'),
137+
() => functions.httpsCallable('example'),
138+
'httpsCallable',
139+
);
140+
});
141+
142+
it('httpsCallableFromUrl()', function () {
143+
const app = firebase.app();
144+
const functions = app.functions();
145+
functionsRefV9Deprecation(
146+
() => httpsCallableFromUrl(functions, 'https://example.com/example'),
147+
() => functions.httpsCallableFromUrl('https://example.com/example'),
148+
'httpsCallableFromUrl',
149+
);
150+
});
151+
});
152+
});
88153
});

packages/functions/e2e/functions.e2e.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ describe('functions() modular', function () {
448448

449449
it('accepts passing in a region string as first arg to an app', async function () {
450450
const { getApp } = modular;
451-
const { getFunctions } = functionsModular;
451+
const { getFunctions, httpsCallable } = functionsModular;
452452
const region = 'europe-west1';
453453

454454
const functionsForRegion = getFunctions(getApp(), region);
@@ -461,15 +461,15 @@ describe('functions() modular', function () {
461461

462462
getApp().functions(region)._customUrlOrRegion.should.equal(region);
463463

464-
const functionRunner = functionsForRegion.httpsCallable('testFunctionCustomRegion');
464+
const functionRunner = httpsCallable(functionsForRegion, 'testFunctionCustomRegion');
465465

466466
const response = await functionRunner();
467467
response.data.should.equal(region);
468468
});
469469

470470
it('accepts passing in a custom url string as first arg to an app', async function () {
471471
const { getApp } = modular;
472-
const { getFunctions } = functionsModular;
472+
const { getFunctions, httpsCallable } = functionsModular;
473473
const customUrl = 'https://us-central1-react-native-firebase-testing.cloudfunctions.net';
474474

475475
const functionsForCustomUrl = getFunctions(getApp(), customUrl);
@@ -482,7 +482,7 @@ describe('functions() modular', function () {
482482

483483
functionsForCustomUrl._customUrlOrRegion.should.equal(customUrl);
484484

485-
const functionRunner = functionsForCustomUrl.httpsCallable('testFunctionDefaultRegionV2');
485+
const functionRunner = httpsCallable(functionsForCustomUrl, 'testFunctionDefaultRegionV2');
486486

487487
const response = await functionRunner();
488488
response.data.should.equal('null');

packages/functions/lib/modular/index.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
*/
2323

2424
import { getApp } from '@react-native-firebase/app';
25+
import { MODULAR_DEPRECATION_ARG } from '@react-native-firebase/app/lib/common';
2526

2627
/**
2728
* Returns a Functions instance for the given app.
@@ -46,7 +47,7 @@ export function getFunctions(app, regionOrCustomDomain) {
4647
* @returns {void}
4748
*/
4849
export function connectFunctionsEmulator(functionsInstance, host, port) {
49-
return functionsInstance.useEmulator(host, port);
50+
return functionsInstance.useEmulator.call(functionsInstance, host, port, MODULAR_DEPRECATION_ARG);
5051
}
5152

5253
/**
@@ -57,7 +58,12 @@ export function connectFunctionsEmulator(functionsInstance, host, port) {
5758
* @returns {HttpsCallable}
5859
*/
5960
export function httpsCallable(functionsInstance, name, options) {
60-
return functionsInstance.httpsCallable(name, options);
61+
return functionsInstance.httpsCallable.call(
62+
functionsInstance,
63+
name,
64+
options,
65+
MODULAR_DEPRECATION_ARG,
66+
);
6167
}
6268

6369
/**
@@ -68,7 +74,12 @@ export function httpsCallable(functionsInstance, name, options) {
6874
* @returns {HttpsCallable}
6975
*/
7076
export function httpsCallableFromUrl(functionsInstance, url, options) {
71-
return functionsInstance.httpsCallableFromUrl(url, options);
77+
return functionsInstance.httpsCallableFromUrl.call(
78+
functionsInstance,
79+
url,
80+
options,
81+
MODULAR_DEPRECATION_ARG,
82+
);
7283
}
7384

7485
export { HttpsErrorCode } from '../index';

0 commit comments

Comments
 (0)