Skip to content

Commit

Permalink
Enforce no api request are made on blank forms
Browse files Browse the repository at this point in the history
  • Loading branch information
amitbadala committed Nov 7, 2023
1 parent f8e9cca commit 18a411f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 12 deletions.
33 changes: 29 additions & 4 deletions test/end-to-end/signin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,35 @@ describe("SuperTokens SignIn", function () {
waitUntil: "domcontentloaded",
});

await submitForm(page);
let formFieldErrors = await getFieldErrors(page);
// Also standard non-optional-error is displayed if nonOptionalErrorMsg is not provided
assert.deepStrictEqual(formFieldErrors, ["Please add email", "Field is not optional"]);
let apiCallMade = false;

const requestHandler = (request) => {
const url = request.url();
if (url === SIGN_IN_API) {
apiCallMade = true;
request.continue();
} else {
request.continue();
}
};

await page.setRequestInterception(true);
page.on("request", requestHandler);

try {
await submitForm(page);
let formFieldErrors = await getFieldErrors(page);

// Also standard non-optional-error is displayed if nonOptionalErrorMsg is not provided
assert.deepStrictEqual(formFieldErrors, ["Please add email", "Field is not optional"]);
} finally {
page.off("request", requestHandler);
await page.setRequestInterception(false);
}

if (apiCallMade) {
throw new Error("Empty form making API request to signin");
}
});
});
});
Expand Down
44 changes: 36 additions & 8 deletions test/end-to-end/signup.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,14 +478,42 @@ describe("SuperTokens SignUp", function () {
});

it("Check on blank form submit nonOptionalErrorMsg gets displayed as expected", async function () {
await submitForm(page);
let formFieldErrors = await getFieldErrors(page);
// Also standard non-optional-error is displayed if nonOptionalErrorMsg is not provided
assert.deepStrictEqual(formFieldErrors, [
"Field is not optional",
"Field is not optional",
"You must accept the terms and conditions",
]);
let apiCallMade = false;

const requestHandler = (request) => {
const url = request.url();
if (url === SIGN_UP_API) {
apiCallMade = true;
request.continue();
} else {
request.continue();
}
};

await page.setRequestInterception(true);
page.on("request", requestHandler);

// Listen for all network requests
page.on("request", (request) => {});

try {
// Fill and submit the form with custom fields
await submitForm(page);
let formFieldErrors = await getFieldErrors(page);
// Also standard non-optional-error is displayed if nonOptionalErrorMsg is not provided
assert.deepStrictEqual(formFieldErrors, [
"Field is not optional",
"Field is not optional",
"You must accept the terms and conditions",
]);
} finally {
page.off("request", requestHandler);
await page.setRequestInterception(false);
}

if (apiCallMade) {
throw new Error("Empty form making API request to sign-up");
}
});

it("Check if nonOptionalErrorMsg overwrites server error message for non-optional fields", async function () {
Expand Down

0 comments on commit 18a411f

Please sign in to comment.