From e4faa9ef8bb611e66cee4f776755098bd77c4868 Mon Sep 17 00:00:00 2001 From: Frank Bergmann Date: Fri, 1 Jul 2022 14:22:29 +0200 Subject: [PATCH] WIP - Added mocking to show_file_links_spec.rb integration test --- .../spec/features/show_file_links_spec.rb | 15 ++++++++++++--- .../requests/api/v3/file_links/file_links_spec.rb | 2 +- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/modules/storages/spec/features/show_file_links_spec.rb b/modules/storages/spec/features/show_file_links_spec.rb index ae2b692cc7..2a6299ade6 100644 --- a/modules/storages/spec/features/show_file_links_spec.rb +++ b/modules/storages/spec/features/show_file_links_spec.rb @@ -41,9 +41,8 @@ describe 'Showing of file links in work package', with_flag: { storages_module_a let(:file_link) { create(:file_link, container: work_package, storage:) } let(:wp_page) { ::Pages::FullWorkPackage.new(work_package, project) } - # We're going to use the real ConnectionManager because we can't mock request_with_token_refresh - let(:connection_manager) { ::OAuthClients::ConnectionManager.new(user: current_user, oauth_client:) } - # let(:connection_manager) { instance_double(::OAuthClients::ConnectionManager) } + let(:connection_manager) { instance_double(::OAuthClients::ConnectionManager) } + let(:sync_service) { instance_double(::Storages::FileLinkSyncService) } before do allow(::OAuthClients::ConnectionManager) @@ -55,6 +54,16 @@ describe 'Showing of file links in work package', with_flag: { storages_module_a allow(connection_manager) .to receive(:get_access_token) .and_return(ServiceResult.success(result: oauth_client_token)) + allow(connection_manager) + .to receive(:authorization_state) + .and_return(:connected) + + # Mock FileLinkSyncService as if Nextcloud would respond with origin_permission=nil + allow(::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 }) + end project_storage file_link diff --git a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb index d0fa239239..5cdf1881b5 100644 --- a/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb +++ b/modules/storages/spec/requests/api/v3/file_links/file_links_spec.rb @@ -84,7 +84,7 @@ describe 'API v3 file links resource', with_flag: { storages_module_active: true allow(::Storages::FileLinkSyncService) .to receive(:new).and_return(sync_service) allow(sync_service).to receive(:call) do |file_links| - ServiceResult.success(result: file_links) + ServiceResult.success(result: file_links.each { |file_link| file_link.origin_permission = :view }) end login_as current_user