-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: Add support for any type in formField values (#924)
* Add support for accepting any type in form fields * Add test case for int in formField --------- Co-authored-by: Rishabh Poddar <[email protected]>
- Loading branch information
1 parent
2488e0e
commit f6b577f
Showing
3 changed files
with
137 additions
and
3 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
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
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 |
---|---|---|
|
@@ -830,6 +830,136 @@ describe(`signupFeature: ${printPath("[test/emailpassword/signupFeature.test.js] | |
assert(response.user.emails[0] === "[email protected]"); | ||
}); | ||
|
||
it("test valid boolean formFields with optional", async function () { | ||
const connectionURI = await startST(); | ||
STExpress.init({ | ||
supertokens: { | ||
connectionURI, | ||
}, | ||
appInfo: { | ||
apiDomain: "api.supertokens.io", | ||
appName: "SuperTokens", | ||
websiteDomain: "supertokens.io", | ||
}, | ||
recipeList: [ | ||
EmailPassword.init({ | ||
signUpFeature: { | ||
formFields: [ | ||
{ | ||
id: "autoVerify", | ||
optional: false, | ||
}, | ||
], | ||
}, | ||
}), | ||
Session.init({ getTokenTransferMethod: () => "cookie" }), | ||
], | ||
}); | ||
const app = express(); | ||
|
||
app.use(middleware()); | ||
|
||
app.use(errorHandler()); | ||
|
||
let response = await new Promise((resolve) => | ||
request(app) | ||
.post("/auth/signup") | ||
.send({ | ||
formFields: [ | ||
{ | ||
id: "password", | ||
value: "validpass123", | ||
}, | ||
{ | ||
id: "email", | ||
value: "[email protected]", | ||
}, | ||
{ | ||
id: "autoVerify", | ||
value: false, | ||
}, | ||
], | ||
}) | ||
.expect(200) | ||
.end((err, res) => { | ||
if (err) { | ||
resolve(undefined); | ||
} else { | ||
resolve(JSON.parse(res.text)); | ||
} | ||
}) | ||
); | ||
|
||
assert(response.status === "OK"); | ||
assert(response.user.id !== undefined); | ||
assert(response.user.emails[0] === "[email protected]"); | ||
}); | ||
|
||
it("test valid int formFields with optional", async function () { | ||
const connectionURI = await startST(); | ||
STExpress.init({ | ||
supertokens: { | ||
connectionURI, | ||
}, | ||
appInfo: { | ||
apiDomain: "api.supertokens.io", | ||
appName: "SuperTokens", | ||
websiteDomain: "supertokens.io", | ||
}, | ||
recipeList: [ | ||
EmailPassword.init({ | ||
signUpFeature: { | ||
formFields: [ | ||
{ | ||
id: "intField", | ||
optional: false, | ||
}, | ||
], | ||
}, | ||
}), | ||
Session.init({ getTokenTransferMethod: () => "cookie" }), | ||
], | ||
}); | ||
const app = express(); | ||
|
||
app.use(middleware()); | ||
|
||
app.use(errorHandler()); | ||
|
||
let response = await new Promise((resolve) => | ||
request(app) | ||
.post("/auth/signup") | ||
.send({ | ||
formFields: [ | ||
{ | ||
id: "password", | ||
value: "validpass123", | ||
}, | ||
{ | ||
id: "email", | ||
value: "[email protected]", | ||
}, | ||
{ | ||
id: "intField", | ||
value: 23, | ||
}, | ||
], | ||
}) | ||
.expect(200) | ||
.end((err, res) => { | ||
if (err) { | ||
resolve(undefined); | ||
} else { | ||
resolve(JSON.parse(res.text)); | ||
} | ||
}) | ||
); | ||
|
||
assert(response.status === "OK"); | ||
assert(response.user.id !== undefined); | ||
assert(response.user.emails[0] === "[email protected]"); | ||
}); | ||
|
||
//- Bad test case without optional (something is missing, and it's not optional) | ||
it("test bad case input to signup without optional", async function () { | ||
const connectionURI = await startST(); | ||
|