Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/controllers/test_executions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,11 @@ def render_multi_measure_stream
end

def render_measure_tests_table_row_stream
task = Task.find(@task.id)
render turbo_stream: turbo_stream.replace(
view_context.measure_tests_table_row_wrapper_id(@task),
view_context.measure_tests_table_row_wrapper_id(task),
partial: 'products/measure_tests_table_row',
locals: { task: @task,
locals: { task: task,
has_eh_tests: @product.eh_tests?,
has_ep_tests: @product.ep_tests?,
html_id: test_execution_param(:html_id),
Expand Down
8 changes: 8 additions & 0 deletions app/models/test_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ class TestExecution
belongs_to :task, touch: true

before_save :verify_artifact
before_create :mark_task_latest_execution
after_save :refresh_product_test_status
after_destroy :refresh_product_test_status

def verify_artifact
artifact&.save
end

def mark_task_latest_execution
return unless task

task.latest_test_execution_id = id.to_s
task.set(latest_test_execution_id: id.to_s) if task.persisted?
end

def refresh_product_test_status
task&.refresh_product_test_status
end
Expand Down
43 changes: 43 additions & 0 deletions test/controllers/test_executions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,36 @@ def setup_c4
end
end

test 'turbo create shows c2 and c3 results in progress after rerun' do
sign_in User.find(ADMIN)
@first_product.update!(c3_test: true)
c3_task = @first_test.tasks.create!({}, C3Cat3Task)
@first_c2_task.test_executions.create!(state: :passed, user: @vendor_user)
c3_task.test_executions.create!(state: :passed, user: @vendor_user)

post :create, params: turbo_create_params(@first_c2_task, xml_upload, include_c1: false)

assert_response :success
assert_equal 2, response.body.scan('In Progress').count
end

test 'turbo create shows c1 and c3 results in progress after rerun' do
sign_in User.find(ADMIN)
measure_ids = ['AE65090C-EB1F-11E7-8C3F-9A214CF093AE']
product = @vendor.products.create!(name: "my product #{rand}", c1_test: true, c3_test: true, bundle_id: @bundle_id,
measure_ids:)
test = product.product_tests.create!({ name: "my measure test #{rand}", measure_ids: }, MeasureTest)
c1_task = test.tasks.c1_task
c3_task = test.tasks.c3_cat1_task
c1_task.test_executions.create!(state: :passed, user: @vendor_user)
c3_task.test_executions.create!(state: :passed, user: @vendor_user)

post :create, params: turbo_create_params(c1_task, zip_upload, include_c1: true)

assert_response :success
assert_equal 2, response.body.scan('In Progress').count
end

# need negative tests for user that does not have owner or vendor access
test 'should be able to restrict access to create unauthorized users ' do
C1Task.any_instance.stubs(:validators).returns([])
Expand Down Expand Up @@ -588,6 +618,19 @@ def xml_upload
Rack::Test::UploadedFile.new(xmlfile, 'application/xml')
end

def turbo_create_params(task, upload, include_c1:)
{
format: :turbo_stream,
task_id: task.id,
test_execution: {
results: upload,
html_id: include_c1 ? 'c1_c3_qrda_i' : 'c2_c3_qrda_iii',
include_c1: include_c1.to_s,
product_page_url: vendor_product_path(task.product_test.product.vendor, task.product_test.product)
}
}
end

def accepted_execution_show_attributes
%w[state created_at]
end
Expand Down
10 changes: 10 additions & 0 deletions test/models/c3_cat1_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ def test_task_should_include_c3_cat1_validators
assert(@task.validators.any? { |v| v.is_a?(MeasurePeriodValidator) })
end

def test_new_execution_updates_cached_status_when_previous_execution_was_latest
@task.test_executions.create!(state: :passed, user: @user)
assert_equal 'passing', @test.reload.task_status('C3Cat1Task')

new_execution = @task.test_executions.create!(user: @user)

assert_equal new_execution.id.to_s, @task.reload.latest_test_execution_id
assert_equal 'pending', @test.reload.task_status('C3Cat1Task')
end

def test_task_should_not_error_when_extra_record_included
c1_task = @test.tasks.create!({}, C1Task)
zip = File.new(Rails.root.join('test', 'fixtures', 'qrda', 'cat_I', 'ep_qrda_test_too_many_files.zip'))
Expand Down
10 changes: 10 additions & 0 deletions test/models/c3_cat3_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@ def test_task_should_include_c3_cat3_validators
assert(@task.validators.any? { |v| v.is_a?(MeasurePeriodValidator) })
end

def test_new_execution_updates_cached_status_when_previous_execution_was_latest
@task.test_executions.create!(state: :passed, user: @user)
assert_equal 'passing', @test.reload.task_status('C3Cat3Task')

new_execution = @task.test_executions.create!(user: @user)

assert_equal new_execution.id.to_s, @task.reload.latest_test_execution_id
assert_equal 'pending', @test.reload.task_status('C3Cat3Task')
end

def test_task_good_results_should_pass
c2_task = @test.tasks.create({ expected_results: @test.expected_results }, C2Task)
xml = Tempfile.new(['good_results_debug_file', '.xml'])
Expand Down
Loading