Skip to content

Commit

Permalink
refactor: test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
porcellus committed May 16, 2024
1 parent 91ff48b commit 666d30b
Show file tree
Hide file tree
Showing 28 changed files with 412 additions and 720 deletions.
4 changes: 2 additions & 2 deletions lib/build/emailpasswordprebuiltui.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions lib/build/index2.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 6 additions & 15 deletions lib/build/recipe/emailpassword/prebuiltui.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions lib/build/recipe/thirdparty/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import AuthPageThemeWrapper from "../../theme/authPage";

import type AuthRecipe from "../../..";
import type { TranslationStore } from "../../../../../translation/translationHelpers";
import type { Navigate, PartialAuthComponent, UserContext } from "../../../../../types";
import type { AuthComponent, Navigate, PartialAuthComponent, UserContext } from "../../../../../types";
import type { GetLoginMethodsResponseNormalized } from "../../../../multitenancy/types";
import type { RecipeRouter } from "../../../../recipeRouter";
import type { AuthPageThemeProps } from "../../../types";
Expand Down Expand Up @@ -102,7 +102,7 @@ const AuthPageInner: React.FC<AuthPageProps> = (props) => {
GetLoginMethodsResponseNormalized | undefined
>(undefined);
const [error, setError] = useState<string | undefined>(errorFromQS);
const [sessionLoadedAndDidNotExist, setSessionLoadedAndDidNotExist] = useState(false);
const [sessionLoadedAndNotRedirecting, setSessionLoadedAndNotRedirecting] = useState(false);
const st = SuperTokens.getInstanceOrThrow();
const [factorList, setFactorList] = useState<string[] | undefined>(props.factors);
const [isSignUp, setIsSignUp] = useState<boolean>(props.isSignUp ?? isSignUpFromQS ?? st.defaultToSignUp);
Expand Down Expand Up @@ -131,7 +131,7 @@ const AuthPageInner: React.FC<AuthPageProps> = (props) => {
}, [loadedDynamicLoginMethods, setLoadedDynamicLoginMethods]);

useEffect(() => {
if (sessionLoadedAndDidNotExist) {
if (sessionLoadedAndNotRedirecting) {
return;
}

Expand All @@ -155,9 +155,11 @@ const AuthPageInner: React.FC<AuthPageProps> = (props) => {
props.navigate
)
.catch(rethrowInRender);
} else {
setSessionLoadedAndNotRedirecting(true);
}
} else {
setSessionLoadedAndDidNotExist(true);
setSessionLoadedAndNotRedirecting(true);
}
}
}, [sessionContext.loading]);
Expand All @@ -181,7 +183,7 @@ const AuthPageInner: React.FC<AuthPageProps> = (props) => {
}

