From 7fdfd4c86950fb7eb1bc40c29cde77fe76ce60be Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Thu, 4 Jul 2024 15:24:09 +0100 Subject: [PATCH 1/2] Use the comment property to set the Zendesk ticket description This was causing an error GdsApi::HTTPUnprocessableEntity: URL: http://support-api/support-tickets Response body: {"status":"error","errors":{"description":["can't be blank"]}} The docs say to use `comment` instead. https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#description-and-first-comment "When creating a ticket, use the comment property to set the ticket description, which is also the first comment. Important: Do not use the description property to set the first comment. The property is for reading purposes only. While it's possible to use the property to set the first comment, the functionality has limitations and is provided to support existing implementations." Ticket Comments are represented as JSON objects. They have a multiple properties. The comment string needs to be in the "body" property. See https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/ --- app/models/support_ticket.rb | 4 +++- spec/models/support_ticket_spec.rb | 20 ++++++-------------- spec/requests/support_tickets_spec.rb | 10 +++------- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/app/models/support_ticket.rb b/app/models/support_ticket.rb index 5af34b14..ba4d45b2 100644 --- a/app/models/support_ticket.rb +++ b/app/models/support_ticket.rb @@ -14,7 +14,9 @@ def attributes { "subject" => subject, "tags" => tags, - "body" => ticket_body, + "comment" => { + "body" => description, + }, } end diff --git a/spec/models/support_ticket_spec.rb b/spec/models/support_ticket_spec.rb index 219b72ab..c48ee690 100644 --- a/spec/models/support_ticket_spec.rb +++ b/spec/models/support_ticket_spec.rb @@ -28,13 +28,9 @@ expect(support_ticket.attributes).to eq( "subject" => "Feedback for app", "tags" => %w[app_name], - "body" => <<-TICKET_BODY.strip_heredoc, - [User agent] - Safari - - [Details] - Ticket details go here. - TICKET_BODY + "comment" => { + "body" => "Ticket details go here.", + }, ) end @@ -48,13 +44,9 @@ expect(support_ticket.attributes).to eq( "subject" => "Feedback for app", "tags" => %w[app_name], - "body" => <<-TICKET_BODY.strip_heredoc, - [User agent] - - - [Details] - Ticket details go here. - TICKET_BODY + "comment" => { + "body" => "Ticket details go here.", + }, ) end end diff --git a/spec/requests/support_tickets_spec.rb b/spec/requests/support_tickets_spec.rb index 129c3eea..7e7f05c5 100644 --- a/spec/requests/support_tickets_spec.rb +++ b/spec/requests/support_tickets_spec.rb @@ -20,13 +20,9 @@ zendesk_request = expect_zendesk_to_receive_ticket( "subject" => "Feedback for app", "tags" => %w[app_name], - "body" => <<-TICKET_BODY.strip_heredoc, - [User agent] - Safari - - [Details] - Ticket details go here. - TICKET_BODY + "comment" => { + "body" => "Ticket details go here.", + }, ) post "/support-tickets", From 029d633296cf470f4fe64b1a38b511a6a72c2a67 Mon Sep 17 00:00:00 2001 From: Aga Dufrat Date: Wed, 10 Jul 2024 20:46:44 +0100 Subject: [PATCH 2/2] Don't format ticket body in SupportTicket We anticipate that the inbound API call will have the body formatted so we don't need to do it here. `user_agent` attribute should also be removed from support_tickets_controller. Since it requires update to the Pact test in a another repo it will be removed in a follow up PR. --- app/models/support_ticket.rb | 13 +------------ spec/models/support_ticket_spec.rb | 1 - spec/requests/support_tickets_spec.rb | 2 -- 3 files changed, 1 insertion(+), 15 deletions(-) diff --git a/app/models/support_ticket.rb b/app/models/support_ticket.rb index ba4d45b2..94923dde 100644 --- a/app/models/support_ticket.rb +++ b/app/models/support_ticket.rb @@ -6,7 +6,6 @@ class SupportTicket def initialize(attributes) @subject = attributes.fetch(:subject, nil) @tags = attributes.fetch(:tags, nil) - @user_agent = attributes.fetch(:user_agent, nil) @description = attributes.fetch(:description, nil) end @@ -22,15 +21,5 @@ def attributes private - attr_reader :subject, :tags, :user_agent, :description - - def ticket_body - <<-TICKET_BODY.strip_heredoc - [User agent] - #{user_agent} - - [Details] - #{description} - TICKET_BODY - end + attr_reader :subject, :tags, :description end diff --git a/spec/models/support_ticket_spec.rb b/spec/models/support_ticket_spec.rb index c48ee690..6d408e30 100644 --- a/spec/models/support_ticket_spec.rb +++ b/spec/models/support_ticket_spec.rb @@ -21,7 +21,6 @@ support_ticket = described_class.new( subject: "Feedback for app", tags: %w[app_name], - user_agent: "Safari", description: "Ticket details go here.", ) diff --git a/spec/requests/support_tickets_spec.rb b/spec/requests/support_tickets_spec.rb index 7e7f05c5..f4fa22aa 100644 --- a/spec/requests/support_tickets_spec.rb +++ b/spec/requests/support_tickets_spec.rb @@ -8,7 +8,6 @@ params: { subject: "Feedback for app", tags: %w[app_name], - user_agent: "Safari", description: "Ticket details go here.", } @@ -29,7 +28,6 @@ params: { subject: "Feedback for app", tags: %w[app_name], - user_agent: "Safari", description: "Ticket details go here.", }