OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
[#52039] fixed file links unit tests
Eric Schubert3696be105561
diff --git a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rbindex a735b6ef8fb..c9c706618b7 100644--- a/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb+++ b/modules/storages/spec/lib/api/v3/file_links/file_link_representer_rendering_spec.rb@@ -38,8 +38,8 @@ RSpec.describe API::V3::FileLinks::FileLinkRepresenter, 'rendering' dolet(:container) { build_stubbed(:work_package) }let(:project) { container.project }let(:creator) { build_stubbed(:user, firstname: 'Rey', lastname: 'Palpatine') }- let(:origin_permission) { :view }- let(:file_link) { build_stubbed(:file_link, storage:, container:, creator:, origin_permission:) }+ let(:origin_status) { :view_allowed }+ let(:file_link) { build_stubbed(:file_link, storage:, container:, creator:, origin_status:) }let(:user) { build_stubbed(:user) }let(:representer) { described_class.new(file_link, current_user: user) }@@ -88,39 +88,49 @@ RSpec.describe API::V3::FileLinks::FileLinkRepresenter, 'rendering' doendend- describe 'permission' do- context 'with permission granted' do+ describe 'status' do+ context 'with permission' doit_behaves_like 'has a titled link' do- let(:link) { 'permission' }- let(:href) { 'urn:openproject-org:api:v3:file-links:permission:View' }- let(:title) { 'View' }+ let(:link) { 'status' }+ let(:href) { 'urn:openproject-org:api:v3:file-links:permission:ViewAllowed' }+ let(:title) { 'View allowed' }endend- context 'with permission NotAllowed' do- let(:origin_permission) { :not_allowed }+ context 'without permission' do+ let(:origin_status) { :view_not_allowed }it_behaves_like 'has a titled link' do- let(:link) { 'permission' }- let(:href) { 'urn:openproject-org:api:v3:file-links:permission:NotAllowed' }- let(:title) { 'Not allowed' }+ let(:link) { 'status' }+ let(:href) { 'urn:openproject-org:api:v3:file-links:permission:ViewNotAllowed' }+ let(:title) { 'View not allowed' }endend- context 'with permission not defined (nil)' do- let(:origin_permission) { nil }+ context 'if not found' do+ let(:origin_status) { :not_found }++ it_behaves_like 'has a titled link' do+ let(:link) { 'status' }+ let(:href) { 'urn:openproject-org:api:v3:file-links:NotFound' }+ let(:title) { 'Not found' }+ end+ end++ context 'with status not defined (nil)' do+ let(:origin_status) { nil }it_behaves_like 'has no link' do- let(:link) { 'permission' }+ let(:link) { 'status' }endend- context 'with permission check had an Error' do- let(:origin_permission) { :error }+ context 'with status check had an error' do+ let(:origin_status) { :error }it_behaves_like 'has a titled link' do- let(:link) { 'permission' }- let(:href) { 'urn:openproject-org:api:v3:file-links:permission:Error' }+ let(:link) { 'status' }+ let(:href) { 'urn:openproject-org:api:v3:file-links:Error' }let(:title) { 'Error' }endenddiff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rbindex 7f9ae5afcc0..9c8b7a05c93 100644--- a/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/file_links_api_spec.rb@@ -96,7 +96,7 @@ RSpec.describe 'API v3 file links resource' doallow(Storages::FileLinkSyncService).to receive(:new).and_return(sync_service)allow(sync_service).to receive(:call) do |file_links|- ServiceResult.success(result: file_links.each { |file_link| file_link.origin_permission = :view })+ ServiceResult.success(result: file_links.each { |file_link| file_link.origin_status = :view_allowed })endlogin_as current_userdiff --git a/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb b/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rbindex f380a95e4f9..947d8374fd8 100644--- a/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb+++ b/modules/storages/spec/requests/api/v3/file_links/mixed_case_file_links_integration_spec.rb@@ -73,8 +73,7 @@ RSpec.describe 'API v3 file links resource' dolet(:file_link_happy) { create(:file_link, origin_id: "24", storage: storage_good, container: work_package) }let(:file_link_other_user) { create(:file_link, origin_id: '25', storage: storage_good, container: work_package) }- let(:file_link_trashed) { create(:file_link, origin_id: '26', storage: storage_good, container: work_package) }- let(:file_link_deleted) { create(:file_link, origin_id: '27', storage: storage_good, container: work_package) }+ let(:file_link_deleted) { create(:file_link, origin_id: '26', storage: storage_good, container: work_package) }let(:file_link_unauth_happy) { create(:file_link, origin_id: "28", storage: storage_unauth, container: work_package) }let(:file_link_error_happy) { create(:file_link, origin_id: "29", storage: storage_error, container: work_package) }@@ -88,7 +87,6 @@ RSpec.describe 'API v3 file links resource' dolet(:file_info_s404) { { status: "Not found", statuscode: 404 } }# Nextcloud response part for valid file- let(:trashed) { false } # trashed is included in file_info1_s200 belowlet(:file_info_happy) do{id: 24,@@ -101,23 +99,6 @@ RSpec.describe 'API v3 file links resource' dosize: 12706214,owner_id: "admin",owner_name: "admin",- trashed: false,- path: "/Nextcloud Manual.pdf"- }- end- let(:file_info_trashed) do- {- id: 26,- status: "OK",- statuscode: 200,- name: "Reasons to use Nextcloud Manual.pdf",- mtime: 1655311634,- ctime: 1655344567,- mimetype: "application/pdf",- size: 954123,- owner_id: "admin",- owner_name: "admin",- trashed: true,path: "/Nextcloud Manual.pdf"}end@@ -137,7 +118,6 @@ RSpec.describe 'API v3 file links resource' dofile_link_happyfile_link_other_user- file_link_trashedfile_link_deleted# FileLinks on host-unauth and host-error that we'll see in the result list with origin_permission=:error@@ -158,8 +138,7 @@ RSpec.describe 'API v3 file links resource' dodata: {'24': file_info_happy,'25': file_info_s403,- '26': file_info_trashed,- '27': file_info_s404+ '26': file_info_s404}}}.to_json@@ -190,15 +169,15 @@ RSpec.describe 'API v3 file links resource' doend# total, count, element_type, collection_type = 'Collection'- it_behaves_like 'API V3 collection response', 5, 5, 'FileLink', 'Collection' do+ it_behaves_like 'API V3 collection response', 6, 6, 'FileLink', 'Collection' dolet(:elements) do[file_link_timeout_happy,file_link_error_happy,file_link_unauth_happy,+ file_link_deleted,file_link_other_user,file_link_happy- # We didn't include file_link_trashed here, as it's not returned by API]endend@@ -209,30 +188,26 @@ RSpec.describe 'API v3 file links resource' do# A "happy" file link should be visiblehappy_file_link = elements.detect { |e| e["originData"]["id"] == "24" }- expect(happy_file_link["_links"]["permission"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_VIEW+ expect(happy_file_link["_links"]["status"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_VIEW# Check that we've got an updated mtimeexpect(happy_file_link["originData"]["lastModifiedAt"]).to eql Time.zone.at(1655301234).iso8601(3)# A file link created by another user is not_allowedother_user_file_link = elements.detect { |e| e["originData"]["id"] == "25" }- expect(other_user_file_link["_links"]["permission"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_NOT_ALLOWED-- # A trashed FileLink should not be shown in the AP result list, but is not yet deleted- trashed_file_link = elements.detect { |e| e["originData"]["id"] == "26" }- expect(trashed_file_link).to be_nil+ expect(other_user_file_link["_links"]["status"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_NOT_ALLOWED# The deleted_file_link should not even appear in the Database anymoredeleted_file_link = elements.detect { |e| e["originData"]["id"] == "27" }expect(deleted_file_link).to be_nilexpect(Storages::FileLink.where(origin_id: '27').count).to be 0- # The FileLink from a Nextcloud with error should have origin_permission=:error+ # The FileLink from a Nextcloud with error should have origin_status=:errorerror_file_link = elements.detect { |e| e["originData"]["id"] == "29" }- expect(error_file_link["_links"]["permission"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_ERROR+ expect(error_file_link["_links"]["status"]["href"]).to eql API::V3::FileLinks::URN_STATUS_ERROR- # The FileLink from a Nextcloud with timeout should have origin_permission=:error+ # The FileLink from a Nextcloud with timeout should have origin_status=:errorerror_file_link = elements.detect { |e| e["originData"]["id"] == "30" }- expect(error_file_link["_links"]["permission"]["href"]).to eql API::V3::FileLinks::URN_PERMISSION_ERROR+ expect(error_file_link["_links"]["status"]["href"]).to eql API::V3::FileLinks::URN_STATUS_ERRORendendenddiff --git a/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb b/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rbindex 4f9da34621a..d6fd48e8680 100644--- a/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb+++ b/modules/storages/spec/services/storages/file_links/file_link_sync_service_spec.rb@@ -80,9 +80,9 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do.stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })end- it 'returns a FileLink with #origin_permission :not_allowed' do+ it 'returns a FileLink with #origin_status :not_allowed' doexpect(service.success).to be_truthy- expect(service.result.first.origin_permission).to be :not_allowed+ expect(service.result.first.origin_status).to be :view_not_allowedendend@@ -106,8 +106,8 @@ RSpec.describe Storages::FileLinkSyncService, type: :model doexpect(service.result.count).to be 2expect(service.result[0].origin_id).to eql file_info_one.idexpect(service.result[1].origin_id).to eql file_info_two.id- expect(service.result[0].origin_permission).to be :view- expect(service.result[1].origin_permission).to be :not_allowed+ expect(service.result[0].origin_status).to be :view_allowed+ expect(service.result[1].origin_status).to be :view_not_allowedendend@@ -120,10 +120,11 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do.stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })end- it 'deletes the file link' do+ it 'returns the file link with a status set to :not_found' doexpect(service.success).to be_truthy- expect(service.result.count).to be 0- expect(Storages::FileLink.all.count).to be 0+ expect(service.result.count).to be 1+ expect(Storages::FileLink.count).to be 1+ expect(service.result.first.origin_status).to be :not_foundendend@@ -136,11 +137,11 @@ RSpec.describe Storages::FileLinkSyncService, type: :model do.stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })end- it 'returns the file link with a permission set to :error' do+ it 'returns the file link with a status set to :error' doexpect(service.success).to be_truthyexpect(service.result.count).to be 1- expect(Storages::FileLink.all.count).to be 1- expect(service.result.first.origin_permission).to be :error+ expect(Storages::FileLink.count).to be 1+ expect(service.result.first.origin_status).to be :errorendend@@ -153,23 +154,7 @@ RSpec.describe Storages::FileLinkSyncService, type: :model doit 'leaves the list of file_links unchanged with permissions = :error' doexpect(service.success).to be_truthy- expect(service.result.first.origin_permission).to be :error- end- end-- context 'with file trashed in storage' do- let(:file_info) { build(:storage_file_info, trashed: true) }- let(:file_link_one) { create(:file_link, origin_id: file_info.id, storage: storage_one, container: work_package) }-- before do- Storages::Peripherals::Registry- .stub('queries.nextcloud.files_info', ->(_) { ServiceResult.success(result: [file_info]) })- end-- it 'returns an empty list of FileLinks' do- expect(subject).to be_a ServiceResult- expect(service.success).to be_truthy- expect(service.result.length).to be 0+ expect(service.result.first.origin_status).to be :errorendendend