Skip to content

Commit

Permalink
Added check to show page for missing saved settings
Browse files Browse the repository at this point in the history
  • Loading branch information
abujeda committed Mar 22, 2024
1 parent 1ea485c commit 55578d4
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ def show
set_app_groups
set_saved_settings

settings_params = settings_request_params
app_token = settings_params[:token]
settings_name = settings_params[:id]
settings_values = bc_templates(app_token).fetch(settings_name.to_sym, {})
request_params = settings_request_params
app_token = request_params[:token]
settings_name = request_params[:id]
settings_values = bc_templates(app_token)[settings_name.to_sym]
if settings_values.nil?
redirect_to new_batch_connect_session_context_path(token: app_token),
alert: t('dashboard.bc_saved_settings.missing_settings')
return
end

@settings = BatchConnect::Settings.new(app_token, settings_name, settings_values)
if @settings.outdated?
flash.now[:alert] = t('dashboard.bc_saved_settings.outdated_message', app_title: @settings.app.title)
Expand All @@ -20,9 +26,9 @@ def show

# DELETE /batch_connect/<app_token>/settings/<settings_name>
def destroy
settings_params = settings_request_params
app_token = settings_params[:token]
settings_name = settings_params[:id]
request_params = settings_request_params
app_token = request_params[:token]
settings_name = request_params[:id]
delete_bc_template(app_token, settings_name)
redirect_to new_batch_connect_session_context_path(token: app_token),
notice: t('dashboard.bc_saved_settings.deleted_message', settings_name: settings_name)
Expand Down
1 change: 1 addition & 0 deletions apps/dashboard/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ en:
bc_saved_settings:
title: "Saved Settings"
no_settings_title: "You have no saved settings."
missing_settings: "Selected saved settings not found."
launch_label: "Launch"
launch_title: "Launch %{app_title} with %{settings_name} parameters"
delete_label: "Delete"
Expand Down
54 changes: 54 additions & 0 deletions apps/dashboard/test/models/batch_connect/settings_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# frozen_string_literal: true

require 'test_helper'

module BatchConnect
class SettingsTest < ActionView::TestCase

test 'can set values' do
target = BatchConnect::Settings.new('app/token', 'settings name', { name: 'value' })

assert_equal('app/token', target.token)
assert_equal('settings name', target.name)
assert_equal({ name: 'value' }, target.values)
end

test 'app returns BatchConnect::App based on token' do
target = BatchConnect::Settings.new('sys/token', 'settings name', { name: 'value' })

assert_instance_of(BatchConnect::App, target.app)
assert_equal('sys/token', target.app.token)
end

test 'outdated? returns true when settings keys do not match app attribute ids' do
app_token = 'sys/token'
setting_values = { bc_account: 'engineering', bc_cluster: 'test', bc_hours: 4 }
target = BatchConnect::Settings.new(app_token, 'settings name', setting_values)
create_app(app_token, ['bc_account', 'bc_cluster'])
assert_equal(true, target.outdated?)

setting_values = { bc_account: 'engineering' }
target = BatchConnect::Settings.new(app_token, 'settings name', setting_values)
create_app(app_token, ['bc_account', 'bc_cluster'])
assert_equal(true, target.outdated?)
end

test 'outdated? returns false when settings keys match app attribute ids' do
app_token = 'sys/token'
setting_values = { bc_account: 'engineering', bc_cluster: 'test' }
target = BatchConnect::Settings.new(app_token, 'settings name', setting_values)
create_app(app_token, ['bc_account', 'bc_cluster'])

assert_equal(false, target.outdated?)
end

private

def create_app(token, attributes)
router = Router.router_from_token(token)
app = BatchConnect::App.new(router: router)
app.stubs(:attributes).returns(attributes.map { |id| SmartAttributes::AttributeFactory.build(id, {}) })
BatchConnect::App.stubs(:from_token).with(app.token).returns(app)
end
end
end

0 comments on commit 55578d4

Please sign in to comment.