Skip to content

Fix handleOpenURL spelling. #4758

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages-exp/auth-exp/src/platform_cordova/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export interface CordovaWindow extends Window {
readonly displayName: string;
};

handleOpenUrl(url: string): void;
handleOpenURL(url: string): void;
}

export interface InAppBrowserRef {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,18 +228,18 @@ describe('platform_cordova/popup_redirect/popup_redirect', () => {
});
});

context('when using global handleOpenUrl callback', () => {
context('when using global handleOpenURL callback', () => {
it('ignores inbound callbacks that are not for this app', async () => {
await resolver._initialize(auth);
win.handleOpenUrl(`${NOT_PACKAGE_NAME}://foo`);
win.handleOpenURL(`${NOT_PACKAGE_NAME}://foo`);

// Clear timeout is called in the handler so we can check that
expect(win.clearTimeout).not.to.have.been.called;
});

it('passes through callback if package name matches', async () => {
await resolver._initialize(auth);
win.handleOpenUrl(`${PACKAGE_NAME}://foo`);
win.handleOpenURL(`${PACKAGE_NAME}://foo`);
expect(win.clearTimeout).to.have.been.calledWith(NO_EVENT_TIMER_ID);
});

Expand All @@ -256,32 +256,32 @@ describe('platform_cordova/popup_redirect/popup_redirect', () => {

const promise = event(await resolver._initialize(auth));
eventsStubs._eventFromPartialAndUrl!.returns(finalEvent as AuthEvent);
win.handleOpenUrl(`${PACKAGE_NAME}://foo`);
win.handleOpenURL(`${PACKAGE_NAME}://foo`);
expect(await promise).to.eq(finalEvent);
expect(events._eventFromPartialAndUrl).to.have.been.calledWith(
{ type: AuthEventType.REAUTH_VIA_REDIRECT },
`${PACKAGE_NAME}://foo`
);
});

it('calls the dev existing handleOpenUrl function', async () => {
const oldHandleOpenUrl = sinon.stub();
win.handleOpenUrl = oldHandleOpenUrl;
it('calls the dev existing handleOpenURL function', async () => {
const oldHandleOpenURL = sinon.stub();
win.handleOpenURL = oldHandleOpenURL;

await resolver._initialize(auth);
win.handleOpenUrl(`${PACKAGE_NAME}://foo`);
expect(oldHandleOpenUrl).to.have.been.calledWith(
win.handleOpenURL(`${PACKAGE_NAME}://foo`);
expect(oldHandleOpenURL).to.have.been.calledWith(
`${PACKAGE_NAME}://foo`
);
});

it('calls the dev existing handleOpenUrl function for other package', async () => {
const oldHandleOpenUrl = sinon.stub();
win.handleOpenUrl = oldHandleOpenUrl;
it('calls the dev existing handleOpenURL function for other package', async () => {
const oldHandleOpenURL = sinon.stub();
win.handleOpenURL = oldHandleOpenURL;

await resolver._initialize(auth);
win.handleOpenUrl(`${NOT_PACKAGE_NAME}://foo`);
expect(oldHandleOpenUrl).to.have.been.calledWith(
win.handleOpenURL(`${NOT_PACKAGE_NAME}://foo`);
expect(oldHandleOpenURL).to.have.been.calledWith(
`${NOT_PACKAGE_NAME}://foo`
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolverInternal {
manager: AuthEventManager
): void {
// Get the global plugins
const { universalLinks, handleOpenUrl, BuildInfo } = _cordovaWindow();
const { universalLinks, handleOpenURL, BuildInfo } = _cordovaWindow();

const noEventTimeout = setTimeout(async () => {
// We didn't see that initial event. Clear any pending object and
Expand Down Expand Up @@ -149,18 +149,18 @@ class CordovaPopupRedirectResolver implements PopupRedirectResolverInternal {
// For this to work, cordova-plugin-customurlscheme needs to be installed.
// https://github.com/EddyVerbruggen/Custom-URL-scheme
// Do not overwrite the existing developer's URL handler.
const existingHandleOpenUrl = handleOpenUrl;
const existingHandleOpenURL = handleOpenURL;
const packagePrefix = `${BuildInfo.packageName.toLowerCase()}://`;
_cordovaWindow().handleOpenUrl = async url => {
_cordovaWindow().handleOpenURL = async url => {
if (url.toLowerCase().startsWith(packagePrefix)) {
// We want this intentionally to float
// eslint-disable-next-line @typescript-eslint/no-floating-promises
universalLinksCb({ url });
}
// Call the developer's handler if it is present.
if (typeof existingHandleOpenUrl === 'function') {
if (typeof existingHandleOpenURL === 'function') {
try {
existingHandleOpenUrl(url);
existingHandleOpenURL(url);
} catch (e) {
// This is a developer error. Don't stop the flow of the SDK.
console.error(e);
Expand Down