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

52 lines
1.5 KiB
Ruby

# frozen_string_literal: true
require "test_helper"
class TableInviteInvitesControllerTest < ActionDispatch::IntegrationTest
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 "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