tabletop-companion/test/controllers/table_invites_controller_te...

75 lines
2.2 KiB
Ruby

# frozen_string_literal: true
require "test_helper"
class TableInviteInvitesControllerTest < ActionDispatch::IntegrationTest
test "should get index" do
sign_in users(:trevor)
get table_invites_url
assert_response :success
end
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
test "can invite a non-user to join" do
sign_in users(:trevor)
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
end
assert_redirected_to table_path(tables(:table))
end
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
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