Skip to content

Commit

Permalink
feat(app-distribution): Firebase V9 modular API (#7307)
Browse files Browse the repository at this point in the history
* feat(app-distribution): Firebase V9 modular API

* add modular export in index.js

* fix(types): AppDistribution -> FirebaseAppDistribution, typedefs for jsdocs

---------

Co-authored-by: Mike Hardy <[email protected]>
  • Loading branch information
exaby73 and mikehardy authored Sep 5, 2023
1 parent 0149480 commit 309fec4
Show file tree
Hide file tree
Showing 6 changed files with 196 additions and 37 deletions.
134 changes: 97 additions & 37 deletions packages/app-distribution/e2e/app-distribution.e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,49 +16,109 @@
*/

describe('appDistribution()', function () {
describe('native module is loaded', function () {
it('checks native module load status', function () {
firebase.appDistribution().native;
describe('v8 compatibility', function () {
describe('native module is loaded', function () {
it('checks native module load status', function () {
firebase.appDistribution().native;
});
});
});

describe('isTesterSignedIn()', function () {
it('checks if a tester is signed in', async function () {
if (device.getPlatform() === 'ios') {
await firebase.appDistribution().isTesterSignedIn();
} else {
this.skip();
}
describe('isTesterSignedIn()', function () {
it('checks if a tester is signed in', async function () {
if (device.getPlatform() === 'ios') {
await firebase.appDistribution().isTesterSignedIn();
} else {
this.skip();
}
});
});
});
// Requires a valid google account logged in on device and associated with iOS testing app
xdescribe('signInTester()', function () {
it('signs a tester in', async function () {
if (device.getPlatform() === 'ios') {
await firebase.appDistribution().signInTester();
} else {
this.skip();
}
// Requires a valid google account logged in on device and associated with iOS testing app
xdescribe('signInTester()', function () {
it('signs a tester in', async function () {
if (device.getPlatform() === 'ios') {
await firebase.appDistribution().signInTester();
} else {
this.skip();
}
});
});
});
describe('signOutTester()', function () {
it('signs out a tester', async function () {
if (device.getPlatform() === 'ios') {
await firebase.appDistribution().signOutTester();
} else {
this.skip();
}
describe('signOutTester()', function () {
it('signs out a tester', async function () {
if (device.getPlatform() === 'ios') {
await firebase.appDistribution().signOutTester();
} else {
this.skip();
}
});
});
// Requires a valid google account logged in on device and associated with iOS testing app
// plus a new IPA file uploaded
xdescribe('checkForUpdate()', function () {
it('checks for an update', async function () {
if (device.getPlatform() === 'ios') {
await firebase.appDistribution().checkForUpdate();
} else {
this.skip();
}
});
});
});
// Requires a valid google account logged in on device and associated with iOS testing app
// plus a new IPA file uploaded
xdescribe('checkForUpdate()', function () {
it('checks for an update', async function () {
if (device.getPlatform() === 'ios') {
await firebase.appDistribution().checkForUpdate();
} else {
this.skip();
}

describe('modular', function () {
describe('native module is loaded', function () {
it('checks native module load status', function () {
const { getAppDistribution } = appDistributionModular;
const appDistribution = getAppDistribution();
appDistribution.native;
});
});

describe('isTesterSignedIn()', function () {
it('checks if a tester is signed in', async function () {
const { getAppDistribution, isTesterSignedIn } = appDistributionModular;
const appDistribution = getAppDistribution();
if (device.getPlatform() === 'ios') {
await isTesterSignedIn(appDistribution);
} else {
this.skip();
}
});
});
// Requires a valid google account logged in on device and associated with iOS testing app
xdescribe('signInTester()', function () {
it('signs a tester in', async function () {
const { getAppDistribution, signInTester } = appDistributionModular;
const appDistribution = getAppDistribution();
if (device.getPlatform() === 'ios') {
await signInTester(appDistribution);
} else {
this.skip();
}
});
});
describe('signOutTester()', function () {
it('signs out a tester', async function () {
const { getAppDistribution, signOutTester } = appDistributionModular;
const appDistribution = getAppDistribution();
if (device.getPlatform() === 'ios') {
await signOutTester(appDistribution);
} else {
this.skip();
}
});
});
// Requires a valid google account logged in on device and associated with iOS testing app
// plus a new IPA file uploaded
xdescribe('checkForUpdate()', function () {
it('checks for an update', async function () {
const { getAppDistribution, checkForUpdate } = appDistributionModular;
const appDistribution = getAppDistribution();
if (device.getPlatform() === 'ios') {
await checkForUpdate(appDistribution);
} else {
this.skip();
}
});
});
});
});
2 changes: 2 additions & 0 deletions packages/app-distribution/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ class FirebaseAppDistributionModule extends FirebaseModule {
}
}

export * from './modular';

// import { SDK_VERSION } from '@react-native-firebase/app-distribution';
export const SDK_VERSION = version;

Expand Down
39 changes: 39 additions & 0 deletions packages/app-distribution/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { ReactNativeFirebase } from '@react-native-firebase/app';
import { FirebaseAppDistributionTypes } from '..';

export type FirebaseAppDistribution = FirebaseAppDistributionTypes.Module;

/**
* Get an App Distribution instance for the specified app or current app.
*/
export declare function getAppDistribution(
app?: ReactNativeFirebase.FirebaseApp,
): FirebaseAppDistribution;

/**
* Returns true if the App Distribution tester is signed in.
* If not an iOS device, it always rejects, as neither false nor true seem like a sensible default.
*/
export declare function isTesterSignedIn(
appDistribution: FirebaseAppDistribution,
): Promise<boolean>;

/**
* Sign-in the App Distribution tester
* If not an iOS device, it always rejects, as no defaults seem sensible.
*/
export declare function signInTester(appDistribution: FirebaseAppDistribution): Promise<void>;

/**
* Check to see whether a new distribution is available
* If not an iOS device, it always rejects, as no default response seems sensible.
*/
export declare function checkForUpdate(
appDistribution: FirebaseAppDistribution,
): Promise<FirebaseAppDistributionTypes.AppDistributionRelease>;

/**
* Sign out App Distribution tester
* If not an iOS device, it always rejects, as no default response seems sensible.
*/
export declare function signOutTester(appDistribution: FirebaseAppDistribution): Promise<void>;
50 changes: 50 additions & 0 deletions packages/app-distribution/lib/modular/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { firebase } from '..';

/**
* @typedef {import("..").FirebaseApp} FirebaseApp
* @typedef {import("..").FirebaseAppDistributionTypes.AppDistributionRelease} AppDistributionRelease
* @typedef {import("..").FirebaseAppDistributionTypes.Module} FirebaseAppDistribution
*/

/**
* @param {FirebaseApp | undefined} app
* @returns {FirebaseAppDistribution}
*/
export function getAppDistribution(app) {
if (app) {
return firebase.appDistribution(app);
}
return firebase.appDistribution();
}

/**
* @param {FirebaseAppDistribution} appDistribution
* @returns {Promise<boolean>}
*/
export function isTesterSignedIn(appDistribution) {
return appDistribution.isTesterSignedIn();
}

/**
* @param {FirebaseAppDistribution} appDistribution
* @returns {Promise<void>}
*/
export function signInTester(appDistribution) {
return appDistribution.signInTester();
}

/**
* @param {FirebaseAppDistribution} appDistribution
* @returns {AppDistributionRelease>}
*/
export function checkForUpdate(appDistribution) {
return appDistribution.checkForUpdate();
}

/**
* @param {FirebaseAppDistribution} appDistribution
* @returns {Promise<void>}
*/
export function signOutTester(appDistribution) {
return appDistribution.signOutTester();
}
2 changes: 2 additions & 0 deletions tests/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import firebase, * as modular from '@react-native-firebase/app';
import '@react-native-firebase/app-check';
import * as appCheckModular from '@react-native-firebase/app-check';
import '@react-native-firebase/app-distribution';
import * as appDistributionModular from '@react-native-firebase/app-distribution';
import NativeEventEmitter from '@react-native-firebase/app/lib/internal/RNFBNativeEventEmitter';
import '@react-native-firebase/app/lib/utils';
import '@react-native-firebase/auth';
Expand Down Expand Up @@ -54,6 +55,7 @@ jet.exposeContextProperty('module', firebase);
jet.exposeContextProperty('modular', modular);
jet.exposeContextProperty('functionsModular', functionsModular);
jet.exposeContextProperty('analyticsModular', analyticsModular);
jet.exposeContextProperty('appDistributionModular', appDistributionModular);
jet.exposeContextProperty('remoteConfigModular', remoteConfigModular);
jet.exposeContextProperty('perfModular', perfModular);
jet.exposeContextProperty('appCheckModular', appCheckModular);
Expand Down
6 changes: 6 additions & 0 deletions tests/e2e/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ Object.defineProperty(global, 'appCheckModular', {
},
});

Object.defineProperty(global, 'appDistributionModular', {
get() {
return jet.appDistributionModular;
},
});

Object.defineProperty(global, 'storageModular', {
get() {
return jet.storageModular;
Expand Down

1 comment on commit 309fec4

@vercel
Copy link

@vercel vercel bot commented on 309fec4 Sep 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.