Skip to content

Commit

Permalink
Add integration test for matchmaking groups controller
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxagon committed Feb 15, 2024
1 parent a3cae0d commit a7bf6ee
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 15 deletions.
48 changes: 48 additions & 0 deletions test/controllers/matchmaking_groups_controller_test.rb
Original file line number Diff line number Diff line change
@@ -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
15 changes: 0 additions & 15 deletions test/models/matchmaking_group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 23 additions & 0 deletions test/support/database_test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit a7bf6ee

Please sign in to comment.