-
Notifications
You must be signed in to change notification settings - Fork 66
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
Action item test #390
Action item test #390
Conversation
test/support/test_helpers.ex
Outdated
Map.put(context, :other_user, other_user) | ||
end | ||
|
||
def assign_idea(%{other_user: other_user, retro: retro} = context) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm... rather than hardcode an action items values here, i think we should alter the existing persist_idea_for_retro
function such that it can be assigned to different users depending on the needs of the test. That way, we encapsulate idea creation in a single helper that can take dynamic category, body values, assignee, and so on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, i agree! will update.
test/support/test_helpers.ex
Outdated
@@ -3,6 +3,7 @@ defmodule RemoteRetro.TestHelpers do | |||
alias RemoteRetro.{Repo, User, Vote} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To avoid repeating RemoteRetro
, you can leverage the alias
macro, seen here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yessss.
test/support/test_helpers.ex
Outdated
end | ||
|
||
def assign_idea(%{other_user: other_user, retro: retro} = context) do | ||
idea = %RemoteRetro.Idea{assignee_id: other_user.id, body: "blurgh", category: "action-item", retro_id: retro.id, user_id: other_user.id} |> RemoteRetro.Repo.insert! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey Nichol, tiny but helpful elixir tidbit is that you can leverage the alias
macro (see comment) above so that you don't have to include the RemoteRetro
module prefix repeatedly. To learn more, peep this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
test/support/test_helpers.ex
Outdated
@@ -36,6 +37,27 @@ defmodule RemoteRetro.TestHelpers do | |||
Map.put(context, :user, user) | |||
end | |||
|
|||
def persist_other_user_for_retro(context) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @nicholalexander, i see what you mean about wanting to generalize user creation logic. given that each test helper takes and returns a context, maybe we could simply change the existing persist_user_for_retro
to persist_users_for_retro
, and have the callsites define @users
as a list of users. That way, we can keep the logic in the existing (though altered) method and avoid introducing a new method just for this 'other user' case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool.
test/support/test_helpers.ex
Outdated
Map.put(context, :idea, idea) | ||
end | ||
|
||
def set_participation(%{other_user: other_user, retro: retro} = context) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
given that a participation record represents the link of a user to a retro, i think we might want to encapsulate the creation of a participation in the persist_users_for_retro
helper. the benefit is that then we don't have to call set_participation
after we've called the helper that builds the necessary user. Whaddaya think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the only reason not to do this was if we wanted to test users without participations - like potentially if a user was invited but never joined and was assigned an action item? or something wierd like that? Not sure. Might be overly convoluted. I think I'll just set it in persist_users
as you suggest and then if its a problem down the road we can split it out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍!
browser_logs.log
Outdated
@@ -0,0 +1,16 @@ | |||
%cDownload the React DevTools for a better development experience: https://fb.me/react-devtools |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we recently added browser_logs.log
to the .gitignore, so i think this branch may have been cut off of master before that change got in. @nicholalexander Can you rebase and repush to see if this file gets removed from the diff?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes! should'a seen this.
b0a2924
to
5d7b700
Compare
This refactors the I think this should be ok, and if the logic we use to assign ideas becomes more complex, we can revist how this works. Primarily, you should check how things get called in the most complicated case, Additionally this adds Apex to the dependencies which is Elixir's version of Awesome Print. |
config/test.exs
Outdated
config :remote_retro, :other_user, %{ | ||
"email" => "misstestuser@gmail.com", | ||
"email_verified" => "true", "family_name" => "Alexander", | ||
"gender" => "female", "given_name" => "Nicole", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nicole, eh? 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought we'd want to have a good selection of test users.
test/support/test_helpers.ex
Outdated
Enum.each(users, fn user -> | ||
persist_user(user) | ||
end) | ||
persisted_users = User |> Repo.all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey @nicholalexander! your persist_user
helper returns a persisted user (with id
) so here where you're doing Enum.each
, you could instead do Enum.map
and avoid the extra call to the db with User |> Repo.all
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked at this but there was a problem with the travis user sometimes already being in the database and couldn't quite figure out how that was happening. i'm updating the persist to be an insert or find.
String.replace(name, ~r/ +/, "") |> Macro.underscore |> String.to_atom | ||
end | ||
|
||
defp user_map(users) do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do away with user_name_atom
helper, as Map
s can house string keys. This avoids the need for the helper, as well as the transformations done when building the map and accessing it. Separately, I think we should use the users email
as the key in this map, rather than the user's name, as email is unique.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i thought about that but i was afraid that would make the call sites in retro_channel_test.exs
sort of wierd that you'd have to know the email address of your mock user to use it in the tests.
also, i liked having the atom...
if anything i was thinking that we should refactor mock_user to be test_user so it's consistent with the name - or else change mock_user's name from test_user to mock_user (same difference really).
I don't feel particularly strongly so up to you!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you'd have to know the email address of your mock user to use it in the tests
Good point. What if we changed the test users' names and emails to be something semantic, like @test_user_one
, where the email is testuser@one.com
, and @test_user_two
, where the email is testuser@two.com
. We could do the same thing with the names, as I think that would make things much clearer for all folks who ending up reading/writing tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds good. i'll make that change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made the change but left the names "Test User" and "Other User" because i felt it made it easier to read the error messages on failing tests. I think it clarifies things, though. This should be good to merge now. Lemme know!
test/support/test_helpers.ex
Outdated
persist_user(user) | ||
end) | ||
persisted_users = User |> Repo.all | ||
Map.merge(user_map(persisted_users), context) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we'll want to reverse the arguments here, as we don't want any users
on context taking precedent over the users you just persisted, as they'll have the id
s we want
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool
test/support/test_helpers.ex
Outdated
end | ||
|
||
defp persist_assigned_idea(user, idea, retro) do | ||
%Participation{retro_id: retro.id, user_id: user.id} |> Repo.insert! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm... our application adds a participation
record when the user joins a retro, so I think that the participation record should be persisted in the persist_users_for_retro
helper, as it will confused anyone who doesn't have intimate knowledge of the system would be confused as to why a participation is being created as an implicit pre-req to the action item being assigned
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💯
@@ -87,4 +92,33 @@ defmodule RetroIdeaRealtimeUpdateTest do | |||
assert String.contains?(action_items_list_text, "let's do the thing! (Test User)") | |||
end | |||
end | |||
|
|||
describe "when an action-item is reassigned" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test language here can be made a clearer: "when an action item is assigned"-> "it can be reassigned to another user"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
clearer test language. insert_or_find behavior use map to avoid database query switch context argument order for map.
Description of Change(s) Introduced:
An e2e test which exercises reassigning an action item from an initial user to another user. This uses three new test helpers,
persist_other_user_for_retro
,assign_idea
, andset_participation
to get the initial state correct. It includes a first test to verify the action item is present and assigned to Other User (the non primary test user). It then exercises the idea edit form and checks that it has been reassigned.This also sets up a new
other_user
object in the test config.It might make sense to clean up some of the helpers to generalize the
persist_user_for_retro
but wasn't sure how I'd do that - still figuring out thecontext
. Also, didn't update the tags on this test as I wasn't sure how you might want that set.refactored with @laumontemayor
Relevant github Issue:
Resolves #366
Thanks!