From bb885ffad592975ebc82572daf79a55949d5dca8 Mon Sep 17 00:00:00 2001 From: Eric Enns <492127+ericenns@users.noreply.github.com> Date: Wed, 18 Sep 2024 10:54:19 -0500 Subject: [PATCH] GraphQL: Use scoped context to skip queries and authorization (#765) * feat: use scoped context to skip authorization and skip unnecessary queries * chore: fix test failure and skip authorization for attachments from resolvers * chore: update samples attachments query test to use nodes instead of edges to retrieve results * chore: change attachments for sample1 in fixtures to fix inconsistent ordering on different os * chore: fix rubocop warning --- .../resolvers/project_attachments_resolver.rb | 1 + .../resolvers/project_sample_resolver.rb | 1 + .../resolvers/project_samples_resolver.rb | 2 + app/graphql/resolvers/projects_resolver.rb | 1 + .../resolvers/sample_attachments_resolver.rb | 1 + app/graphql/resolvers/samples_resolver.rb | 1 + app/graphql/types/attachment_type.rb | 4 +- app/graphql/types/project_type.rb | 4 +- app/graphql/types/sample_type.rb | 9 +- .../samples/attachments_controller_test.rb | 4 +- test/fixtures/active_storage/attachments.yml | 8 +- test/fixtures/active_storage/blobs.yml | 6 +- test/fixtures/data_exports.yml | 2 +- test/graphql/attachments_query_test.rb | 184 +++++++++--------- test/jobs/data_exports/create_job_test.rb | 8 +- test/models/attachment_test.rb | 12 +- .../attachments/create_service_test.rb | 2 +- test/system/projects/samples_test.rb | 26 +-- test/system/workflow_executions_test.rb | 4 +- 19 files changed, 143 insertions(+), 137 deletions(-) diff --git a/app/graphql/resolvers/project_attachments_resolver.rb b/app/graphql/resolvers/project_attachments_resolver.rb index a90421c75b..d32bdfdd8c 100644 --- a/app/graphql/resolvers/project_attachments_resolver.rb +++ b/app/graphql/resolvers/project_attachments_resolver.rb @@ -16,6 +16,7 @@ class ProjectAttachmentsResolver < BaseResolver alias project object def resolve(filter:, order_by:) + context.scoped_set!(:attachments_preauthorized, true) ransack_obj = project.namespace.attachments.joins(:file_blob).ransack(filter&.to_h) ransack_obj.sorts = ["#{order_by.field} #{order_by.direction}"] if order_by.present? diff --git a/app/graphql/resolvers/project_sample_resolver.rb b/app/graphql/resolvers/project_sample_resolver.rb index c7c86fc8e4..ccebdc4697 100644 --- a/app/graphql/resolvers/project_sample_resolver.rb +++ b/app/graphql/resolvers/project_sample_resolver.rb @@ -18,6 +18,7 @@ class ProjectSampleResolver < BaseResolver def resolve(args) project = Namespaces::ProjectNamespace.find_by(puid: args[:project_puid])&.project + context.scoped_set!(:project, project) if args[:sample_puid] Sample.find_by(puid: args[:sample_puid], project:) else diff --git a/app/graphql/resolvers/project_samples_resolver.rb b/app/graphql/resolvers/project_samples_resolver.rb index be14667668..cafa96210e 100644 --- a/app/graphql/resolvers/project_samples_resolver.rb +++ b/app/graphql/resolvers/project_samples_resolver.rb @@ -16,6 +16,8 @@ class ProjectSamplesResolver < BaseResolver default_value: nil def resolve(filter:, order_by:) + context.scoped_set!(:project, project) + context.scoped_set!(:samples_preauthorized, true) ransack_obj = project.samples.ransack(filter&.to_h) ransack_obj.sorts = ["#{order_by.field} #{order_by.direction}"] if order_by.present? diff --git a/app/graphql/resolvers/projects_resolver.rb b/app/graphql/resolvers/projects_resolver.rb index 25276e20c5..5f9df05833 100644 --- a/app/graphql/resolvers/projects_resolver.rb +++ b/app/graphql/resolvers/projects_resolver.rb @@ -21,6 +21,7 @@ class ProjectsResolver < BaseResolver default_value: nil def resolve(group_id:, filter:, order_by:) + context.scoped_set!(:projects_preauthorized, true) projects = group_id ? projects_by_group_scope(group_id:) : projects_by_scope ransack_obj = projects.ransack(filter&.to_h) ransack_obj.sorts = ["#{order_by.field} #{order_by.direction}"] if order_by.present? diff --git a/app/graphql/resolvers/sample_attachments_resolver.rb b/app/graphql/resolvers/sample_attachments_resolver.rb index c6ee4eba25..380cc38a4c 100644 --- a/app/graphql/resolvers/sample_attachments_resolver.rb +++ b/app/graphql/resolvers/sample_attachments_resolver.rb @@ -16,6 +16,7 @@ class SampleAttachmentsResolver < BaseResolver alias sample object def resolve(filter:, order_by:) + context.scoped_set!(:attachments_preauthorized, true) ransack_obj = sample.attachments.joins(:file_blob).ransack(filter&.to_h) ransack_obj.sorts = ["#{order_by.field} #{order_by.direction}"] if order_by.present? diff --git a/app/graphql/resolvers/samples_resolver.rb b/app/graphql/resolvers/samples_resolver.rb index c644f7e928..34f72a3fb9 100644 --- a/app/graphql/resolvers/samples_resolver.rb +++ b/app/graphql/resolvers/samples_resolver.rb @@ -21,6 +21,7 @@ class SamplesResolver < BaseResolver default_value: nil def resolve(group_id:, filter:, order_by:) + context.scoped_set!(:samples_preauthorized, true) samples = group_id ? samples_by_group_scope(group_id:) : samples_by_project_scope ransack_obj = samples.ransack(filter&.to_h) ransack_obj.sorts = ["#{order_by.field} #{order_by.direction}"] if order_by.present? diff --git a/app/graphql/types/attachment_type.rb b/app/graphql/types/attachment_type.rb index 206fc6e992..9bea12f101 100644 --- a/app/graphql/types/attachment_type.rb +++ b/app/graphql/types/attachment_type.rb @@ -26,12 +26,12 @@ def attachment_url end def self.authorized?(object, context) - super && + super && (context[:attachments_preauthorized] || allowed_to?( :read?, object.attachable.project, context: { user: context[:current_user], token: context[:token] } - ) + )) end end end diff --git a/app/graphql/types/project_type.rb b/app/graphql/types/project_type.rb index 1c6bb18fe5..bd8c2a6cfb 100644 --- a/app/graphql/types/project_type.rb +++ b/app/graphql/types/project_type.rb @@ -35,12 +35,12 @@ class ProjectType < Types::BaseType field :parent, NamespaceType, null: false, description: 'Parent namespace' def self.authorized?(object, context) - super && + super && (context[:projects_preauthorized] || allowed_to?( :read?, object, context: { user: context[:current_user], token: context[:token] } - ) + )) end end end diff --git a/app/graphql/types/sample_type.rb b/app/graphql/types/sample_type.rb index 41f08bf8e4..395339f8ab 100644 --- a/app/graphql/types/sample_type.rb +++ b/app/graphql/types/sample_type.rb @@ -28,13 +28,18 @@ class SampleType < Types::BaseType null: true, description: 'Datetime when associated attachments were last updated.' + def project + context.scoped_set!(:projects_preauthorized, true) + context[:project] || object.project + end + def self.authorized?(object, context) - super && + super && (context[:samples_preauthorized] || allowed_to?( :read_sample?, object.project, context: { user: context[:current_user], token: context[:token] } - ) + )) end end end diff --git a/test/controllers/projects/samples/attachments_controller_test.rb b/test/controllers/projects/samples/attachments_controller_test.rb index 2eca3257ce..2e8b3022dd 100644 --- a/test/controllers/projects/samples/attachments_controller_test.rb +++ b/test/controllers/projects/samples/attachments_controller_test.rb @@ -55,7 +55,7 @@ class AttachmentsControllerTest < ActionDispatch::IntegrationTest post namespace_project_sample_attachments_url(@namespace, @project, @sample1), params: { attachment: { files: [fixture_file_upload('test_file_1.fastq', 'text/plain'), - fixture_file_upload('test_file.fastq', 'text/plain')] + fixture_file_upload('test_file_A.fastq', 'text/plain')] } }, as: :turbo_stream end @@ -65,7 +65,7 @@ class AttachmentsControllerTest < ActionDispatch::IntegrationTest assert_no_difference('Attachment.count') do post namespace_project_sample_attachments_url(@namespace, @project, @sample1), params: { attachment: { - files: [fixture_file_upload('test_file.fastq', 'text/plain')] + files: [fixture_file_upload('test_file_A.fastq', 'text/plain')] } }, as: :turbo_stream end diff --git a/test/fixtures/active_storage/attachments.yml b/test/fixtures/active_storage/attachments.yml index ac8838fb9e..43fbcf4fa6 100644 --- a/test/fixtures/active_storage/attachments.yml +++ b/test/fixtures/active_storage/attachments.yml @@ -1,12 +1,12 @@ -attachment1_file_test_file_fastq: +attachment1_file_test_file_A_fastq: name: file record: attachment1 (Attachment) - blob: attachment1_file_test_file_fastq_blob + blob: attachment1_file_test_file_A_fastq_blob -attachment2_file_test_file_A_fastq: +attachment2_file_test_file_B_fastq: name: file record: attachment2 (Attachment) - blob: attachment2_file_test_file_A_fastq_blob + blob: attachment2_file_test_file_B_fastq_blob attachmentA_file_test_file_fastq: name: file diff --git a/test/fixtures/active_storage/blobs.yml b/test/fixtures/active_storage/blobs.yml index dbade44bb7..e3202dc1c9 100644 --- a/test/fixtures/active_storage/blobs.yml +++ b/test/fixtures/active_storage/blobs.yml @@ -1,9 +1,11 @@ -attachment1_file_test_file_fastq_blob: <%= ActiveStorage::FixtureSet.blob filename: "test_file.fastq", service_name: "test" %> +attachment1_file_test_file_A_fastq_blob: <%= ActiveStorage::FixtureSet.blob filename: "test_file_A.fastq", service_name: "test" %> -attachment2_file_test_file_A_fastq_blob: <%= ActiveStorage::FixtureSet.blob filename: "test_file_A.fastq", service_name: "test" %> +attachment2_file_test_file_B_fastq_blob: <%= ActiveStorage::FixtureSet.blob filename: "test_file_B.fastq", service_name: "test" %> test_file_fastq_blob: <%= ActiveStorage::FixtureSet.blob filename: "test_file.fastq", service_name: "test" %> +test_file_A_fastq_blob: <%= ActiveStorage::FixtureSet.blob filename: "test_file_A.fastq", service_name: "test" %> + testsample_illumina_pe_forward_blob: <%= ActiveStorage::FixtureSet.blob filename: "TestSample_S1_L001_R1_001.fastq", service_name: "test" %> testsample_illumina_pe_reverse_blob: <%= ActiveStorage::FixtureSet.blob filename: "TestSample_S1_L001_R2_001.fastq", service_name: "test" %> diff --git a/test/fixtures/data_exports.yml b/test/fixtures/data_exports.yml index dbf22bae0d..9086523876 100644 --- a/test/fixtures/data_exports.yml +++ b/test/fixtures/data_exports.yml @@ -13,7 +13,7 @@ data_export_one: created_at: <%= 1.week.ago %> updated_at: <%= 1.day.ago %> user_id: <%= ActiveRecord::FixtureSet.identify(:john_doe, :uuid) %> - manifest: '{"type":"Samples Export","date": "2024-01-01","children":[{"name":"INXT_PRJ_AAAAAAAAAA","type":"folder","irida-next-type":"project","irida-next-name":"Project 1","children":[{"name":"INXT_SAM_AAAAAAAAAA","type":"folder","irida-next-type":"sample","irida-next-name":"Project 1 Sample 1","children":[{"name":"INXT_ATT_AAAAAAAAAA","type":"folder","irida-next-type":"attachment","children":[{"name":"test_file.fastq","type":"file","metadata":{"format":"fastq"}}]},{"name":"INXT_ATT_AAAAAAAAAB","type":"folder","irida-next-type":"attachment","children":[{"name":"test_file_A.fastq","type":"file","metadata":{"format":"fastq"}}]}]}]}]}' + manifest: '{"type":"Samples Export","date": "2024-01-01","children":[{"name":"INXT_PRJ_AAAAAAAAAA","type":"folder","irida-next-type":"project","irida-next-name":"Project 1","children":[{"name":"INXT_SAM_AAAAAAAAAA","type":"folder","irida-next-type":"sample","irida-next-name":"Project 1 Sample 1","children":[{"name":"INXT_ATT_AAAAAAAAAA","type":"folder","irida-next-type":"attachment","children":[{"name":"test_file_A.fastq","type":"file","metadata":{"format":"fastq"}}]},{"name":"INXT_ATT_AAAAAAAAAB","type":"folder","irida-next-type":"attachment","children":[{"name":"test_file_B.fastq","type":"file","metadata":{"format":"fastq"}}]}]}]}]}' data_export_two: export_type: sample diff --git a/test/graphql/attachments_query_test.rb b/test/graphql/attachments_query_test.rb index b97115d816..eb6166e070 100644 --- a/test/graphql/attachments_query_test.rb +++ b/test/graphql/attachments_query_test.rb @@ -8,15 +8,13 @@ class AttachmentsQueryTest < ActiveSupport::TestCase sample(puid: $puid) { id attachments(filter: $attachmentFilter, orderBy: $attachmentOrderBy) { - edges { - node { - id, - metadata, - filename, - byteSize, - createdAt, - updatedAt - } + nodes { + id, + metadata, + filename, + byteSize, + createdAt, + updatedAt } } } @@ -28,15 +26,13 @@ class AttachmentsQueryTest < ActiveSupport::TestCase project(puid: $puid) { id attachments(filter: $attachmentFilter, orderBy: $attachmentOrderBy) { - edges { - node { - id, - metadata, - filename, - byteSize, - createdAt, - updatedAt - } + nodes { + id, + metadata, + filename, + byteSize, + createdAt, + updatedAt } } } @@ -48,16 +44,14 @@ class AttachmentsQueryTest < ActiveSupport::TestCase sample(puid: $puid) { id attachments { - edges { - node { - id, - filename, - attachmentUrl, - createdAt, - updatedAt - } + nodes { + id, + filename, + attachmentUrl, + createdAt, + updatedAt } - } + } } } GRAPHQL @@ -67,13 +61,11 @@ class AttachmentsQueryTest < ActiveSupport::TestCase sample(puid: $puid) { id attachments { - edges { - node { - id, - metadata( - keys: ["format"] - ) - } + nodes { + id, + metadata( + keys: ["format"] + ) } } } @@ -85,11 +77,9 @@ class AttachmentsQueryTest < ActiveSupport::TestCase sample(puid: $samp_puid) { id attachments(first: $first) { - edges { - node { - id, - metadata - } + nodes { + id, + metadata } } } @@ -114,21 +104,21 @@ def setup assert_not_empty data, 'sample type should work' assert_not_empty data['attachments'] - assert_not_empty data['attachments']['edges'] + assert_not_empty data['attachments']['nodes'] - attachments = data['attachments']['edges'] + attachments = data['attachments']['nodes'] assert_equal 2, attachments.count - assert_equal 'test_file.fastq', attachments[0]['node']['filename'] - assert_equal 'test_file_A.fastq', attachments[1]['node']['filename'] + assert_equal 'test_file_A.fastq', attachments[0]['filename'] + assert_equal 'test_file_B.fastq', attachments[1]['filename'] - assert_equal 2102, attachments[0]['node']['byteSize'] - assert_equal 2101, attachments[1]['node']['byteSize'] + assert_equal 2101, attachments[0]['byteSize'] + assert_equal 2101, attachments[1]['byteSize'] - assert_equal 'fastq', attachments[0]['node']['metadata']['format'] - assert_equal 'none', attachments[0]['node']['metadata']['compression'] - assert_equal 'fastq', attachments[1]['node']['metadata']['format'] - assert_equal 'none', attachments[1]['node']['metadata']['compression'] + assert_equal 'fastq', attachments[0]['metadata']['format'] + assert_equal 'none', attachments[0]['metadata']['compression'] + assert_equal 'fastq', attachments[1]['metadata']['format'] + assert_equal 'none', attachments[1]['metadata']['compression'] end test 'attachment query on project should work' do @@ -143,21 +133,21 @@ def setup assert_not_empty data, 'project type should work' assert_not_empty data['attachments'] - assert_not_empty data['attachments']['edges'] + assert_not_empty data['attachments']['nodes'] - attachments = data['attachments']['edges'] + attachments = data['attachments']['nodes'] assert_equal 2, attachments.count - assert_equal 'test_file.fastq', attachments[0]['node']['filename'] - assert_equal 'data_export_8.csv', attachments[1]['node']['filename'] + assert_equal 'test_file.fastq', attachments[0]['filename'] + assert_equal 'data_export_8.csv', attachments[1]['filename'] - assert_equal 2102, attachments[0]['node']['byteSize'] - assert_equal 84, attachments[1]['node']['byteSize'] + assert_equal 2102, attachments[0]['byteSize'] + assert_equal 84, attachments[1]['byteSize'] - assert_equal 'fastq', attachments[0]['node']['metadata']['format'] - assert_equal 'none', attachments[0]['node']['metadata']['compression'] - assert_equal 'csv', attachments[1]['node']['metadata']['format'] - assert_equal 'none', attachments[1]['node']['metadata']['compression'] + assert_equal 'fastq', attachments[0]['metadata']['format'] + assert_equal 'none', attachments[0]['metadata']['compression'] + assert_equal 'csv', attachments[1]['metadata']['format'] + assert_equal 'none', attachments[1]['metadata']['compression'] end test 'attachment query should work for uploader access level' do @@ -173,21 +163,21 @@ def setup assert_not_empty data, 'sample type should work' assert_not_empty data['attachments'] - assert_not_empty data['attachments']['edges'] + assert_not_empty data['attachments']['nodes'] - attachments = data['attachments']['edges'] + attachments = data['attachments']['nodes'] assert_equal 2, attachments.count - assert_equal 'test_file.fastq', attachments[0]['node']['filename'] - assert_equal 'test_file_A.fastq', attachments[1]['node']['filename'] + assert_equal 'test_file_A.fastq', attachments[0]['filename'] + assert_equal 'test_file_B.fastq', attachments[1]['filename'] - assert_equal 2102, attachments[0]['node']['byteSize'] - assert_equal 2101, attachments[1]['node']['byteSize'] + assert_equal 2101, attachments[0]['byteSize'] + assert_equal 2101, attachments[1]['byteSize'] - assert_equal 'fastq', attachments[0]['node']['metadata']['format'] - assert_equal 'none', attachments[0]['node']['metadata']['compression'] - assert_equal 'fastq', attachments[1]['node']['metadata']['format'] - assert_equal 'none', attachments[1]['node']['metadata']['compression'] + assert_equal 'fastq', attachments[0]['metadata']['format'] + assert_equal 'none', attachments[0]['metadata']['compression'] + assert_equal 'fastq', attachments[1]['metadata']['format'] + assert_equal 'none', attachments[1]['metadata']['compression'] end test 'attachment query should work with filter' do @@ -202,17 +192,17 @@ def setup assert_not_empty data, 'sample type should work' assert_not_empty data['attachments'] - assert_not_empty data['attachments']['edges'] + assert_not_empty data['attachments']['nodes'] - attachments = data['attachments']['edges'] + attachments = data['attachments']['nodes'] assert_equal 1, attachments.count - assert_equal 'test_file_A.fastq', attachments[0]['node']['filename'] + assert_equal 'test_file_A.fastq', attachments[0]['filename'] - assert_equal 2101, attachments[0]['node']['byteSize'] + assert_equal 2101, attachments[0]['byteSize'] - assert_equal 'fastq', attachments[0]['node']['metadata']['format'] - assert_equal 'none', attachments[0]['node']['metadata']['compression'] + assert_equal 'fastq', attachments[0]['metadata']['format'] + assert_equal 'none', attachments[0]['metadata']['compression'] end test 'attachment query should work with order by' do @@ -228,21 +218,21 @@ def setup assert_not_empty data, 'sample type should work' assert_not_empty data['attachments'] - assert_not_empty data['attachments']['edges'] + assert_not_empty data['attachments']['nodes'] - attachments = data['attachments']['edges'] + attachments = data['attachments']['nodes'] assert_equal 2, attachments.count - assert_equal 'test_file_A.fastq', attachments[0]['node']['filename'] - assert_equal 'test_file.fastq', attachments[1]['node']['filename'] + assert_equal 'test_file_A.fastq', attachments[0]['filename'] + assert_equal 'test_file_B.fastq', attachments[1]['filename'] - assert_equal 2101, attachments[0]['node']['byteSize'] - assert_equal 2102, attachments[1]['node']['byteSize'] + assert_equal 2101, attachments[0]['byteSize'] + assert_equal 2101, attachments[1]['byteSize'] - assert_equal 'fastq', attachments[0]['node']['metadata']['format'] - assert_equal 'none', attachments[0]['node']['metadata']['compression'] - assert_equal 'fastq', attachments[1]['node']['metadata']['format'] - assert_equal 'none', attachments[1]['node']['metadata']['compression'] + assert_equal 'fastq', attachments[0]['metadata']['format'] + assert_equal 'none', attachments[0]['metadata']['compression'] + assert_equal 'fastq', attachments[1]['metadata']['format'] + assert_equal 'none', attachments[1]['metadata']['compression'] end test 'attachment url query should work' do @@ -257,11 +247,11 @@ def setup assert_nil result['errors'], 'should work and have no errors.' - attachments = result['data']['sample']['attachments']['edges'] + attachments = result['data']['sample']['attachments']['nodes'] assert_equal 2, attachments.count - assert_equal file_url1, attachments[0]['node']['attachmentUrl'] - assert_equal file_url2, attachments[1]['node']['attachmentUrl'] + assert_equal file_url1, attachments[0]['attachmentUrl'] + assert_equal file_url2, attachments[1]['attachmentUrl'] end test 'attachment url query should not work due to expired token for uploader access level' do @@ -283,9 +273,9 @@ def setup assert_nil result['errors'], 'should work and have no errors.' - attachments = result['data']['sample']['attachments']['edges'] - metadata1 = attachments[0]['node']['metadata'] - metadata2 = attachments[1]['node']['metadata'] + attachments = result['data']['sample']['attachments']['nodes'] + metadata1 = attachments[0]['metadata'] + metadata2 = attachments[1]['metadata'] assert_equal 'fastq', metadata1['format'], "should have requested 'format'" assert_equal 'fastq', metadata2['format'], "should have requested 'format'" @@ -303,10 +293,10 @@ def setup assert_nil result['errors'], 'should work and have no errors.' - attachment1 = result['data']['sample']['attachments']['edges'][0] - attachment2 = result['data']['sample']['attachments']['edges'][1] - metadata1 = attachment1['node']['metadata'] - metadata2 = attachment2['node']['metadata'] + attachment1 = result['data']['sample']['attachments']['nodes'][0] + attachment2 = result['data']['sample']['attachments']['nodes'][1] + metadata1 = attachment1['metadata'] + metadata2 = attachment2['metadata'] assert_equal 'forward', metadata1['direction'] assert_equal 'reverse', metadata2['direction'] @@ -315,7 +305,7 @@ def setup assert_equal 'pe', metadata2['type'] # check they reference each other - assert_equal attachment1['node']['id'], "gid://irida/Attachment/#{metadata2['associated_attachment_id']}" - assert_equal attachment2['node']['id'], "gid://irida/Attachment/#{metadata1['associated_attachment_id']}" + assert_equal attachment1['id'], "gid://irida/Attachment/#{metadata2['associated_attachment_id']}" + assert_equal attachment2['id'], "gid://irida/Attachment/#{metadata1['associated_attachment_id']}" end end diff --git a/test/jobs/data_exports/create_job_test.rb b/test/jobs/data_exports/create_job_test.rb index 3503fa4e44..6ca3e2d241 100644 --- a/test/jobs/data_exports/create_job_test.rb +++ b/test/jobs/data_exports/create_job_test.rb @@ -61,7 +61,7 @@ def setup 'irida-next-type' => 'attachment', 'children' => [{ - 'name' => 'test_file.fastq', + 'name' => 'test_file_A.fastq', 'type' => 'file', 'metadata' => { 'format' => 'fastq' } }] @@ -71,7 +71,7 @@ def setup 'type' => 'folder', 'irida-next-type' => 'attachment', 'children' => [{ - 'name' => 'test_file_A.fastq', + 'name' => 'test_file_B.fastq', 'type' => 'file', 'metadata' => { 'format' => 'fastq' } }] @@ -114,9 +114,9 @@ def setup '└─ INXT_PRJ_AAAAAAAAAA/ (Project 1)', ' └─ INXT_SAM_AAAAAAAAAA/ (Project 1 Sample 1)', ' ├─ INXT_ATT_AAAAAAAAAA/', - ' │ └─ test_file.fastq', + ' │ └─ test_file_A.fastq', ' └─ INXT_ATT_AAAAAAAAAB/', - ' └─ test_file_A.fastq', + ' └─ test_file_B.fastq', '' ].join("\n") diff --git a/test/models/attachment_test.rb b/test/models/attachment_test.rb index fc5dfbde54..99bce70017 100644 --- a/test/models/attachment_test.rb +++ b/test/models/attachment_test.rb @@ -19,8 +19,10 @@ def setup end test 'invalid when file checksum matches another Attachment associated with the Attachable' do - new_attachment = @sample.attachments.build(file: { io: Rails.root.join('test/fixtures/files/test_file.fastq').open, - filename: 'test_file.fastq' }) + new_attachment = @sample.attachments.build( + file: { io: Rails.root.join('test/fixtures/files/test_file_A.fastq').open, + filename: 'test_file_A.fastq' } + ) assert_not new_attachment.valid? assert new_attachment.errors.added?(:file, :checksum_uniqueness) end @@ -28,8 +30,8 @@ def setup test 'file checksum matches another Attachment associated with the Attachable but with different filename' do assert_equal 2, @sample.attachments.count new_attachment = @sample.attachments.build(file: - { io: Rails.root.join('test/fixtures/files/test_file.fastq').open, - filename: 'copy_of_test_file.fastq' }) + { io: Rails.root.join('test/fixtures/files/test_file_A.fastq').open, + filename: 'copy_of_test_file_A.fastq' }) assert new_attachment.valid? @sample.save assert_equal 3, @sample.attachments.count @@ -38,7 +40,7 @@ def setup test 'file checksum differs from another Attachment associated with the Attachable but with same filename' do new_attachment = @sample.attachments.build(file: { io: Rails.root.join('test/fixtures/files/test_file_C.fastq').open, - filename: 'test_file.fastq' }) + filename: 'test_file_A.fastq' }) assert new_attachment.valid? @sample.save assert_equal 3, @sample.attachments.count diff --git a/test/services/attachments/create_service_test.rb b/test/services/attachments/create_service_test.rb index 7464463a7a..9860ff3c2a 100644 --- a/test/services/attachments/create_service_test.rb +++ b/test/services/attachments/create_service_test.rb @@ -10,7 +10,7 @@ def setup @sample1 = samples(:sample1) @project1 = projects(:project1) @group1 = groups(:group_one) - @fastq_se_blob = active_storage_blobs(:test_file_fastq_blob) + @fastq_se_blob = active_storage_blobs(:test_file_A_fastq_blob) @attachment_b_blob = active_storage_blobs(:attachmentB_file_test_file_fastq_blob) @testsample_illumina_pe_fwd_blob = active_storage_blobs(:testsample_illumina_pe_forward_blob) @testsample_illumina_pe_rev_blob = active_storage_blobs(:testsample_illumina_pe_reverse_blob) diff --git a/test/system/projects/samples_test.rb b/test/system/projects/samples_test.rb index b2db5b42c0..0d3e1896c3 100644 --- a/test/system/projects/samples_test.rb +++ b/test/system/projects/samples_test.rb @@ -162,9 +162,9 @@ class SamplesTest < ApplicationSystemTestCase click_button I18n.t('projects.samples.attachments.delete_attachment_modal.submit_button') end - assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'test_file.fastq') + assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'test_file_A.fastq') within('#table-listing') do - assert_no_text 'test_file.fastq' + assert_no_text 'test_file_A.fastq' end end @@ -908,8 +908,8 @@ class SamplesTest < ApplicationSystemTestCase end click_link I18n.t('projects.samples.show.concatenate_button'), match: :first within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file.fastq' assert_text 'test_file_A.fastq' + assert_text 'test_file_B.fastq' fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') assert_html5_inputs_valid @@ -958,8 +958,8 @@ class SamplesTest < ApplicationSystemTestCase end click_link I18n.t('projects.samples.show.concatenate_button'), match: :first within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file.fastq' assert_text 'test_file_A.fastq' + assert_text 'test_file_B.fastq' fill_in I18n.t('projects.samples.attachments.concatenations.modal.basename'), with: 'concatenated_file' check 'Delete originals' click_on I18n.t('projects.samples.attachments.concatenations.modal.submit_button') @@ -1132,21 +1132,21 @@ class SamplesTest < ApplicationSystemTestCase visit namespace_project_sample_url(@namespace, @project, @sample1) within %(turbo-frame[id="table-listing"]) do assert_selector 'table #attachments-table-body tr', count: 2 - find('table #attachments-table-body tr', text: 'test_file.fastq').find('input').click find('table #attachments-table-body tr', text: 'test_file_A.fastq').find('input').click + find('table #attachments-table-body tr', text: 'test_file_B.fastq').find('input').click end click_link I18n.t('projects.samples.show.delete_files_button'), match: :first within('span[data-controller-connected="true"] dialog') do - assert_text 'test_file.fastq' assert_text 'test_file_A.fastq' + assert_text 'test_file_B.fastq' click_on I18n.t('projects.samples.attachments.deletions.modal.submit_button') assert_html5_inputs_valid end assert_text I18n.t('projects.samples.attachments.deletions.destroy.success') within %(turbo-frame[id="table-listing"]) do assert_selector 'table #attachments-table-body tr', count: 0 - assert_no_text 'test_file.fastq' assert_no_text 'test_file_A.fastq' + assert_no_text 'test_file_B.fastq' assert_text I18n.t('projects.samples.show.no_files') assert_text I18n.t('projects.samples.show.no_associated_files') end @@ -2536,23 +2536,23 @@ def retrieve_puids click_button I18n.t('projects.samples.attachments.delete_attachment_modal.submit_button') end - assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'test_file.fastq') + assert_text I18n.t('projects.samples.attachments.destroy.success', filename: 'test_file_A.fastq') within('#table-listing') do - assert_no_text 'test_file.fastq' - assert_text 'test_file_A.fastq' + assert_no_text 'test_file_A.fastq' + assert_text 'test_file_B.fastq' end click_link I18n.t('projects.samples.show.delete_files_button'), match: :first within('dialog') do - assert_text 'test_file_A.fastq' - assert_no_text 'test_file.fastq' + assert_text 'test_file_B.fastq' + assert_no_text 'test_file_A.fastq' click_button I18n.t('projects.samples.attachments.deletions.modal.submit_button') end assert_text I18n.t('projects.samples.attachments.deletions.destroy.success') assert_no_text 'test_file_A.fastq' - assert_no_text 'test_file.fastq' + assert_no_text 'test_file_B.fastq' assert_text I18n.t('projects.samples.show.no_files') assert_selector 'a.cursor-not-allowed.pointer-events-none', count: 2 end diff --git a/test/system/workflow_executions_test.rb b/test/system/workflow_executions_test.rb index 88190fcdcc..ff50c6f84e 100644 --- a/test/system/workflow_executions_test.rb +++ b/test/system/workflow_executions_test.rb @@ -340,7 +340,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase assert_selector 'table tbody tr', count: 1 assert_text 'INXT_SAM_AAAAAAAAAA' assert_text 'INXT_ATT_AAAAAAAAAA' - assert_text 'test_file.fastq' + assert_text 'test_file_A.fastq' end test 'can view workflow execution with samplesheet with multiple files' do @@ -353,7 +353,7 @@ class WorkflowExecutionsTest < ApplicationSystemTestCase assert_selector 'table tbody tr', count: 1 assert_text 'INXT_SAM_AAAAAAAAAA' assert_text 'INXT_ATT_AAAAAAAAAA' - assert_text 'test_file.fastq' + assert_text 'test_file_A.fastq' assert_text 'INXT_ATT_AAAAAAAAAB' assert_text 'test_file_A.fastq' end