-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
120 additions
and
11 deletions.
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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
require "test_helper" | ||
|
||
class InvitationsControllerTest < ActionDispatch::IntegrationTest | ||
setup do | ||
sign_in @user = users(:family_admin) | ||
@invitation = invitations(:one) | ||
end | ||
|
||
test "should get new" do | ||
get new_invitation_url | ||
assert_response :success | ||
end | ||
|
||
test "should create invitation for member" do | ||
assert_difference("Invitation.count") do | ||
assert_enqueued_with(job: ActionMailer::MailDeliveryJob) do | ||
post invitations_url, params: { | ||
invitation: { | ||
email: "[email protected]", | ||
role: "member" | ||
} | ||
} | ||
end | ||
end | ||
|
||
invitation = Invitation.order(created_at: :desc).first | ||
assert_equal "member", invitation.role | ||
assert_equal @user, invitation.inviter | ||
assert_equal "[email protected]", invitation.email | ||
assert_redirected_to settings_profile_path | ||
assert_equal I18n.t("invitations.create.success"), flash[:notice] | ||
end | ||
|
||
test "non-admin cannot create admin invitation" do | ||
sign_in users(:family_member) | ||
|
||
assert_difference("Invitation.count") do | ||
post invitations_url, params: { | ||
invitation: { | ||
email: "[email protected]", | ||
role: "admin" | ||
} | ||
} | ||
end | ||
|
||
invitation = Invitation.last | ||
assert_equal "member", invitation.role # Role should be downgraded to member | ||
end | ||
|
||
test "admin can create admin invitation" do | ||
assert_difference("Invitation.count") do | ||
post invitations_url, params: { | ||
invitation: { | ||
email: "[email protected]", | ||
role: "admin" | ||
} | ||
} | ||
end | ||
|
||
invitation = Invitation.last | ||
assert_equal "admin", invitation.role | ||
assert_equal @user.family, invitation.family | ||
assert_equal @user, invitation.inviter | ||
end | ||
|
||
test "should handle invalid invitation creation" do | ||
assert_no_difference("Invitation.count") do | ||
post invitations_url, params: { | ||
invitation: { | ||
email: "", | ||
role: "member" | ||
} | ||
} | ||
end | ||
|
||
assert_redirected_to settings_profile_path | ||
assert_equal I18n.t("invitations.create.failure"), flash[:alert] | ||
end | ||
|
||
test "should accept invitation and redirect to registration" do | ||
get accept_invitation_url(@invitation.token) | ||
assert_redirected_to new_registration_path(invitation: @invitation.token) | ||
end | ||
|
||
test "should not accept invalid invitation token" do | ||
get accept_invitation_url("invalid-token") | ||
assert_response :not_found | ||
end | ||
end |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
one: | ||
email: "[email protected]" | ||
token: "valid-token-123" | ||
role: "member" | ||
inviter: family_admin | ||
family: dylan_family | ||
created_at: <%= Time.current %> | ||
updated_at: <%= Time.current %> | ||
expires_at: <%= 3.days.from_now %> | ||
|
||
two: | ||
email: "[email protected]" | ||
token: "valid-token-456" | ||
role: "admin" | ||
inviter: family_admin | ||
family: dylan_family | ||
created_at: <%= Time.current %> | ||
updated_at: <%= Time.current %> | ||
expires_at: <%= 3.days.from_now %> |