1
0
mirror of https://github.com/jcwimer/wrestlingApp synced 2026-04-02 21:24:25 +00:00
Files
wrestlingdev.com/test/integration/tournament_job_status_test.rb

71 lines
2.3 KiB
Ruby

require "test_helper"
class TournamentJobStatusIntegrationTest < ActionDispatch::IntegrationTest
include Devise::Test::IntegrationHelpers
setup do
@tournament = tournaments(:one)
@user = users(:admin) # Assuming an admin user exists in your fixtures
@running_job = tournament_job_statuses(:running_job)
@errored_job = tournament_job_statuses(:errored_job)
sign_in @user
end
test "tournament director sees active jobs on tournament show page" do
get tournament_path(@tournament)
assert_response :success
# Should display the running job but not the errored job
assert_match @running_job.job_name, response.body
assert_match "Background Jobs In Progress", response.body
assert_no_match @errored_job.job_name, response.body
end
test "tournament director does not see job section when no active jobs" do
# Delete all active jobs
TournamentJobStatus.where.not(status: "Errored").destroy_all
get tournament_path(@tournament)
assert_response :success
# Should not display the job section
assert_no_match "Background Jobs In Progress", response.body
end
test "non-director user does not see job information" do
sign_out @user
@regular_user = users(:one) # Assuming a regular user exists in fixtures
sign_in @regular_user
# Assuming regular users don't have permission to manage the tournament
get tournament_path(@tournament)
assert_response :success
# Should not display job information
assert_no_match "Background Jobs In Progress", response.body
end
test "jobs get cleaned up after successful completion" do
# Test that CalculateSchoolScoreJob removes job status when complete
school = schools(:one)
job_name = "Calculating team score for #{school.name}"
# Create a job status for this school
TournamentJobStatus.create!(
tournament: @tournament,
job_name: job_name,
status: "Running"
)
# Verify the job exists
assert TournamentJobStatus.exists?(tournament: @tournament, job_name: job_name)
# Run the job synchronously
CalculateSchoolScoreJob.perform_sync(school)
# Verify the job status was removed
assert_not TournamentJobStatus.exists?(tournament: @tournament, job_name: job_name)
end
end