Skip to content
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

[FINE] Union edit service_dialog API call #16971

Merged
merged 1 commit into from
Feb 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/controllers/api/service_dialogs_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ def create_resource(_type, _id, data)
def edit_resource(type, id, data)
service_dialog = resource_search(id, type, Dialog)
begin
service_dialog.update!(data.except('content'))
service_dialog.update_tabs(data['content']['dialog_tabs']) if data['content']
$api_log.warn("Both 'dialog_tabs':[...] and 'content':{'dialog_tabs':[...]} were specified. 'content':{'dialog_tabs':[...]} will be ignored.") if data.key?('dialog_tabs') && data['content'].try(:key?, 'dialog_tabs')
service_dialog.update_tabs(data['dialog_tabs'] || data['content']['dialog_tabs']) if data['dialog_tabs'] || data['content']
service_dialog.update!(data.except('dialog_tabs', 'content'))
rescue => err
raise BadRequestError, "Failed to update service dialog - #{err}"
end
Expand Down
78 changes: 78 additions & 0 deletions spec/requests/api/service_dialogs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,84 @@
expect(response.parsed_body).to include(expected)
end

context 'using call with :content key' do
it 'POST /api/service_dialogs/:id updates a service dialog' do
api_basic_authorize collection_action_identifier(:service_dialogs, :edit)
dialog_tab = dialog.dialog_tabs.first
dialog_group = dialog_tab.dialog_groups.first
dialog_field = dialog_group.dialog_fields.first

updated_dialog = {
'label' => 'updated label',
'content' => {
'dialog_tabs' => [
'id' => dialog_tab.id.to_s,
'label' => 'updated tab label',
'dialog_groups' => [
{
'id' => dialog_group.id.to_s,
'dialog_fields' => [
{ 'id' => dialog_field.id.to_s }
]
}
]
]
}
}

expected = {
'href' => a_string_including(service_dialogs_url(dialog.id)),
'id' => dialog.id,
'label' => 'updated label'
}

expect do
run_post(service_dialogs_url(dialog.id), gen_request(:edit, updated_dialog))
dialog.reload
end.to change(dialog, :content)
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

context 'using call without :content key' do
it 'POST /api/service_dialogs/:id updates a service dialog' do
api_basic_authorize collection_action_identifier(:service_dialogs, :edit)
dialog_tab = dialog.dialog_tabs.first
dialog_group = dialog_tab.dialog_groups.first
dialog_field = dialog_group.dialog_fields.first

updated_dialog = {
'label' => 'updated label',
'dialog_tabs' => [
'id' => dialog_tab.id.to_s,
'label' => 'updated tab label',
'dialog_groups' => [
{
'id' => dialog_group.id.to_s,
'dialog_fields' => [
{ 'id' => dialog_field.id.to_s }
]
}
]
]
}

expected = {
'href' => a_string_including(service_dialogs_url(dialog.id)),
'id' => dialog.id,
'label' => 'updated label'
}

expect do
run_post(service_dialogs_url(dialog.id), gen_request(:edit, updated_dialog))
dialog.reload
end.to change(dialog, :content)
expect(response).to have_http_status(:ok)
expect(response.parsed_body).to include(expected)
end
end

it 'POST /api/service_dialogs updates multiple service dialog' do
dialog2 = FactoryGirl.create(:dialog_with_tab_and_group_and_field)

Expand Down