generated from sergiodxa/remix-auth-strategy-template
-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use context.formData if available over request.formData() (#14)
* Use context.formData if available over request.formData() * Add docs
- Loading branch information
Showing
3 changed files
with
67 additions
and
1 deletion.
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 |
---|---|---|
|
@@ -70,4 +70,44 @@ describe(FormStrategy, () => { | |
|
||
expect(verify).toBeCalledWith({ form: body, context }); | ||
}); | ||
|
||
test("should prefer context.formData over request.formData()", async () => { | ||
let body = new FormData(); | ||
body.set("email", "[email protected]"); | ||
|
||
let request = new Request("", { body, method: "POST" }); | ||
|
||
let context = { formData: body }; | ||
|
||
let strategy = new FormStrategy<string>(async ({ form }) => { | ||
return form.get("email") as string; | ||
}); | ||
|
||
expect( | ||
strategy.authenticate(request, sessionStorage, { | ||
sessionKey: "user", | ||
context, | ||
}) | ||
).resolves.toBe("[email protected]"); | ||
}); | ||
|
||
test("ignore context.formData if it's not an FormData object", async () => { | ||
let body = new FormData(); | ||
body.set("email", "[email protected]"); | ||
|
||
let request = new Request("", { body, method: "POST" }); | ||
|
||
let context = { formData: { email: "[email protected]" } }; | ||
|
||
let strategy = new FormStrategy<string>(async ({ form }) => { | ||
return form.get("email") as string; | ||
}); | ||
|
||
expect( | ||
strategy.authenticate(request, sessionStorage, { | ||
sessionKey: "user", | ||
context, | ||
}) | ||
).resolves.toBe("[email protected]"); | ||
}); | ||
}); |