Skip to content

Commit

Permalink
test(installations): ensure modular API are exported properly (#7937)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Jul 29, 2024
1 parent 55de95f commit 246b86c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
40 changes: 28 additions & 12 deletions packages/installations/__tests__/installations.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { describe, expect, it } from '@jest/globals';

import { firebase, getInstallations, onIdChange } from '../lib';
import {
firebase,
getInstallations,
deleteInstallations,
getId,
getToken,
onIdChange,
} from '../lib';

describe('installations()', function () {
describe('namespace', function () {
Expand All @@ -22,23 +29,32 @@ describe('installations()', function () {
});

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

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

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

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

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

describe('getInstallations', function () {
it('returns an instance of Installations', async function () {
const installations = getInstallations();
expect(installations).toBeDefined();
// expect(installations.app).toBeDefined();
});

// it('supports multiple apps', async function () {
// const app = firebase.app();
// const secondaryApp = firebase.app('secondaryFromNative');

// const installations = getInstallations();
// const installationsForApp = getInstallations(secondaryApp);

// expect(installations.app).toEqual(app);
// expect(installationsForApp.app).toEqual(secondaryApp);
// });
});

describe('onIdChange', function () {
Expand Down
13 changes: 6 additions & 7 deletions packages/installations/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,29 @@
import { ReactNativeFirebase } from '@react-native-firebase/app';
import { FirebaseInstallationsTypes } from '../index';

import FirebaseInstallations = FirebaseInstallationsTypes.Module;
/**
* Returns an instance of Installations associated with the given FirebaseApp instance.
*/
export declare function getInstallations(
app?: ReactNativeFirebase.FirebaseApp,
): FirebaseInstallationsTypes.Module;
): FirebaseInstallations;

/**
* Deletes the Firebase Installation and all associated data.
*/
export declare function deleteInstallations(
installations?: FirebaseInstallationsTypes.Module,
): Promise<void>;
export declare function deleteInstallations(installations?: FirebaseInstallations): Promise<void>;

/**
* Creates a Firebase Installation if there isn't one for the app and returns the Installation ID.
*/
export declare function getId(installations: FirebaseInstallationsTypes.Module): Promise<string>;
export declare function getId(installations: FirebaseInstallations): Promise<string>;

/**
* Returns a Firebase Installations auth token, identifying the current Firebase Installation.
*/
export declare function getToken(
installations: FirebaseInstallationsTypes.Module,
installations: FirebaseInstallations,
forceRefresh?: boolean,
): Promise<string>;

Expand All @@ -37,6 +36,6 @@ declare type IdChangeUnsubscribeFn = () => void;
* Sets a new callback that will get called when Installation ID changes. Returns an unsubscribe function that will remove the callback when called.
*/
export declare function onIdChange(
installations: FirebaseInstallationsTypes.Module,
installations: FirebaseInstallations,
callback: IdChangeCallbackFn,
): IdChangeUnsubscribeFn;
12 changes: 6 additions & 6 deletions packages/installations/lib/modular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
import { firebase } from '..';

/**
* @param {import("@react-native-firebase/app").ReactNativeFirebase.FirebaseApp} app
* @returns {import("..").FirebaseInstallationsTypes.Module}
* @typedef {import('..').FirebaseInstallationsTypes.Module} FirebaseInstallation
*/

export function getInstallations(app) {
if (app) {
return firebase.app(app.name).installations();
Expand All @@ -29,23 +29,23 @@ export function getInstallations(app) {
}

/**
* @param {import("..").FirebaseInstallationsTypes.Module} installations
* @param {FirebaseInstallation} installations
* @returns {Promise<void>}
*/
export function deleteInstallations(installations) {
return firebase.app(installations.app.name).installations().delete();
}

/**
* @param {import("..").FirebaseInstallationsTypes.Module} installations
* @param {FirebaseInstallation} installations
* @returns {Promise<string>}
*/
export function getId(installations) {
return firebase.app(installations.app.name).installations().getId();
}

/**
* @param {import("..").FirebaseInstallationsTypes.Module} installations
* @param {FirebaseInstallation} installations
* @param {boolean | undefined} forceRefresh
* @returns {Promise<string>}
*/
Expand All @@ -54,7 +54,7 @@ export function getToken(installations, forceRefresh) {
}

/**
* @param {import("..").FirebaseInstallationsTypes.Module} installations
* @param {FirebaseInstallation} installations
* @param {(string) => void} callback
* @returns {() => void}
*/
Expand Down

0 comments on commit 246b86c

Please sign in to comment.