Skip to content

Commit

Permalink
test(functions): ensure modular API are exported properly (#7935)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Jul 30, 2024
1 parent 89c55f3 commit 4460536
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 9 deletions.
26 changes: 25 additions & 1 deletion packages/functions/__tests__/functions.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { describe, expect, it } from '@jest/globals';

import functions, { firebase } from '../lib';
import functions, {
firebase,
getFunctions,
connectFunctionsEmulator,
httpsCallable,
httpsCallableFromUrl,
} from '../lib';

describe('Cloud Functions', function () {
describe('namespace', function () {
Expand Down Expand Up @@ -46,4 +52,22 @@ describe('Cloud Functions', function () {
);
});
});

describe('modular', function () {
it('`getFunctions` function is properly exposed to end user', function () {
expect(getFunctions).toBeDefined();
});

it('`connectFunctionsEmulator` function is properly exposed to end user', function () {
expect(connectFunctionsEmulator).toBeDefined();
});

it('`httpsCallable` function is properly exposed to end user', function () {
expect(httpsCallable).toBeDefined();
});

it('`httpsCallableFromUrl` function is properly exposed to end user', function () {
expect(httpsCallableFromUrl).toBeDefined();
});
});
});
2 changes: 2 additions & 0 deletions packages/functions/lib/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ export const firebase: ReactNativeFirebase.Module & {

export default defaultExport;

export * from './modular';

/**
* Attach namespace to `firebase.` and `FirebaseApp.`.
*/
Expand Down
9 changes: 2 additions & 7 deletions packages/functions/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ import fallBackModule from './web/RNFBFunctionsModule';
const namespace = 'functions';
const nativeModuleName = 'RNFBFunctionsModule';

export {
getFunctions,
httpsCallable,
httpsCallableFromUrl,
connectFunctionsEmulator,
} from './modular/index';

export const HttpsErrorCode = {
OK: 'ok',
CANCELLED: 'cancelled',
Expand Down Expand Up @@ -207,6 +200,8 @@ export default createModuleNamespace({
ModuleClass: FirebaseFunctionsModule,
});

export * from './modular';

// import functions, { firebase } from '@react-native-firebase/functions';
// functions().logEvent(...);
// firebase.functions().logEvent(...);
Expand Down
2 changes: 1 addition & 1 deletion packages/functions/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export declare function httpsCallable<RequestData = unknown, ResponseData = unkn
* @param {HttpsCallableOptions | undefined} options An instance of {@link HttpsCallableOptions} containing metadata about how calls should be executed.
* @returns {HttpsCallable}
*/
export declare function httpsCallableFromURL<RequestData = unknown, ResponseData = unknown>(
export declare function httpsCallableFromUrl<RequestData = unknown, ResponseData = unknown>(
functionsInstance: Functions,
url: string,
options?: HttpsCallableOptions,
Expand Down
1 change: 1 addition & 0 deletions packages/functions/lib/modular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export function getFunctions(app, regionOrCustomDomain) {
* @param {Functions} functionsInstance A functions instance.
* @param {string} host The emulator host. (ex: localhost)
* @param {number} port The emulator port. (ex: 5001)
* @returns {void}
*/
export function connectFunctionsEmulator(functionsInstance, host, port) {
return firebase
Expand Down

0 comments on commit 4460536

Please sign in to comment.