Skip to content

Commit

Permalink
Add tests for invalid email/password in token reset and reset API
Browse files Browse the repository at this point in the history
  • Loading branch information
deepjyoti30-st committed Sep 25, 2024
1 parent f31d336 commit b508079
Showing 1 changed file with 85 additions and 0 deletions.
85 changes: 85 additions & 0 deletions test/emailpassword/passwordreset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,48 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js]
assert(response.body.formFields[0].id === "email");
});

it("test invalid email type in generate token API", async function () {
const connectionURI = await startST();
STExpress.init({
supertokens: {
connectionURI,
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [EmailPassword.init(), Session.init()],
});
const app = express();

app.use(middleware());

app.use(errorHandler());

let response = await new Promise((resolve) =>
request(app)
.post("/auth/user/password/reset/token")
.send({
formFields: [
{
id: "email",
value: 123456,
},
],
})
.expect(400)
.end((err, res) => {
if (err) {
resolve(undefined);
} else {
resolve(res);
}
})
);
assert(response.body.message === "email value must be a string");
});

it("test that generated password link is correct", async function () {
const connectionURI = await startST();

Expand Down Expand Up @@ -255,6 +297,49 @@ describe(`passwordreset: ${printPath("[test/emailpassword/passwordreset.test.js]
assert(response.status !== "FIELD_ERROR");
});

it("test invalid type of password", async function () {
const connectionURI = await startST();
STExpress.init({
supertokens: {
connectionURI,
},
appInfo: {
apiDomain: "api.supertokens.io",
appName: "SuperTokens",
websiteDomain: "supertokens.io",
},
recipeList: [EmailPassword.init(), Session.init()],
});
const app = express();

app.use(middleware());

app.use(errorHandler());

let response = await new Promise((resolve) =>
request(app)
.post("/auth/user/password/reset")
.send({
formFields: [
{
id: "password",
value: 12345,
},
],
token: "randomToken",
})
.expect(400)
.end((err, res) => {
if (err) {
resolve(undefined);
} else {
resolve(JSON.parse(res.text));
}
})
);
assert(response.message === "password value must be a string");
});

it("test token missing from input", async function () {
const connectionURI = await startST();
STExpress.init({
Expand Down

0 comments on commit b508079

Please sign in to comment.