Repository navigation
Add assign custom button actions for button sets and service templates #1341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -831,6 +831,58 @@ | |
| end | ||
| end | ||
|
|
||
| describe "Service Templates add custom button" do | ||
| let(:service_template) { FactoryBot.create(:service_template, :with_provision_resource_action_and_dialog) } | ||
| let(:button) { FactoryBot.create(:custom_button, :applies_to => service_template, :userid => @user.userid) } | ||
|
|
||
| it "can add a custom button to a service template" do | ||
| api_basic_authorize action_identifier(:service_templates, :add_custom_button, :resource_actions, :post) | ||
|
|
||
| post(api_service_template_url(nil, service_template), :params => {:action => "add_custom_button", :button_id => button.id}) | ||
|
|
||
| expect(response).to have_http_status(:ok) | ||
| expect(response.parsed_body).to include("message" => "Button added to Service Template order") | ||
| expect(service_template.reload.options[:button_order]).to include("cb-#{button.id}") | ||
| end | ||
|
|
||
| it "is idempotent when adding a custom button to a service template" do | ||
| api_basic_authorize action_identifier(:service_templates, :add_custom_button, :resource_actions, :post) | ||
|
|
||
| 2.times do | ||
| post(api_service_template_url(nil, service_template), :params => {:action => "add_custom_button", :button_id => button.id}) | ||
| expect(response).to have_http_status(:ok) | ||
| end | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's good we don't add it multiple times but I'm curious if subsequent "add button" requests should fail if it's already added. I'm not sure what we do with other API endpoints when adding something already added, so it might be better to review later on and see if it makes sense based on other patterns we have. |
||
|
|
||
| expect(service_template.reload.options[:button_order]).to eq(["cb-#{button.id}"]) | ||
| end | ||
|
|
||
| it "is forbidden without appropriate role" do | ||
| api_basic_authorize | ||
|
|
||
| post(api_service_template_url(nil, service_template), :params => {:action => "add_custom_button", :button_id => button.id}) | ||
|
|
||
| expect(response).to have_http_status(:forbidden) | ||
| end | ||
|
|
||
| it "fails for an invalid service template id" do | ||
| api_basic_authorize action_identifier(:service_templates, :add_custom_button, :resource_actions, :post) | ||
|
|
||
| post(api_service_template_url(nil, 999_999), :params => {:action => "add_custom_button", :button_id => button.id}) | ||
|
|
||
| expect(response).to have_http_status(:not_found) | ||
| end | ||
|
|
||
| it "fails when adding a custom button without a button_id" do | ||
| api_basic_authorize action_identifier(:service_templates, :add_custom_button, :resource_actions, :post) | ||
|
|
||
| post(api_service_template_url(nil, service_template), :params => {:action => "add_custom_button"}) | ||
|
|
||
| expect(response).to have_http_status(:bad_request) | ||
| expect(response.parsed_body["error"]).to include("message" => a_string_including("Must specify a button_id")) | ||
| expect(service_template.reload.options[:button_order]).to be_blank | ||
| end | ||
| end | ||
|
|
||
| context "schedules subcollection" do | ||
| let!(:service_template) { FactoryBot.create(:service_template, :with_provision_resource_action_and_dialog) } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed in chat, we found that
api_actionhandles the rescue and re-raise so it's actually a better pattern to follow. So, I'm 👍 on this.