-
Notifications
You must be signed in to change notification settings - Fork 15
fix(email_verification): should refresh email verification is called once per second #125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
5172cbd
fb6e67a
525cb00
88aac6d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
This file was deleted.
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.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,20 @@ import EmailVerification from "../../recipe/emailverification"; | |
| import SuperTokens from "../../lib/build/supertokens"; | ||
| import assert from "assert"; | ||
|
|
||
| /* | ||
| * Delay function is used in case of email verification claim as we have added a debouncing | ||
| * mechanism that shouldRefresh will return false if multiple calls are done in 1000ms. | ||
| * Hence adding delay after each email verification or shouldRefresh calls will result in | ||
| * correct tests. | ||
| * Test for checking when the shouldRefresh returning false when called multiple times in 1000ms | ||
| * is added. | ||
| */ | ||
| const delay = async () => { | ||
| return new Promise((resolve) => { | ||
| setTimeout(resolve, 1000); | ||
| }); | ||
| }; | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer if you did this through manipulating the |
||
| describe("EmailVerificationClaim test", function () { | ||
| jsdom({ url: "http://localhost.org" }); | ||
|
|
||
|
|
@@ -35,6 +49,7 @@ describe("EmailVerificationClaim test", function () { | |
| }); | ||
|
|
||
| const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); | ||
| await delay(); // Added for correct results, since shouldRefresh is debounced | ||
| const shouldRefreshUndefined = await validator.shouldRefresh({}); | ||
| assert.strictEqual(shouldRefreshUndefined, true); | ||
| }); | ||
|
|
@@ -49,9 +64,11 @@ describe("EmailVerificationClaim test", function () { | |
| }); | ||
|
|
||
| const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(10, 200); | ||
| await delay(); // Added for correct results, since shouldRefresh is debounced | ||
| const shouldRefreshValid = await validator.shouldRefresh({ | ||
| "st-ev": { v: true, t: Date.now() - 199 * 1000 }, | ||
| }); | ||
| await delay(); // Added for correct results, since shouldRefresh is debounced | ||
| const shouldRefreshExpired = await validator.shouldRefresh({ | ||
| "st-ev": { v: true, t: Date.now() - 201 * 1000 }, | ||
| }); | ||
|
|
@@ -69,9 +86,11 @@ describe("EmailVerificationClaim test", function () { | |
| }); | ||
|
|
||
| const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(8); | ||
| await delay(); // Added for correct results, since shouldRefresh is debounced | ||
| const shouldRefreshValid = await validator.shouldRefresh({ | ||
| "st-ev": { v: false, t: Date.now() - 7 * 1000 }, | ||
| }); | ||
| await delay(); // Added for correct results, since shouldRefresh is debounced | ||
| const shouldRefreshExpired = await validator.shouldRefresh({ | ||
| "st-ev": { v: false, t: Date.now() - 9 * 1000 }, | ||
| }); | ||
|
|
@@ -90,14 +109,38 @@ describe("EmailVerificationClaim test", function () { | |
|
|
||
| // NOTE: the default value of refetchTimeOnFalseInSeconds is 10 seconds | ||
| const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); | ||
| await delay(); // Added for correct results, since shouldRefresh is debounced | ||
| const shouldRefreshValid = await validator.shouldRefresh({ | ||
| "st-ev": { v: false, t: Date.now() - 9 * 1000 }, | ||
| }); | ||
| await delay(); // Added for correct results, since shouldRefresh is debounced | ||
| const shouldRefreshExpired = await validator.shouldRefresh({ | ||
| "st-ev": { v: false, t: Date.now() - 11 * 1000 }, | ||
| }); | ||
| assert.strictEqual(shouldRefreshValid, false); | ||
| assert.strictEqual(shouldRefreshExpired, true); | ||
| }); | ||
|
|
||
| it("shouldRefresh should return false if called before 1000ms", async function () { | ||
| SuperTokens.init({ | ||
| appInfo: { | ||
| appName: "SuperTokens", | ||
| apiDomain: "api.supertokens.io", | ||
| }, | ||
| recipeList: [EmailVerification.init()], | ||
| }); | ||
|
|
||
| // NOTE: the default value of refetchTimeOnFalseInSeconds is 10 seconds | ||
| const validator = EmailVerification.EmailVerificationClaim.validators.isVerified(); | ||
| await delay(); // Added for correct results, since shouldRefresh is debounced | ||
| const shouldRefresh = await validator.shouldRefresh({ | ||
| "st-ev": { v: false, t: Date.now() - 11 * 1000 }, | ||
| }); | ||
| const shouldRefreshAgain = await validator.shouldRefresh({ | ||
| "st-ev": { v: false, t: Date.now() - 11 * 1000 }, | ||
| }); | ||
| assert.strictEqual(shouldRefresh, true); | ||
| assert.strictEqual(shouldRefreshAgain, false); | ||
| }); | ||
| }); | ||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.