2024-05-29 14:24:18 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class TableInviteInvitesControllerTest < ActionDispatch::IntegrationTest
|
2024-05-29 15:47:31 +00:00
|
|
|
test "should get index" do
|
|
|
|
sign_in users(:trevor)
|
|
|
|
get table_invites_url
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
2024-05-29 14:24:18 +00:00
|
|
|
test "only a table owner can invite players" do
|
|
|
|
sign_in users(:trevor)
|
|
|
|
get new_table_table_invite_url(tables(:gimlis_table))
|
|
|
|
assert_response :not_found
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should get new" do
|
|
|
|
sign_in users(:trevor)
|
|
|
|
get new_table_table_invite_url(tables(:table))
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should get edit" do
|
|
|
|
sign_in users(:frodo)
|
|
|
|
get edit_table_invite_url(table_invites(:unaccepted))
|
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should create table_invite" do
|
|
|
|
sign_in users(:trevor)
|
|
|
|
assert_changes("TableInvite.count", +1) do
|
|
|
|
post(table_table_invites_url(tables(:table)), params: { table_invite: { email: "uninvited_user@example.com" } })
|
|
|
|
end
|
|
|
|
assert_redirected_to table_path(tables(:table))
|
|
|
|
end
|
|
|
|
|
2024-05-30 07:16:06 +00:00
|
|
|
test "can invite a non-user to join" do
|
2024-05-29 15:47:31 +00:00
|
|
|
sign_in users(:trevor)
|
2024-05-30 07:16:06 +00:00
|
|
|
assert_changes("TableInvite.count", +1) do
|
|
|
|
assert_emails(+1) do
|
|
|
|
post(table_table_invites_url(tables(:table)), params: { table_invite: { email: "not_a_member@example.com" } })
|
|
|
|
end
|
2024-05-29 15:47:31 +00:00
|
|
|
end
|
2024-05-30 07:16:06 +00:00
|
|
|
assert_redirected_to table_path(tables(:table))
|
2024-05-29 15:47:31 +00:00
|
|
|
end
|
2024-05-30 07:16:06 +00:00
|
|
|
|
2024-05-29 15:47:31 +00:00
|
|
|
test "should email user when an invite is created" do
|
|
|
|
sign_in users(:trevor)
|
|
|
|
assert_emails(+1) do
|
|
|
|
post(table_table_invites_url(tables(:table)), params: { table_invite: { email: "uninvited_user@example.com" } })
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-05-29 14:24:18 +00:00
|
|
|
test "should accept table_invite" do
|
|
|
|
sign_in users(:frodo)
|
|
|
|
invite = table_invites(:unaccepted)
|
|
|
|
assert_nil invite.accepted_at
|
|
|
|
patch table_invite_url(invite), params: { accept: true }
|
|
|
|
assert_redirected_to table_path(invite.table)
|
|
|
|
invite.reload
|
|
|
|
assert_not_nil invite.accepted_at
|
|
|
|
end
|
|
|
|
|
|
|
|
test "should decline table_invite" do
|
|
|
|
sign_in users(:frodo)
|
|
|
|
invite = table_invites(:unaccepted)
|
|
|
|
assert_nil invite.accepted_at
|
|
|
|
patch table_invite_url(invite), params: { decline: true }
|
|
|
|
assert_redirected_to root_path
|
|
|
|
invite.reload
|
|
|
|
assert_not_nil invite.declined_at
|
|
|
|
end
|
|
|
|
end
|