Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tooyosi committed Oct 7, 2024
1 parent b03e84d commit a4eca6f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
4 changes: 2 additions & 2 deletions app/assets/javascripts/views/forms/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ document.addEventListener("DOMContentLoaded", function () {

if(hidden_input){
hidden_input.classList.remove('hidden');
};
}

var visible_input = document.getElementById(visible_input_id);
if(visible_input){
visible_input.classList.add('hidden');
};
}
};

if (is_reducer_form) {
Expand Down
5 changes: 4 additions & 1 deletion app/controllers/reducers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@ def record_not_valid(exception)
def remove_unwanted_config_key(param_object)
if param_object[:topic] == 'reduce_by_subject'
param_object[:subject_reducer_keys] = nil
elsif
elsif param_object[:topic] == 'reduce_by_user'
param_object[:user_reducer_keys] = nil
else
param_object[:subject_reducer_keys] = nil
param_object[:user_reducer_keys] = nil
end
end
Expand Down
28 changes: 28 additions & 0 deletions spec/controllers/reducers_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@
reducer: {key: nil, type: 'external'}}
expect(response.status).to eq(200)
end

context 'when topic is reduce_by_subject' do
it 'sets subject_reducer_keys to nil' do
put :update, params: {
workflow_id: workflow.id,
id: reducer.id,
reducer: {url: 'https://example.org/2', user_reducer_keys: 'user_reducer_keys_value', subject_reducer_keys: 'subject_reducer_keys',topic: 'reduce_by_subject'},
}

reducer.reload
expect(reducer.subject_reducer_keys).to be_nil
expect(reducer.user_reducer_keys).to eq('user_reducer_keys_value')
end
end

context 'when topic is not reduce_by_subject' do
it 'sets user_reducer_keys to nil' do
put :update, params: {
workflow_id: workflow.id,
id: reducer.id,
reducer: {url: 'https://example.org/2', user_reducer_keys: 'user_reducer_keys_value', subject_reducer_keys: 'subject_reducer_keys_value',topic: 'reduce_by_user'},
}

reducer.reload
expect(reducer.subject_reducer_keys).to eq('subject_reducer_keys_value')
expect(reducer.user_reducer_keys).to be_nil
end
end
end
end
end

0 comments on commit a4eca6f

Please sign in to comment.