use assert_recieve

This commit is contained in:
FloatingGhost 2023-08-02 18:02:47 +01:00
parent 9f2bd3f944
commit df573c898a
8 changed files with 56 additions and 56 deletions

View file

@ -21,7 +21,7 @@ test "input" do
send(self(), {:mix_shell_input, :prompt, "Yes"}) send(self(), {:mix_shell_input, :prompt, "Yes"})
answer = shell_prompt("Do you want this?") answer = shell_prompt("Do you want this?")
assert_received {:mix_shell, :prompt, [message]} assert_receive {:mix_shell, :prompt, [message]}
assert message =~ "Do you want this?" assert message =~ "Do you want this?"
assert answer == "Yes" assert answer == "Yes"
end end
@ -31,7 +31,7 @@ test "with defval" do
answer = shell_prompt("Do you want this?", "defval") answer = shell_prompt("Do you want this?", "defval")
assert_received {:mix_shell, :prompt, [message]} assert_receive {:mix_shell, :prompt, [message]}
assert message =~ "Do you want this? [defval]" assert message =~ "Do you want this? [defval]"
assert answer == "defval" assert answer == "defval"
end end

View file

@ -58,7 +58,7 @@ test "config migration refused when deprecated settings are found" do
MixTask.migrate_to_db("test/fixtures/config/temp.secret.exs") MixTask.migrate_to_db("test/fixtures/config/temp.secret.exs")
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ assert message =~
"Migration is not allowed until all deprecation warnings have been resolved." "Migration is not allowed until all deprecation warnings have been resolved."

View file

@ -24,15 +24,15 @@ test "uploads migrated" do
store: fn %Upload{name: _file, path: _path}, _opts -> {:ok, %{}} end do store: fn %Upload{name: _file, path: _path}, _opts -> {:ok, %{}} end do
Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "S3"]) Mix.Tasks.Pleroma.Uploads.run(["migrate_local", "S3"])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "Migrating files from local" assert message =~ "Migrating files from local"
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert %{"total_count" => total_count} = assert %{"total_count" => total_count} =
Regex.named_captures(~r"^Found (?<total_count>\d+) uploads$", message) Regex.named_captures(~r"^Found (?<total_count>\d+) uploads$", message)
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
# @logevery in Mix.Tasks.Pleroma.Uploads # @logevery in Mix.Tasks.Pleroma.Uploads
count = count =

View file

