Skip to content

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

tests[Op#50737]: Add New File storage feature specs

Kabiru Mwenja55bd6e6a6524
diff --git a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
index 02c05533ce2..9dd1a2088f7 100644
--- a/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
+++ b/modules/storages/app/controllers/storages/admin/oauth_clients_controller.rb
@@ -159,7 +159,6 @@ class Storages::Admin::OAuthClientsController < ApplicationController
end
def delete_current_oauth_client
- @previous_oauth_client_present = @storage.oauth_client.present?
::OAuthClients::DeleteService.new(user: User.current, model: @storage.oauth_client).call if @storage.oauth_client
end
end
diff --git a/modules/storages/spec/features/admin_storages_spec.rb b/modules/storages/spec/features/admin_storages_spec.rb
index 868dd8ea166..37fa86bb4cb 100644
--- a/modules/storages/spec/features/admin_storages_spec.rb
+++ b/modules/storages/spec/features/admin_storages_spec.rb
@@ -89,6 +89,194 @@ RSpec.describe 'Admin storages',
end
end
+ describe 'New file storage', with_flag: { storage_primer_design: true } do
+ context 'with Nextcloud Storage' do
+ it 'renders a Nextcloud specific multi-step form', :webmock do
+ visit admin_settings_storages_path
+
+ within('.blankslate') { click_link("Storage") }
+ expect(page).to have_current_path(new_admin_settings_storage_path)
+
+ aggregate_failures 'Select provider view' do
+ # General information
+ expect(page).to have_select('storages_storage[provider_type]', with_options: %w[Nextcloud OneDrive/SharePoint])
+
+ # Select Nextcloud
+ select('Nextcloud', from: 'storages_storage[provider_type]')
+ click_button('Save and continue')
+
+ # OAuth application
+ expect(page).to have_test_selector('storage-openproject-oauth-label', text: 'OpenProject OAuth')
+ expect(page).to have_test_selector('label-openproject_oauth_application_configured-status', text: 'Incomplete')
+
+ # OAuth client
+ expect(page).to have_test_selector('storage-oauth-client-label', text: 'Nextcloud OAuth')
+ expect(page).to have_test_selector('label-storage_oauth_client_configured-status', text: 'Incomplete')
+ expect(page).to have_test_selector('storage-oauth-client-id-description',
+ text: "Allow OpenProject to access Nextcloud data using OAuth.")
+
+ # Automatically managed project folders
+ expect(page).to have_test_selector('storage-managed-project-folders-label',
+ text: 'Automatically managed folders')
+ expect(page).to have_test_selector('label-managed-project-folders-status', text: 'Incomplete')
+ expect(page).to have_test_selector('storage-automatically-managed-project-folders-description',
+ text: 'Let OpenProject create folders per project automatically.')
+ end
+
+ aggregate_failures 'General information' do
+ within_test_selector('storage-general-info-form') do
+ fill_in 'storages_nextcloud_storage_name', with: 'My Nextcloud'
+ click_button 'Save and continue'
+
+ expect(page).to have_text("Host is not a valid URL.")
+
+ mock_server_capabilities_response("https://example.com")
+ mock_server_config_check_response("https://example.com")
+ fill_in 'storages_nextcloud_storage_host', with: 'https://example.com'
+ click_button 'Save and continue'
+ end
+
+ expect(page).to have_test_selector('label-host_name_configured-status', text: 'Completed')
+ expect(page).to have_test_selector('storage-description', text: "Nextcloud - My Nextcloud - https://example.com")
+ end
+
+ aggregate_failures 'OAuth application' do
+ within_test_selector('storage-openproject-oauth-application-form') do
+ warning_section = find_test_selector('storage-openproject_oauth_application_warning')
+ expect(warning_section).to have_text('The client secret value will not be accessible again after you close ' \
+ 'this window. Please copy these values into the Nextcloud ' \
+ 'OpenProject Integration settings.')
+ expect(warning_section).to have_link('Nextcloud OpenProject Integration settings',
+ href: "https://example.com/settings/admin/openproject")
+
+ storage = Storages::NextcloudStorage.find_by(host: 'https://example.com')
+ expect(page).to have_css('#openproject_oauth_application_uid',
+ value: storage.reload.oauth_application.uid)
+ expect(page).to have_css('#openproject_oauth_application_secret',
+ value: storage.reload.oauth_application.secret)
+
+ click_link 'Done, continue'
+ end
+ end
+
+ aggregate_failures 'OAuth Client' do
+ within_test_selector('storage-oauth-client-form') do
+ # With null values, submit button should be disabled
+ expect(page).to have_css('#oauth_client_client_id', value: '')
+ expect(page).to have_css('#oauth_client_client_secret', value: '')
+ expect(find_test_selector('storage-oauth-client-submit-button')).to be_disabled
+
+ # Happy path - Submit valid values
+ fill_in 'oauth_client_client_id', with: '1234567890'
+ fill_in 'oauth_client_client_secret', with: '0987654321'
+ expect(find_test_selector('storage-oauth-client-submit-button')).not_to be_disabled
+ click_button 'Save and continue'
+ end
+
+ expect(page).to have_test_selector('label-storage_oauth_client_configured-status', text: 'Completed')
+ expect(page).to have_test_selector('storage-oauth-client-id-description', text: "OAuth Client ID: 1234567890")
+ end
+
+ aggregate_failures 'Automatically managed project folders' do
+ within_test_selector('storage-automatically-managed-project-folders-form') do
+ automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')
+ application_password_input = page.find_by_id('storages_nextcloud_storage_password')
+ expect(automatically_managed_switch).to be_checked
+ expect(application_password_input.value).to be_empty
+
+ # Clicking submit with application password empty should show an error
+ click_button('Done, complete setup')
+ expect(page).to have_text("Password can't be blank.")
+
+ # Test the error path for an invalid storage password.
+ # Mock a valid response (=401) for example.com, so the password validation should fail
+ mock_nextcloud_application_credentials_validation('https://example.com', password: "1234567890",
+ response_code: 401)
+ automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')
+ expect(automatically_managed_switch).to be_checked
+ fill_in 'storages_nextcloud_storage_password', with: "1234567890"
+ # Clicking submit with application password empty should show an error
+ click_button('Done, complete setup')
+ expect(page).to have_text("Password is not valid.")
+
+ # Test the happy path for a valid storage password.
+ # Mock a valid response (=200) for example.com, so the password validation should succeed
+ # Fill in application password and submit
+ mock_nextcloud_application_credentials_validation('https://example.com', password: "1234567890")
+ automatically_managed_switch = page.find('[name="storages_nextcloud_storage[automatically_managed]"]')
+ expect(automatically_managed_switch).to be_checked
+ fill_in 'storages_nextcloud_storage_password', with: "1234567890"
+ click_button('Done, complete setup')
+ end
+
+ expect(page).to have_current_path(admin_settings_storages_path)
+ expect(page).to have_text("Storage connected successfully! Remember to activate the module and the specific " \
+ "storage in the project settings of each desired project to use it.")
+ end
+ end
+ end
+
+ context 'with OneDrive Storage' do
+ it 'renders a One Drive specific multi-step form', :webmock do
+ visit admin_settings_storages_path
+
+ within('.PageHeader') { click_link("Storage") }
+ expect(page).to have_current_path(new_admin_settings_storage_path)
+
+ aggregate_failures 'Select provider view' do
+ # General information
+ expect(page).to have_select('storages_storage[provider_type]', with_options: %w[Nextcloud OneDrive/SharePoint])
+
+ # Select OneDrive
+ select('OneDrive/SharePoint', from: 'storages_storage[provider_type]')
+ click_button('Save and continue')
+
+ # OAuth client
+ expect(page).to have_test_selector('storage-oauth-client-label', text: 'Azure OAuth')
+ expect(page).to have_test_selector('label-storage_oauth_client_configured-status', text: 'Incomplete')
+ expect(page).to have_test_selector('storage-oauth-client-id-description',
+ text: "Allow OpenProject to access Azure data using OAuth " \
+ "to connect OneDrive/Sharepoint.")
+ end
+
+ aggregate_failures 'General information' do
+ within_test_selector('storage-general-info-form') do
+ fill_in 'storages_one_drive_storage_name', with: 'My OneDrive'
+ click_button 'Save and continue'
+
+ expect(page).to have_text("Drive can't be blank.")
+
+ fill_in 'storages_one_drive_storage_drive_id', with: '1234567890'
+ click_button 'Save and continue'
+ end
+
+ expect(page).to have_test_selector('label-host_name_configured-storage_tenant_drive_configured-status',
+ text: 'Completed')
+ expect(page).to have_test_selector('storage-description', text: 'OneDrive/SharePoint - My OneDrive')
+ end
+
+ aggregate_failures 'OAuth Client' do
+ within_test_selector('storage-oauth-client-form') do
+ # With null values, submit button should be disabled
+ expect(page).to have_css('#oauth_client_client_id', value: '')
+ expect(page).to have_css('#oauth_client_client_secret', value: '')
+ expect(find_test_selector('storage-oauth-client-submit-button')).to be_disabled
+
+ # Happy path - Submit valid values
+ fill_in 'oauth_client_client_id', with: '1234567890'
+ fill_in 'oauth_client_client_secret', with: '0987654321'
+ expect(find_test_selector('storage-oauth-client-submit-button')).not_to be_disabled
+ click_button 'Save and continue'
+ end
+
+ expect(page).to have_current_path(admin_settings_storages_path)
+ expect(page).to have_text("Storage connected successfully! Remember to activate the module and the specific " \
+ "storage in the project settings of each desired project to use it.")
+ end
+ end
+ end
+ end
+
describe 'File storage edit view', with_flag: { storage_primer_design: true } do
it 'renders a delete button' do
storage = create(:nextcloud_storage, name: "Foo Nextcloud")