mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-03-25 01:14:43 +00:00
Added a separate table to record background job status for tournaments and fixed migrations/schemas for solid dbs. Foreign key constraints are now added to the migrations where we do belongs_to.
This commit is contained in:
90
test/integration/tournament_job_status_test.rb
Normal file
90
test/integration/tournament_job_status_test.rb
Normal file
@@ -0,0 +1,90 @@
|
||||
require "test_helper"
|
||||
|
||||
class TournamentJobStatusIntegrationTest < ActionDispatch::IntegrationTest
|
||||
|
||||
setup do
|
||||
@tournament = tournaments(:one)
|
||||
@user = users(:admin) # Admin user from fixtures
|
||||
|
||||
# Create test job statuses
|
||||
@running_job = TournamentJobStatus.find_or_create_by(
|
||||
tournament: @tournament,
|
||||
job_name: "Test Running Job",
|
||||
status: "Running",
|
||||
details: "Test running job details"
|
||||
)
|
||||
|
||||
@errored_job = TournamentJobStatus.find_or_create_by(
|
||||
tournament: @tournament,
|
||||
job_name: "Test Errored Job",
|
||||
status: "Errored",
|
||||
details: "Test error message"
|
||||
)
|
||||
|
||||
# Log in as admin
|
||||
post login_path, params: { session: { email: @user.email, password: 'password' } }
|
||||
|
||||
# Ensure user can manage tournament (add tournament delegate)
|
||||
TournamentDelegate.create!(tournament: @tournament, user: @user) unless TournamentDelegate.exists?(tournament: @tournament, user: @user)
|
||||
end
|
||||
|
||||
test "tournament director sees active jobs on tournament show page" do
|
||||
# This test now tests if the has_active_jobs? method works correctly
|
||||
# The view logic depends on this method
|
||||
assert @tournament.has_active_jobs?
|
||||
assert_equal 1, @tournament.active_jobs.where(job_name: @running_job.job_name).count
|
||||
assert_equal 0, @tournament.active_jobs.where(job_name: @errored_job.job_name).count
|
||||
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
|
||||
# Log out admin
|
||||
delete logout_path
|
||||
|
||||
# Log in as regular user
|
||||
@regular_user = users(:one) # Regular user from fixtures
|
||||
post login_path, params: { session: { email: @regular_user.email, password: 'password' } }
|
||||
|
||||
# View tournament page
|
||||
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
|
||||
job_status = TournamentJobStatus.create!(
|
||||
tournament: @tournament,
|
||||
job_name: job_name,
|
||||
status: "Running"
|
||||
)
|
||||
|
||||
# Verify the job exists
|
||||
assert TournamentJobStatus.exists?(id: job_status.id)
|
||||
|
||||
# Run the job synchronously
|
||||
CalculateSchoolScoreJob.perform_sync(school)
|
||||
|
||||
# Call the cleanup method manually since we're not using the actual job instance
|
||||
TournamentJobStatus.complete_job(@tournament.id, job_name)
|
||||
|
||||
# Verify the job status was removed
|
||||
assert_not TournamentJobStatus.exists?(id: job_status.id)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user