mirror of
https://github.com/jcwimer/wrestlingApp
synced 2026-04-02 21:24:25 +00:00
71 lines
2.2 KiB
Ruby
71 lines
2.2 KiB
Ruby
require "test_helper"
|
|
|
|
class TournamentJobStatusTest < ActiveSupport::TestCase
|
|
setup do
|
|
@tournament = tournaments(:one)
|
|
@job_status = tournament_job_statuses(:running_job)
|
|
end
|
|
|
|
test "should be valid with required fields" do
|
|
job_status = TournamentJobStatus.new(
|
|
tournament: @tournament,
|
|
job_name: "Test Job",
|
|
status: "Queued"
|
|
)
|
|
assert job_status.valid?
|
|
end
|
|
|
|
test "should require tournament" do
|
|
@job_status.tournament = nil
|
|
assert_not @job_status.valid?
|
|
end
|
|
|
|
test "should require job_name" do
|
|
@job_status.job_name = nil
|
|
assert_not @job_status.valid?
|
|
end
|
|
|
|
test "should require status" do
|
|
@job_status.status = nil
|
|
assert_not @job_status.valid?
|
|
end
|
|
|
|
test "status should be one of the allowed values" do
|
|
@job_status.status = "Invalid Status"
|
|
assert_not @job_status.valid?
|
|
|
|
@job_status.status = "Queued"
|
|
assert @job_status.valid?
|
|
|
|
@job_status.status = "Running"
|
|
assert @job_status.valid?
|
|
|
|
@job_status.status = "Errored"
|
|
assert @job_status.valid?
|
|
end
|
|
|
|
test "active scope should exclude errored jobs" do
|
|
active_jobs = TournamentJobStatus.active
|
|
assert_includes active_jobs, tournament_job_statuses(:queued_job)
|
|
assert_includes active_jobs, tournament_job_statuses(:running_job)
|
|
assert_not_includes active_jobs, tournament_job_statuses(:errored_job)
|
|
end
|
|
|
|
test "for_tournament should return only jobs for a specific tournament" do
|
|
tournament_one_jobs = TournamentJobStatus.for_tournament(@tournament)
|
|
assert_equal 3, tournament_one_jobs.count
|
|
assert_includes tournament_one_jobs, tournament_job_statuses(:queued_job)
|
|
assert_includes tournament_one_jobs, tournament_job_statuses(:running_job)
|
|
assert_includes tournament_one_jobs, tournament_job_statuses(:errored_job)
|
|
assert_not_includes tournament_one_jobs, tournament_job_statuses(:another_tournament_job)
|
|
end
|
|
|
|
test "complete_job should remove jobs with matching tournament_id and job_name" do
|
|
assert_difference 'TournamentJobStatus.count', -1 do
|
|
TournamentJobStatus.complete_job(@tournament.id, "Test Running Job")
|
|
end
|
|
|
|
assert_nil TournamentJobStatus.find_by(id: @job_status.id)
|
|
end
|
|
end
|