-
Notifications
You must be signed in to change notification settings - Fork 6
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
How to integrate with Wallaby integration tests #62
Comments
Hey @stabenfeldt , thanks for opening the issue! :D I personally haven't had the chance to use Wallaby, so I'm having a bit of trouble navigating through your issue. I'm assuming you are creating the Can you provide a small example project that I can run or provide a bit of more detail? I'm having trouble understanding what you exactly want to do. Your helper function seems to be similar to https://elixirforum.com/t/wallaby-testing-when-browser-session-is-required-i-e-login/8034/10, which they stated it works with
Thank you! Have a merry Christmas! (sorry if responses are slow right now, Christmas time with family and stuff :p ) |
Hi @LuchoTurtle, Thanks for replying to my issue, and I'm also sorry for being slow to reply. I'm in the mountains at the cabin, celebrating Christmas with my family. 🎅🏼😅 Enjoy the rest of your vacation with the family. |
Hi guys, I hope you had a relaxing and nice vacation! 🤩 I've made a quick and dirty POC. I would be grateful if you could help me to get the Wallaby tests running. Testing as a visitor works, but not as a signed-in user.
|
Thanks for providing the repo! I'm running The defmodule AppWeb.FrontPageFeatureTest do
use AppWeb.ConnCase
use Wallaby.Feature
import Wallaby.Query
import Wallaby.Browser
use Wallaby.DSL
@user_remember_me "_my_app_web_user_remember_me"
def log_in(%{session: session} = _context) do
# This is the profile data normally returned by ElixirAuthMicrosoft.get_user_profile(token.access_token)
# Implemented in the MicrosoftAuthController
profile = %{
id: "123",
mail: "[email protected]",
userPrincipalName: "[email protected]",
displayName: "John.Doe",
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users/$entity",
businessPhones: ["+47 955 22 44"],
givenName: "John",
surname: "Doe",
jobTitle: "Software Craftsman",
officeLocation: "Oslo"
}
conn = %Plug.Conn{secret_key_base: "secret_key_base"}
conn = Plug.Conn.put_session(conn, :profile, profile)
session
|> visit("/")
|> set_cookie(@user_remember_me, conn.resp_cookies[@user_remember_me][:value])
{:ok, %{session: session}}
end
setup context do
log_in(context)
end
feature "Visit the frontpage as a visitor", %{session: session} do
session
|> visit("/")
|> assert_has(css(".phx-hero", text: "To get started, login to your Microsoft Account"))
end
feature "Visit the frontpage as a logged in user", %{session: session} do
session
|> visit("/")
|> assert_has(css(".phx-hero", text: "Welcome John Doe"))
end
end It yields a In either case, I'll try to see what the issue is tomorrow. In any case, we do offer an easy way to mock the calls from our package. If you turn on the Let me know! And thank you again for the feedback, I hope you had an amazing Christmas and New Year's! 🎉 |
Hi guys, Sorry for not replying earlier. I got occupied with something else. I just verified that only the test verifying that you have logged in fails.
Can you please try again with the latest version of the main branch? |
Hi,
When a user signs in with his company's credentials and is redirected back to the provided endpoint, we get the user profile from
ElixirAuthMicrosoft.get_user_profile(token.access_token)
We store this in the session and redirect the user to the app:
Fair enough, but how do I replicate this in a
sign_in_user
function in my Wallaby tests?I found this post on ElixirForum. I've tried to massage it to fit with the auth logic provided by elixir-auth-mirosoft, but I don't understand everything and could need help to get the last pieces to fit together.
A simple test to see if a user has signed in
This is the session we inspect:
TestHelpers
What obvious steps am I missing?
How can I build a sign_in helper that mimics what we do in the MicrosoftAuthController callback?
BTW: I've been using ElixirAuthMicrosoft for 6 months now, and it works like a charm! I just need to get this final piece in place. 😊
The text was updated successfully, but these errors were encountered: