Skip to content

Add afterEach method and apply formatting to the hosting links integr… #8615

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
Oct 29, 2024
Merged
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
99 changes: 45 additions & 54 deletions packages/auth/test/integration/flows/hosting_link.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@
*/

// eslint-disable-next-line import/no-extraneous-dependencies
import { ActionCodeSettings, Auth, sendSignInLinkToEmail } from '@firebase/auth';
import {
ActionCodeSettings,
Auth,
sendSignInLinkToEmail
} from '@firebase/auth';
import { expect, use } from 'chai';
import {
cleanUpTestInstance,
getTestInstance,
randomEmail
} from '../../helpers/integration/helpers';
Expand All @@ -33,16 +38,16 @@ describe('Integration test: hosting link validation', () => {
let auth: Auth;
let email: string;

const AUTHORIZED_CUSTOM_DOMAIN = "localhost/action_code_return";
const ANDROID_PACKAGE_NAME = "com.google.firebase.test.thin";
const AUTHORIZED_CUSTOM_DOMAIN = 'localhost/action_code_return';
const ANDROID_PACKAGE_NAME = 'com.google.firebase.test.thin';
const BASE_SETTINGS: ActionCodeSettings = {
url: 'http://' + AUTHORIZED_CUSTOM_DOMAIN,
handleCodeInApp: true,
android: {packageName: ANDROID_PACKAGE_NAME},
android: { packageName: ANDROID_PACKAGE_NAME }
};
const VALID_LINK_DOMAIN = "jscore-sandbox.testdomaindonotuse.com";
const INVALID_LINK_DOMAIN = "invalid.testdomaindonotuse.com";
const INVALID_LINK_DOMAIN_ERROR = "auth/invalid-hosting-link-domain";
const VALID_LINK_DOMAIN = 'jscore-sandbox.testdomaindonotuse.com';
const INVALID_LINK_DOMAIN = 'invalid.testdomaindonotuse.com';
const INVALID_LINK_DOMAIN_ERROR = 'auth/invalid-hosting-link-domain';
const TEST_TENANT_ID = 'passpol-tenant-d7hha';

beforeEach(function () {
Expand All @@ -53,63 +58,49 @@ describe('Integration test: hosting link validation', () => {
this.skip();
}
});


afterEach(async () => {
await cleanUpTestInstance(auth);
});

it('allows user to sign in with default firebase hosting link', async () => {
// Sends email link to user using default hosting link.
await sendSignInLinkToEmail(
auth,
email,
BASE_SETTINGS
);
await sendSignInLinkToEmail(auth, email, BASE_SETTINGS);
});

it('allows user to sign in to a tenant with default firebase hosting link', async () => {
auth.tenantId = TEST_TENANT_ID;
// Sends email link to user using default hosting link.
await sendSignInLinkToEmail(
auth,
email,
BASE_SETTINGS
);
await sendSignInLinkToEmail(auth, email, BASE_SETTINGS);
});

it('allows user to sign in with custom firebase hosting link', async () => {
// Sends email link to user using custom hosting link.
await sendSignInLinkToEmail(
auth,
email,
{
...BASE_SETTINGS,
linkDomain: VALID_LINK_DOMAIN

}
);
});
// Sends email link to user using custom hosting link.
await sendSignInLinkToEmail(auth, email, {
...BASE_SETTINGS,
linkDomain: VALID_LINK_DOMAIN
});
});

it('allows user to sign in to a tenant with custom firebase hosting link', async () => {
// Sends email link to user using custom hosting link.
auth.tenantId = TEST_TENANT_ID;
await sendSignInLinkToEmail(
auth,
email,
{
...BASE_SETTINGS,
linkDomain: VALID_LINK_DOMAIN

}
);
});
it('allows user to sign in to a tenant with custom firebase hosting link', async () => {
// Sends email link to user using custom hosting link.
auth.tenantId = TEST_TENANT_ID;
await sendSignInLinkToEmail(auth, email, {
...BASE_SETTINGS,
linkDomain: VALID_LINK_DOMAIN
});
});

it('sign in with invalid firebase hosting link throws exception', async () => {
// Throws an exception while sening email link to user using invalid hosting link.
await expect(sendSignInLinkToEmail(
auth,
email,
{
...BASE_SETTINGS,
linkDomain: INVALID_LINK_DOMAIN
}
)).to.be.rejectedWith(FirebaseError, new RegExp(".*" + INVALID_LINK_DOMAIN_ERROR + ".*"));
});
it('sign in with invalid firebase hosting link throws exception', async () => {
// Throws an exception while sening email link to user using invalid hosting link.
await expect(
sendSignInLinkToEmail(auth, email, {
...BASE_SETTINGS,
linkDomain: INVALID_LINK_DOMAIN
})
).to.be.rejectedWith(
FirebaseError,
new RegExp('.*' + INVALID_LINK_DOMAIN_ERROR + '.*')
);
});
});
Loading