Maintenance: Sync Article REST API capabilities with the ones of the frontend.
This commit is contained in:
parent
f0462d4c20
commit
28944de180
3 changed files with 24 additions and 9 deletions
|
@ -101,11 +101,18 @@ class TicketArticlesController < ApplicationController
|
|||
article = Ticket::Article.find(params[:id])
|
||||
authorize!(article)
|
||||
|
||||
clean_params = Ticket::Article.association_name_to_id_convert(params)
|
||||
clean_params = Ticket::Article.param_cleanup(clean_params, true)
|
||||
|
||||
# only apply preferences changes (keep not updated keys/values)
|
||||
clean_params = article.param_preferences_merge(clean_params)
|
||||
# only update internal and highlight info
|
||||
clean_params = {}
|
||||
if !params[:internal].nil?
|
||||
clean_params[:internal] = params[:internal]
|
||||
end
|
||||
if params.dig(:preferences, :highlight).present?
|
||||
clean_params = article.param_preferences_merge(clean_params.merge(
|
||||
preferences: {
|
||||
highlight: params[:preferences][:highlight].to_s
|
||||
}
|
||||
))
|
||||
end
|
||||
|
||||
article.update!(clean_params)
|
||||
|
||||
|
|
|
@ -118,8 +118,10 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
|
|||
content_type: 'text/plain',
|
||||
body: 'some body',
|
||||
type: 'note',
|
||||
internal: false,
|
||||
preferences: {
|
||||
some_key1: 123,
|
||||
highlight: '123',
|
||||
},
|
||||
}
|
||||
post '/api/v1/ticket_articles', params: params, as: :json
|
||||
|
@ -127,28 +129,34 @@ AAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO
|
|||
expect(json_response).to be_a_kind_of(Hash)
|
||||
expect(json_response['subject']).to be_nil
|
||||
expect(json_response['body']).to eq('some body')
|
||||
expect(json_response['internal']).to eq(false)
|
||||
expect(json_response['content_type']).to eq('text/plain')
|
||||
expect(json_response['updated_by_id']).to eq(agent.id)
|
||||
expect(json_response['created_by_id']).to eq(agent.id)
|
||||
expect(json_response['preferences']['some_key1']).to eq(123)
|
||||
expect(json_response['preferences']['highlight']).to eq('123')
|
||||
expect(ticket.articles.count).to eq(5)
|
||||
|
||||
params = {
|
||||
body: 'some body 2',
|
||||
internal: true,
|
||||
preferences: {
|
||||
some_key2: 'abc',
|
||||
highlight: '234',
|
||||
},
|
||||
}
|
||||
put "/api/v1/ticket_articles/#{json_response['id']}", params: params, as: :json
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(json_response).to be_a_kind_of(Hash)
|
||||
expect(json_response['subject']).to be_nil
|
||||
expect(json_response['body']).to eq('some body 2')
|
||||
expect(json_response['body']).not_to eq('some body 2')
|
||||
expect(json_response['internal']).to eq(true)
|
||||
expect(json_response['content_type']).to eq('text/plain')
|
||||
expect(json_response['updated_by_id']).to eq(agent.id)
|
||||
expect(json_response['created_by_id']).to eq(agent.id)
|
||||
expect(json_response['preferences']['some_key1']).to eq(123)
|
||||
expect(json_response['preferences']['some_key2']).to eq('abc')
|
||||
expect(json_response['preferences']['some_key2']).not_to eq('abc')
|
||||
expect(json_response['preferences']['highlight']).to eq('234')
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -902,7 +902,7 @@ RSpec.describe 'Ticket', type: :request do
|
|||
expect(json_response).to be_a_kind_of(Hash)
|
||||
expect(json_response['ticket_id']).to eq(ticket.id)
|
||||
expect(json_response['from']).to eq(%("Tickets Agent via #{ticket_group.email_address.realname}" <#{ticket_group.email_address.email}>))
|
||||
expect(json_response['subject']).to eq('new subject')
|
||||
expect(json_response['subject']).not_to eq('new subject')
|
||||
expect(json_response['body']).to eq('some body')
|
||||
expect(json_response['content_type']).to eq('text/plain')
|
||||
expect(json_response['internal']).to eq(true)
|
||||
|
@ -991,7 +991,7 @@ RSpec.describe 'Ticket', type: :request do
|
|||
expect(json_response).to be_a_kind_of(Hash)
|
||||
expect(json_response['ticket_id']).to eq(ticket.id)
|
||||
expect(json_response['from']).to eq('Tickets Admin')
|
||||
expect(json_response['subject']).to eq('new subject')
|
||||
expect(json_response['subject']).not_to eq('new subject')
|
||||
expect(json_response['body']).to eq('some body')
|
||||
expect(json_response['content_type']).to eq('text/plain')
|
||||
expect(json_response['internal']).to eq(true)
|
||||
|
|
Loading…
Reference in a new issue