diff --git a/app/controllers/test_executions_controller.rb b/app/controllers/test_executions_controller.rb index 5a5be443e..9bb40b180 100644 --- a/app/controllers/test_executions_controller.rb +++ b/app/controllers/test_executions_controller.rb @@ -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), diff --git a/app/models/test_execution.rb b/app/models/test_execution.rb index 6fb17ee36..c2d5aef91 100644 --- a/app/models/test_execution.rb +++ b/app/models/test_execution.rb @@ -23,6 +23,7 @@ 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 @@ -30,6 +31,13 @@ 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 diff --git a/test/controllers/test_executions_controller_test.rb b/test/controllers/test_executions_controller_test.rb index b416b0fc3..93e47892f 100644 --- a/test/controllers/test_executions_controller_test.rb +++ b/test/controllers/test_executions_controller_test.rb @@ -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([]) @@ -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 diff --git a/test/models/c3_cat1_task_test.rb b/test/models/c3_cat1_task_test.rb index 237b775a6..557b669ff 100644 --- a/test/models/c3_cat1_task_test.rb +++ b/test/models/c3_cat1_task_test.rb @@ -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')) diff --git a/test/models/c3_cat3_task_test.rb b/test/models/c3_cat3_task_test.rb index ea88c073f..6b1e70d43 100644 --- a/test/models/c3_cat3_task_test.rb +++ b/test/models/c3_cat3_task_test.rb @@ -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'])