Skip to content

Commit

Permalink
test(dynamic-links): ensure modular API are exported properly (#7934)
Browse files Browse the repository at this point in the history
  • Loading branch information
russellwheatley authored Jul 29, 2024
1 parent 7022204 commit 0157296
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 22 deletions.
48 changes: 48 additions & 0 deletions packages/dynamic-links/__tests__/dynamic-links.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { describe, expect, it } from '@jest/globals';

import {
ShortLinkType,
getDynamicLinks,
buildLink,
buildShortLink,
getInitialLink,
onLink,
performDiagnostics,
resolveLink,
} from '../lib';

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

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

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

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

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

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

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

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

export * from './modular';

export default defaultExport;

/**
Expand Down
12 changes: 7 additions & 5 deletions packages/dynamic-links/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ import { isIOS } from '@react-native-firebase/app/lib/common';
import builder from './builder';
import version from './version';

export const ShortLinkType = {
SHORT: 'SHORT',
UNGUESSABLE: 'UNGUESSABLE',
DEFAULT: 'DEFAULT',
};

const statics = {
ShortLinkType: {
SHORT: 'SHORT',
UNGUESSABLE: 'UNGUESSABLE',
DEFAULT: 'DEFAULT',
},
ShortLinkType,
};

const namespace = 'dynamicLinks';
Expand Down
4 changes: 2 additions & 2 deletions packages/dynamic-links/lib/modular/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ReactNativeFirebase } from '@react-native-firebase/app';
import { FirebaseDynamicLinksTypes } from '..';

type DynamicLinks = FirebaseDynamicLinksTypes.Module;
type FirebaseDynamicLinks = FirebaseDynamicLinksTypes.Module;

export declare const ShortLinkType = FirebaseDynamicLinksTypes.ShortLinkType;

Expand Down Expand Up @@ -141,6 +141,6 @@ export declare function performDiagnostics(dynamicLinks: FirebaseDynamicLinks):
* Can throw error with code 'resolve-link-error' if there is a processing error
*/
export declare function resolveLink(
dynmaicLinks: FirebaseDynamicLinks,
dynamicLinks: FirebaseDynamicLinks,
link: string,
): Promise<FirebaseDynamicLinksTypes.DynamicLink>;
28 changes: 13 additions & 15 deletions packages/dynamic-links/lib/modular/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@ import { firebase } from '..';

/**
* @typedef {import("..").FirebaseApp} FirebaseApp
* @typedef {import("..").FirebaseDynamicLinksTypes} FirebaseDynamicLinksTypes
* @typedef {import("..").FirebaseDynamicLinksTypes.ShortLinkType} ShortLinkType
* @typedef {import("..").FirebaseDynamicLinksTypes.DynamicLink} DynamicLink
* @typedef {import("..").FirebaseDynamicLinksTypes.DynamicLinkParameters} DynamicLinkParameters
* @typedef {import("..").FirebaseDynamicLinksTypes.Module} FirebaseDynamicLinks
*/

// FIXME these are duplicated from the non-modular types and should be by reference
export const ShortLinkType = {
SHORT: 'SHORT',
UNGUESSABLE: 'UNGUESSABLE',
DEFAULT: 'DEFAULT',
};
export { ShortLinkType } from '..';

/**
* @returns {FirebaseDynamicLinks}
Expand All @@ -40,7 +38,7 @@ export function getDynamicLinks() {
/**
*
* @param {FirebaseDynamicLinks} dynamicLinks
* @param {FirebaseDynamicLinksTypes.DynamicLinkParameters} dynamicLinkParams
* @param {DynamicLinkParameters} dynamicLinkParams
* @returns {Promise<string>}
*/
export function buildLink(dynamicLinks, dynamicLinkParams) {
Expand All @@ -50,8 +48,8 @@ export function buildLink(dynamicLinks, dynamicLinkParams) {
/**
*
* @param {FirebaseDynamicLinks} dynamicLinks
* @param {FirebaseDynamicLinksTypes.DynamicLinkParameters} dynamicLinkParams
* @param {FirebaseDynamicLinksTypes.ShortLinkType | undefined} shortLinkType
* @param {DynamicLinkParameters} dynamicLinkParams
* @param {ShortLinkType | undefined} shortLinkType
* @returns {Promise<string>}
*/
export function buildShortLink(dynamicLinks, dynamicLinkParams, shortLinkType) {
Expand All @@ -60,15 +58,15 @@ export function buildShortLink(dynamicLinks, dynamicLinkParams, shortLinkType) {

/**
* @param {FirebaseDynamicLinks} dynamicLinks
* @returns {Promise<FirebaseDynamicLinksTypes.DynamicLink | null>}
* @returns {Promise<DynamicLink | null>}
*/
export function getInitialLink(dynamicLinks) {
return dynamicLinks.getInitialLink();
}

/**
* @param {FirebaseDynamicLinks} dynamicLinks
* @param {(link: FirebaseDynamicLinksTypes.DynamicLink) => void} listener
* @param {(link: DynamicLink) => void} listener
* @returns {() => void}
*/
export function onLink(dynamicLinks, listener) {
Expand All @@ -86,10 +84,10 @@ export function performDiagnostics(dynamicLinks) {

/**
*
* @param {FirebaseDynamicLinks} dynmaicLinks
* @param {FirebaseDynamicLinks} dynamicLinks
* @param {string} link
* @returns {Promise<FirebaseDynamicLinksTypes.DynamicLink>}
* @returns {Promise<DynamicLink>}
*/
export function resolveLink(dynmaicLinks, link) {
return dynmaicLinks.resolveLink(link);
export function resolveLink(dynamicLinks, link) {
return dynamicLinks.resolveLink(link);
}

0 comments on commit 0157296

Please sign in to comment.