@ -52,13 +52,13 @@ test "user is created" do
"--admin" "--admin"
]) ])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "user will be created" assert message =~ "user will be created"
assert_received {:mix_shell, :prompt, [message]} assert_receive {:mix_shell, :prompt, [message]}
assert message =~ "Continue" assert message =~ "Continue"
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "created" assert message =~ "created"
user = User.get_cached_by_nickname(unsaved.nickname) user = User.get_cached_by_nickname(unsaved.nickname)
@ -77,13 +77,13 @@ test "user is not created" do
Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email]) Mix.Tasks.Pleroma.User.run(["new", unsaved.nickname, unsaved.email])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "user will be created" assert message =~ "user will be created"
assert_received {:mix_shell, :prompt, [message]} assert_receive {:mix_shell, :prompt, [message]}
assert message =~ "Continue" assert message =~ "Continue"
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "will not be created" assert message =~ "will not be created"
refute User.get_cached_by_nickname(unsaved.nickname) refute User.get_cached_by_nickname(unsaved.nickname)
@ -100,7 +100,7 @@ test "user is deleted" do
Mix.Tasks.Pleroma.User.run(["rm", user.nickname]) Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ " deleted" assert message =~ " deleted"
assert %{is_active: false} = User.get_by_nickname(user.nickname) assert %{is_active: false} = User.get_by_nickname(user.nickname)
@ -138,7 +138,7 @@ test "a remote user's create activity is deleted when the object has been pruned
Mix.Tasks.Pleroma.User.run(["rm", user.nickname]) Mix.Tasks.Pleroma.User.run(["rm", user.nickname])
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ " deleted" assert message =~ " deleted"
assert %{is_active: false} = User.get_by_nickname(user.nickname) assert %{is_active: false} = User.get_by_nickname(user.nickname)
@ -152,7 +152,7 @@ test "a remote user's create activity is deleted when the object has been pruned
test "no user to delete" do test "no user to delete" do
Mix.Tasks.Pleroma.User.run(["rm", "nonexistent"]) Mix.Tasks.Pleroma.User.run(["rm", "nonexistent"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No local user" assert message =~ "No local user"
end end
end end
@ -169,7 +169,7 @@ test "active user is deactivated and unsubscribed" do
Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname]) Mix.Tasks.Pleroma.User.run(["deactivate", user.nickname])
# Note that the task has delay :timer.sleep(500) # Note that the task has delay :timer.sleep(500)
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == assert message ==
"Successfully deactivated #{user.nickname} and unsubscribed all local followers" "Successfully deactivated #{user.nickname} and unsubscribed all local followers"
@ -183,7 +183,7 @@ test "user is deactivated" do
%{id: id, nickname: nickname} = insert(:user, is_active: false) %{id: id, nickname: nickname} = insert(:user, is_active: false)
assert :ok = Mix.Tasks.Pleroma.User.run(["deactivate", nickname]) assert :ok = Mix.Tasks.Pleroma.User.run(["deactivate", nickname])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "User #{nickname} already deactivated" assert message == "User #{nickname} already deactivated"
user = Repo.get(User, id) user = Repo.get(User, id)
@ -193,7 +193,7 @@ test "user is deactivated" do
test "no user to deactivate" do test "no user to deactivate" do
Mix.Tasks.Pleroma.User.run(["deactivate", "nonexistent"]) Mix.Tasks.Pleroma.User.run(["deactivate", "nonexistent"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No user" assert message =~ "No user"
end end
end end
@ -211,16 +211,16 @@ test "All statuses set" do
"--moderator" "--moderator"
]) ])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* true/ assert message =~ ~r/Admin status .* true/
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ ~r/Confirmation status.* true/ assert message =~ ~r/Confirmation status.* true/
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ ~r/Locked status .* true/ assert message =~ ~r/Locked status .* true/
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ ~r/Moderator status .* true/ assert message =~ ~r/Moderator status .* true/
user = User.get_cached_by_nickname(user.nickname) user = User.get_cached_by_nickname(user.nickname)
@ -248,16 +248,16 @@ test "All statuses unset" do
"--no-moderator" "--no-moderator"
]) ])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ ~r/Admin status .* false/ assert message =~ ~r/Admin status .* false/
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ ~r/Confirmation status.* false/ assert message =~ ~r/Confirmation status.* false/
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ ~r/Locked status .* false/ assert message =~ ~r/Locked status .* false/
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ ~r/Moderator status .* false/ assert message =~ ~r/Moderator status .* false/
user = User.get_cached_by_nickname(user.nickname) user = User.get_cached_by_nickname(user.nickname)
@ -270,7 +270,7 @@ test "All statuses unset" do
test "no user to set status" do test "no user to set status" do
Mix.Tasks.Pleroma.User.run(["set", "nonexistent", "--moderator"]) Mix.Tasks.Pleroma.User.run(["set", "nonexistent", "--moderator"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No local user" assert message =~ "No local user"
end end
end end
@ -283,14 +283,14 @@ test "password reset token is generated" do
Mix.Tasks.Pleroma.User.run(["reset_password", user.nickname]) Mix.Tasks.Pleroma.User.run(["reset_password", user.nickname])
end) =~ "URL:" end) =~ "URL:"
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "Generated" assert message =~ "Generated"
end end
test "no user to reset password" do test "no user to reset password" do
Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"]) Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No local user" assert message =~ "No local user"
end end
end end
@ -307,7 +307,7 @@ test "disables MFA" do
Mix.Tasks.Pleroma.User.run(["reset_mfa", user.nickname]) Mix.Tasks.Pleroma.User.run(["reset_mfa", user.nickname])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "Multi-Factor Authentication disabled for #{user.nickname}" assert message == "Multi-Factor Authentication disabled for #{user.nickname}"
assert %{enabled: false, totp: false} == assert %{enabled: false, totp: false} ==
@ -319,7 +319,7 @@ test "disables MFA" do
test "no user to reset MFA" do test "no user to reset MFA" do
Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"]) Mix.Tasks.Pleroma.User.run(["reset_password", "nonexistent"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No local user" assert message =~ "No local user"
end end
end end
@ -330,7 +330,7 @@ test "invite token is generated" do
Mix.Tasks.Pleroma.User.run(["invite"]) Mix.Tasks.Pleroma.User.run(["invite"])
end) =~ "http" end) =~ "http"
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "Generated user invite token one time" assert message =~ "Generated user invite token one time"
end end
@ -343,7 +343,7 @@ test "token is generated with expires_at" do
]) ])
end) end)
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "Generated user invite token date limited" assert message =~ "Generated user invite token date limited"
end end
@ -356,7 +356,7 @@ test "token is generated with max use" do
]) ])
end) end)
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "Generated user invite token reusable" assert message =~ "Generated user invite token reusable"
end end
@ -371,7 +371,7 @@ test "token is generated with max use and expires date" do
]) ])
end) end)
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "Generated user invite token reusable date limited" assert message =~ "Generated user invite token reusable date limited"
end end
end end
@ -390,9 +390,9 @@ test "invites are listed" do
# end) # end)
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert_received {:mix_shell, :info, [message2]} assert_receive {:mix_shell, :info, [message2]}
assert_received {:mix_shell, :info, [message3]} assert_receive {:mix_shell, :info, [message3]}
assert message =~ "Invites list:" assert message =~ "Invites list:"
assert message2 =~ invite.invite_type assert message2 =~ invite.invite_type
assert message3 =~ invite2.invite_type assert message3 =~ invite2.invite_type
@ -410,7 +410,7 @@ test "invite is revoked" do
]) ])
end) end)
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message =~ "Invite for token #{invite.token} was revoked." assert message =~ "Invite for token #{invite.token} was revoked."
end end
end end
@ -420,14 +420,14 @@ test "activities are deleted" do
%{nickname: nickname} = insert(:user) %{nickname: nickname} = insert(:user)
assert :ok == Mix.Tasks.Pleroma.User.run(["delete_activities", nickname]) assert :ok == Mix.Tasks.Pleroma.User.run(["delete_activities", nickname])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "User #{nickname} statuses deleted." assert message == "User #{nickname} statuses deleted."
end end
test "it prints an error message when user is not exist" do test "it prints an error message when user is not exist" do
Mix.Tasks.Pleroma.User.run(["delete_activities", "foo"]) Mix.Tasks.Pleroma.User.run(["delete_activities", "foo"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No local user" assert message =~ "No local user"
end end
end end
@ -437,7 +437,7 @@ test "user is confirmed" do
%{id: id, nickname: nickname} = insert(:user, is_confirmed: true) %{id: id, nickname: nickname} = insert(:user, is_confirmed: true)
assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname]) assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "#{nickname} doesn't need confirmation." assert message == "#{nickname} doesn't need confirmation."
user = Repo.get(User, id) user = Repo.get(User, id)
@ -450,7 +450,7 @@ test "user is not confirmed" do
insert(:user, is_confirmed: false, confirmation_token: "some token") insert(:user, is_confirmed: false, confirmation_token: "some token")
assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname]) assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "#{nickname} doesn't need confirmation." assert message == "#{nickname} doesn't need confirmation."
user = Repo.get(User, id) user = Repo.get(User, id)
@ -461,7 +461,7 @@ test "user is not confirmed" do
test "it prints an error message when user is not exist" do test "it prints an error message when user is not exist" do
Mix.Tasks.Pleroma.User.run(["confirm", "foo"]) Mix.Tasks.Pleroma.User.run(["confirm", "foo"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No local user" assert message =~ "No local user"
end end
end end
@ -471,7 +471,7 @@ test "user is activated" do
%{id: id, nickname: nickname} = insert(:user, is_active: true) %{id: id, nickname: nickname} = insert(:user, is_active: true)
assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname]) assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "User #{nickname} already activated" assert message == "User #{nickname} already activated"
user = Repo.get(User, id) user = Repo.get(User, id)
@ -482,7 +482,7 @@ test "user is not activated" do
%{id: id, nickname: nickname} = insert(:user, is_active: false) %{id: id, nickname: nickname} = insert(:user, is_active: false)
assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname]) assert :ok = Mix.Tasks.Pleroma.User.run(["activate", nickname])
assert_received {:mix_shell, :info, [message]} assert_receive {:mix_shell, :info, [message]}
assert message == "Successfully activated #{nickname}" assert message == "Successfully activated #{nickname}"
user = Repo.get(User, id) user = Repo.get(User, id)
@ -492,7 +492,7 @@ test "user is not activated" do
test "no user to activate" do test "no user to activate" do
Mix.Tasks.Pleroma.User.run(["activate", "foo"]) Mix.Tasks.Pleroma.User.run(["activate", "foo"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No user" assert message =~ "No user"
end end
end end
@ -536,7 +536,7 @@ test "it deletes all user's tokens and authorizations" do
test "it prints an error message when user is not exist" do test "it prints an error message when user is not exist" do
Mix.Tasks.Pleroma.User.run(["sign_out", "foo"]) Mix.Tasks.Pleroma.User.run(["sign_out", "foo"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "No local user" assert message =~ "No local user"
end end
end end
@ -554,7 +554,7 @@ test "it add tags to a user" do
test "it prints an error message when user is not exist" do test "it prints an error message when user is not exist" do
Mix.Tasks.Pleroma.User.run(["tag", "foo"]) Mix.Tasks.Pleroma.User.run(["tag", "foo"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "Could not change user tags" assert message =~ "Could not change user tags"
end end
end end
@ -573,7 +573,7 @@ test "it deletes tags from a user" do
test "it prints an error message when user is not exist" do test "it prints an error message when user is not exist" do
Mix.Tasks.Pleroma.User.run(["untag", "foo"]) Mix.Tasks.Pleroma.User.run(["untag", "foo"])
assert_received {:mix_shell, :error, [message]} assert_receive {:mix_shell, :error, [message]}
assert message =~ "Could not change user tags" assert message =~ "Could not change user tags"
end end
end end

View file

@ -49,7 +49,7 @@ test "with relays active, it publishes to the relay", %{
ObanHelpers.perform(all_enqueued(worker: PublisherWorker)) ObanHelpers.perform(all_enqueued(worker: PublisherWorker))
end end
assert_received :relay_publish assert_receive :relay_publish
end end
test "with relays deactivated, it does not publish to the relay", %{ test "with relays deactivated, it does not publish to the relay", %{

View file

@ -50,7 +50,7 @@ test "authorizes the existing user using LDAP credentials" do
token = Repo.get_by(Token, token: token) token = Repo.get_by(Token, token: token)
assert token.user_id == user.id assert token.user_id == user.id
assert_received :close_connection assert_receive :close_connection
end end
end end
@ -94,7 +94,7 @@ test "creates a new user after successful LDAP authorization" do
token = Repo.get_by(Token, token: token) |> Repo.preload(:user) token = Repo.get_by(Token, token: token) |> Repo.preload(:user)
assert token.user.nickname == user.nickname assert token.user.nickname == user.nickname
assert_received :close_connection assert_receive :close_connection
end end
end end
@ -129,7 +129,7 @@ test "disallow authorization for wrong LDAP credentials" do
}) })
assert %{"error" => "Invalid credentials"} = json_response(conn, 400) assert %{"error" => "Invalid credentials"} = json_response(conn, 400)
assert_received :close_connection assert_receive :close_connection
end end
end end
end end

View file

@ -39,7 +39,7 @@ test "it sends digest emails", %{user2: user2} do
# Performing job(s) enqueued at previous step # Performing job(s) enqueued at previous step
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert_received {:email, email} assert_receive {:email, email}
assert email.to == [{user2.name, user2.email}] assert email.to == [{user2.name, user2.email}]
assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}" assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
end end

View file

@ -20,7 +20,7 @@ test "it sends new users digest emails" do
NewUsersDigestWorker.perform(%Oban.Job{}) NewUsersDigestWorker.perform(%Oban.Job{})
ObanHelpers.perform_all() ObanHelpers.perform_all()
assert_received {:email, email} assert_receive {:email, email}
assert email.to == [{admin.name, admin.email}] assert email.to == [{admin.name, admin.email}]
assert email.subject == "#{Pleroma.Config.get([:instance, :name])} New Users" assert email.subject == "#{Pleroma.Config.get([:instance, :name])} New Users"