-
Notifications
You must be signed in to change notification settings - Fork 91
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for default signin feature
- Loading branch information
1 parent
0333dbf
commit fa3b6f7
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -669,6 +669,94 @@ describe("SuperTokens SignIn", function () { | |
}); | ||
}); | ||
}); | ||
|
||
describe("SignIn default field tests", function () { | ||
it("Should contain email and password fields prefilled", async function () { | ||
await page.evaluate(() => window.localStorage.setItem("SHOW_SIGNIN_DEFAULT_FIELDS", "YES")); | ||
|
||
await page.reload({ | ||
waitUntil: "domcontentloaded", | ||
}); | ||
|
||
const expectedDefaultValues = { | ||
email: "[email protected]", | ||
password: "fakepassword123", | ||
}; | ||
|
||
const emailInput = await getInputField(page, "email"); | ||
const defaultEmail = await emailInput.evaluate((f) => f.value); | ||
assert.strictEqual(defaultEmail, expectedDefaultValues["email"]); | ||
|
||
const passwordInput = await getInputField(page, "password"); | ||
const defaultPassword = await passwordInput.evaluate((f) => f.value); | ||
assert.strictEqual(defaultPassword, expectedDefaultValues["password"]); | ||
}); | ||
|
||
it("Should have default values in the signin request payload", async function () { | ||
await page.evaluate(() => window.localStorage.setItem("SHOW_SIGNIN_DEFAULT_FIELDS", "YES")); | ||
|
||
await page.reload({ | ||
waitUntil: "domcontentloaded", | ||
}); | ||
|
||
const expectedDefautlValues = [ | ||
{ id: "email", value: "[email protected]" }, | ||
{ id: "password", value: "fakepassword123" }, | ||
]; | ||
|
||
let assertionError = null; | ||
let interceptionPassed = false; | ||
|
||
const requestHandler = async (request) => { | ||
if (request.url().includes(SIGN_IN_API) && request.method() === "POST") { | ||
try { | ||
const postData = JSON.parse(request.postData()); | ||
expectedDefautlValues.forEach(({ id, value }) => { | ||
let findFormData = postData.formFields.find((inputData) => inputData.id === id); | ||
if (findFormData) { | ||
assert.strictEqual(findFormData["value"], value, `Mismatch in payload for key: ${id}`); | ||
} else { | ||
throw new Error("Field not found in req.data"); | ||
} | ||
}); | ||
interceptionPassed = true; | ||
return request.respond({ | ||
status: 200, | ||
headers: { | ||
"access-control-allow-origin": TEST_CLIENT_BASE_URL, | ||
"access-control-allow-credentials": "true", | ||
}, | ||
body: JSON.stringify({ | ||
status: "OK", | ||
}), | ||
}); | ||
} catch (error) { | ||
assertionError = error; // Store the error | ||
} | ||
} | ||
return request.continue(); | ||
}; | ||
|
||
await page.setRequestInterception(true); | ||
page.on("request", requestHandler); | ||
|
||
try { | ||
// Perform the button click and wait for all network activity to finish | ||
await Promise.all([page.waitForNetworkIdle(), submitForm(page)]); | ||
} finally { | ||
page.off("request", requestHandler); | ||
await page.setRequestInterception(false); | ||
} | ||
|
||
if (assertionError) { | ||
throw assertionError; | ||
} | ||
|
||
if (!interceptionPassed) { | ||
throw new Error("test failed"); | ||
} | ||
}); | ||
}); | ||
}); | ||
|
||
describe("SuperTokens SignIn => Server Error", function () { | ||
|