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
Added specs for StorageRepresenter OAuth authorization result
Andreas Pfohle2bd2e876547
diff --git a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb b/modules/storages/spec/requests/api/v3/storages/storages_spec.rbindex f773e8f2aaf..6d4906db6cd 100644--- a/modules/storages/spec/requests/api/v3/storages/storages_spec.rb+++ b/modules/storages/spec/requests/api/v3/storages/storages_spec.rb@@ -32,7 +32,7 @@ require_module_spec_helperdescribe 'API v3 storages resource', with_flag: { storages_module_active: true }, type: :request, content_type: :json doinclude API::V3::Utilities::PathHelper- let(:permissions) { %i(view_file_links) }+ let(:permissions) { %i(view_work_packages view_file_links) }let(:project) { create(:project) }let(:current_user) do@@ -43,11 +43,16 @@ describe 'API v3 storages resource', with_flag: { storages_module_active: true }create(:storage, creator: current_user)end+ let(:project_storage) do+ create(:project_storage, project:, storage:)+ end+subject(:last_response) doget pathendbefore do+ project_storagelogin_as current_userend@@ -99,14 +104,35 @@ describe 'API v3 storages resource', with_flag: { storages_module_active: true }it_behaves_like 'not found'end- context 'when Storage connected to a OAuth2 Authorization Server' do- subject { last_response.body }+ context 'when OAuth authorization server is involved' do+ shared_examples 'a storage authorization result' do |authorization_state:, expected:|+ let(:connection_manager) { instance_double(::OAuthClients::ConnectionManager) }- let(:current_user) { create(:admin) }+ subject { last_response.body }++ before do+ allow(connection_manager).to receive(:authorization_state).and_return(authorization_state)+ allow(::OAuthClients::ConnectionManager).to receive(:new).and_return(connection_manager)+ end++ it "returns #{expected}" do+ expect(subject).to be_json_eql(expected.to_json).at_path('_links/authorizationState/href')+ end+ end++ context 'when authorization succeeds and storage is connected' do+ include_examples 'a storage authorization result',+ authorization_state: :connected, expected: ::API::V3::Storages::URN_CONNECTION_CONNECTED+ end++ context 'when authorization fails' do+ include_examples 'a storage authorization result',+ authorization_state: :failed_authorization, expected: ::API::V3::Storages::URN_CONNECTION_AUTH_FAILED+ end- it 'returns an error authorization state' do- expect(subject).to be_json_eql("urn:openproject-org:api:v3:storages:authorization:Error".to_json)- .at_path('_links/authorizationState/href')+ context 'when authorization fails with an error' do+ include_examples 'a storage authorization result',+ authorization_state: :error, expected: ::API::V3::Storages::URN_CONNECTION_ERRORendendend