Skip to content
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

CHK-3737 : add integration test post auth token #450

Draft
wants to merge 2 commits into
base: CHK-3735-post-authentication-impl
Choose a base branch
from
Draft
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
13 changes: 13 additions & 0 deletions src/__integration_tests__/authentication.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

const CHECKOUT_URL = `http://localhost:1234`;
const MOCK_AUTH_REDIRECT_URL = `http://localhost:8080/auth-redirect-url`;
const CALLBACK_URL = `http://localhost:1234/auth-callback?auth-code=1234`;
const PAGE_LOGIN_URL = `http://localhost:1234/inserisci-email`;


jest.setTimeout(80000);
Expand Down Expand Up @@ -39,5 +41,16 @@ describe("Checkout authentication tests", () => {
expect(currentUrl).toBe(MOCK_AUTH_REDIRECT_URL);
});

it.only("Should correctly come back to login origin url", async () => {
await page.evaluate(() => {
//set item into sessionStorage and localStorage for pass the route Guard
sessionStorage.setItem('loginOriginPage', 'http://localhost:1234/inserisci-email');
}, "it");
await page.goto(CALLBACK_URL);
await page.waitForNavigation();
const currentUrl = await page.evaluate(() => location.href);
console.log("Current url: " + currentUrl);
expect(currentUrl).toBe(PAGE_LOGIN_URL);
});

});
6 changes: 2 additions & 4 deletions src/routes/AuthCallbackPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,9 @@ export default function AuthCallback() {
const [error, setError] = React.useState("");
const [errorModalOpen, setErrorModalOpen] = React.useState(false);

const onError = (m: string) => {
const onError = (m: string | undefined) => {
window.removeEventListener("popstate", onBrowserBackEvent);
window.removeEventListener("beforeunload", onBrowserUnload);
setError(m);
setErrorModalOpen(true);
};

// navigate to last page from session storage
Expand All @@ -49,7 +47,7 @@ export default function AuthCallback() {
void (async (authCode) => {
void authentication({
authCode,
onResponse: (authToken: string) => {
onResponse: (authToken: string | undefined) => {
setSessionItem(SessionItems.authToken, authToken);
returnToOriginPage();
},
Expand Down
6 changes: 3 additions & 3 deletions src/utils/api/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,8 @@ export const authentication = async ({
onError,
}: {
authCode: string | null;
onResponse: (e: string) => void;
onError: (e: string) => void;
onResponse: (e: string | undefined) => void;
onError: (e: string | undefined) => void;
}) => {
await pipe(
O.fromNullable(authCode),
Expand Down Expand Up @@ -693,7 +693,7 @@ export const authentication = async ({
() => onError,
() => onResponse
)
);
)(myRes?.value.authToken);
} else {
onError(ErrorsType.GENERIC_ERROR);
}
Expand Down