if (
sessionLoadedAndDidNotExist &&
sessionLoadedAndNotRedirecting &&
(loadedDynamicLoginMethods !== undefined || !SuperTokens.usesDynamicLoginMethods)
) {
void buildAndSetChildProps(
Expand All @@ -201,7 +203,7 @@ const AuthPageInner: React.FC<AuthPageProps> = (props) => {
abortCtl.abort();
};
}, [
sessionLoadedAndDidNotExist,
sessionLoadedAndNotRedirecting,
rebuildReqCount,
setRebuildReqCount,
props.preBuiltUIList,
Expand Down Expand Up @@ -323,7 +325,7 @@ async function buildAndSetChildProps(

const isSignUp = hasSeparateSignUpView && isSignUpState;

const authComps = [];
const authComps: AuthComponent[] = [];

for (const ui of recipeRouters) {
authComps.push(...ui.getAuthComponents());
Expand Down
9 changes: 6 additions & 3 deletions lib/ts/recipe/emailpassword/prebuiltui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,7 @@ export class EmailPasswordPreBuiltUI extends RecipeRouter {
return;
}

static SignInFeature = SignInFeature;
static SignInTheme = SignInTheme;
static SignUpFeature = SignUpFeature;
static SignUpTheme = SignUpTheme;

static ResetPasswordUsingToken = (prop: FeatureBaseProps<{ userContext?: UserContext }>) =>
Expand All @@ -147,4 +145,9 @@ export class EmailPasswordPreBuiltUI extends RecipeRouter {

const ResetPasswordUsingToken = EmailPasswordPreBuiltUI.ResetPasswordUsingToken;

export { ResetPasswordUsingToken, ResetPasswordUsingTokenThemeWrapper as ResetPasswordUsingTokenTheme };
export {
ResetPasswordUsingToken,
SignInTheme,
SignUpTheme,
ResetPasswordUsingTokenThemeWrapper as ResetPasswordUsingTokenTheme,
};
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import type Recipe from "../../../recipe";
import type { AdditionalLoginAttemptInfoProperties, ComponentOverrideMap, MFAChildProps } from "../../../types";
import type { MFAAction, MFAState, NormalisedConfig } from "../../../types";
import type { RecipeInterface } from "supertokens-web-js/recipe/passwordless";
import type { PasswordlessFlowType } from "supertokens-web-js/recipe/thirdpartypasswordless";
import type { PasswordlessFlowType } from "supertokens-web-js/recipe/passwordless/types";

export const useFeatureReducer = (): [MFAState, React.Dispatch<MFAAction>] => {
return React.useReducer(
Expand Down
3 changes: 1 addition & 2 deletions lib/ts/recipe/thirdparty/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ import { UserInput, GetRedirectionURLContext, PreAPIHookContext, OnHandleEventCo
import { redirectToThirdPartyLogin as UtilsRedirectToThirdPartyLogin } from "./utils";

import type { UserContext } from "../../types";
import type { StateObject } from "supertokens-web-js/recipe/thirdparty";
import type { RecipeFunctionOptions } from "supertokens-web-js/recipe/thirdpartyemailpassword";
import type { StateObject, RecipeFunctionOptions } from "supertokens-web-js/recipe/thirdparty";
import type { User } from "supertokens-web-js/types";

export default class Wrapper {
Expand Down
11 changes: 5 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
"peerDependencies": {
"react": ">=16.8.0",
"react-dom": ">=16.8.0",
"supertokens-web-js": "^0.11.0"
"supertokens-web-js": "github:supertokens/supertokens-web-js#feat/remove_combo_recipes"
},
"scripts": {
"init": "bash ./init.sh",
Expand Down
1 change: 1 addition & 0 deletions test/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ export const SEND_VERIFY_EMAIL_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/u
export const VERIFY_EMAIL_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/user/email/verify`;
export const SIGN_IN_UP_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/signinup`;
export const CREATE_CODE_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/signinup/code`;
export const CONSUME_CODE_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/signinup/code/consume`;
export const CREATE_TOTP_DEVICE_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/totp/device`;
export const GET_AUTH_URL_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/authorisationurl`;
export const LOGIN_METHODS_API = `${TEST_APPLICATION_SERVER_BASE_URL}/auth/loginmethods`;
Expand Down
91 changes: 90 additions & 1 deletion test/end-to-end/mfa.factorscreen.otp.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ import {
setAccountLinkingConfig,
} from "../helpers";
import fetch from "isomorphic-fetch";
import { CREATE_CODE_API, CREATE_TOTP_DEVICE_API, MFA_INFO_API, SOMETHING_WENT_WRONG_ERROR } from "../constants";
import {
CONSUME_CODE_API,
CREATE_CODE_API,
CREATE_TOTP_DEVICE_API,
MFA_INFO_API,
SOMETHING_WENT_WRONG_ERROR,
} from "../constants";

import { TEST_CLIENT_BASE_URL, TEST_SERVER_BASE_URL } from "../constants";
import { getTestPhoneNumber } from "../exampleTestHelpers";
Expand Down Expand Up @@ -328,6 +334,89 @@ describe("SuperTokens SignIn w/ MFA", function () {
}
});

it("should handle consumeCode restart flow error", async () => {
await setMFAInfo({
requirements: [factorId],
alreadySetup: [factorId],
allowedToSetup: [factorId],
});

await page.setRequestInterception(true);
const requestHandler = (request) => {
if (request.url() === CONSUME_CODE_API && request.method() === "POST") {
return request.respond({
status: 200,
headers: {
"access-control-allow-origin": TEST_CLIENT_BASE_URL,
"access-control-allow-credentials": "true",
},
body: JSON.stringify({
status: "RESTART_FLOW_ERROR",
}),
});
}

return request.continue();
};
page.on("request", requestHandler);
try {
await tryEmailPasswordSignIn(page, email);

await completeOTP(page);

await waitForAccessDenied(page);
} finally {
page.off("request", requestHandler);
await page.setRequestInterception(false);
}
});

it("should handle consumeCode restart flow error when setting up factor", async () => {
await setMFAInfo({
requirements: [factorId],
alreadySetup: [],
allowedToSetup: [factorId],
noContacts: true,
});

await page.setRequestInterception(true);
const requestHandler = (request) => {
if (request.url() === CONSUME_CODE_API && request.method() === "POST") {
return request.respond({
status: 200,
headers: {
"access-control-allow-origin": TEST_CLIENT_BASE_URL,
"access-control-allow-credentials": "true",
},
body: JSON.stringify({
status: "RESTART_FLOW_ERROR",
}),
});
}

return request.continue();
};
page.on("request", requestHandler);
try {
await tryEmailPasswordSignIn(page, email);

await setInputValues(page, [
contactMethod === "PHONE"
? { name: "phoneNumber_text", value: getTestPhoneNumber() }
: { name: "email", value: await getTestEmail() },
]);
await submitForm(page);

await completeOTP(page);

const error = await getGeneralError(page);
assert.strictEqual("Login unsuccessful. Please try again.", error);
} finally {
page.off("request", requestHandler);
await page.setRequestInterception(false);
}
});

it("should enable you to change the contact info during setup (w/ contact form)", async () => {
await setMFAInfo({
requirements: [factorId],
Expand Down
Loading

0 comments on commit 666d30b

Please sign in to comment.