From a7bf6ee5021d0dbd792dff3e1cce5c40b6071569 Mon Sep 17 00:00:00 2001 From: Kenneth Bogner Date: Thu, 15 Feb 2024 01:30:01 -0500 Subject: [PATCH] Add integration test for matchmaking groups controller --- .../matchmaking_groups_controller_test.rb | 48 +++++++++++++++++++ test/models/matchmaking_group_test.rb | 15 ------ test/support/database_test_helper.rb | 23 +++++++++ test/test_helper.rb | 4 ++ 4 files changed, 75 insertions(+), 15 deletions(-) create mode 100644 test/controllers/matchmaking_groups_controller_test.rb diff --git a/test/controllers/matchmaking_groups_controller_test.rb b/test/controllers/matchmaking_groups_controller_test.rb new file mode 100644 index 0000000..018233f --- /dev/null +++ b/test/controllers/matchmaking_groups_controller_test.rb @@ -0,0 +1,48 @@ +require "test_helper" + +class MatchmakingGroupsControllerTest < ActionDispatch::IntegrationTest + setup do + @matchmaking_group = create_matchmaking_group(name: "test") + @user = create_user + + sign_in_as(@user) + end + + test "should get index" do + get matchmaking_groups_url + assert_response :success + end + + test "should get new" do + get new_matchmaking_group_url + assert_response :success + end + + test "should create matchmaking_group" do + assert_difference("MatchmakingGroup.count") do + post matchmaking_groups_url, params: { + matchmaking_group: {name: "New Group", slack_channel_name: "test-channel", schedule: "daily", target_size: 2, is_active: true} + } + end + + assert_redirected_to matchmaking_groups_url + end + + test "should get edit" do + get edit_matchmaking_group_url(@matchmaking_group) + assert_response :success + end + + test "should update matchmaking_group" do + patch matchmaking_group_url(@matchmaking_group), params: {matchmaking_group: {name: "Updated Group"}} + assert_redirected_to matchmaking_groups_url + end + + test "should destroy matchmaking_group" do + assert_difference("MatchmakingGroup.count", -1) do + delete matchmaking_group_url(@matchmaking_group) + end + + assert_redirected_to matchmaking_groups_url + end +end diff --git a/test/models/matchmaking_group_test.rb b/test/models/matchmaking_group_test.rb index 78f5b2d..556cb65 100644 --- a/test/models/matchmaking_group_test.rb +++ b/test/models/matchmaking_group_test.rb @@ -62,19 +62,4 @@ class MatchmakingGroupTest < ActiveSupport::TestCase assert_not @subject.name_exists?("test") end end - - private - - def create_matchmaking_group(attrs = {}) - default_attrs = { - name: "test", - slack_channel_name: "test-channel", - schedule: "daily", - target_size: 2, - is_active: true, - slack_user_id: "42" - } - - @subject.create(default_attrs.merge(attrs)) - end end diff --git a/test/support/database_test_helper.rb b/test/support/database_test_helper.rb index d1dd137..7e8a674 100644 --- a/test/support/database_test_helper.rb +++ b/test/support/database_test_helper.rb @@ -7,4 +7,27 @@ def create_historical_match(grouping:, members:, pending_notifications: []) pending_notifications: pending_notifications ) end + + def create_matchmaking_group(name:, **attrs) + default_attrs = { + slack_channel_name: "test-channel", + schedule: "daily", + target_size: 2, + is_active: true, + slack_user_id: "42" + } + + MatchmakingGroup.create(default_attrs.merge(attrs).merge(name: name)) + end + + def create_user(attrs = {}) + slack_user_id = attrs[:slack_user_id] || "USER" + SlackUserProfile.create(slack_user_id: slack_user_id) + + User.create( + auth_token: attrs[:auth_token] || SecureRandom.uuid, + auth_token_expires_at: attrs[:auth_token_expires_at] || 1.day.from_now, + slack_user_id: slack_user_id + ) + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 9928b46..0fdee94 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -29,4 +29,8 @@ class ActiveSupport::TestCase Mocktail.reset Timecop.return end + + def sign_in_as(user) + get "/auth/verify", params: {token: user.auth_token} + end end