Skip to content

Commit

Permalink
Add Pacts tests for Support API
Browse files Browse the repository at this point in the history
We expect a 201 success if the parameters provided for the
`raise_support_ticket` are valid, and a 422 error if not.
  • Loading branch information
deborahchua committed Jun 5, 2024
1 parent d7b118c commit 5fc5fd4
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 4 deletions.
5 changes: 2 additions & 3 deletions lib/gds_api/support_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ def create_global_export_request(request_details)
# SupportApi.raise_support_ticket(
# subject: "Feedback for app",
# tags: ["app_name"]
# body: {
# "User agent": "Safari",
# "Details": "Ticket details go here.",
# user_agent: "Safari",
# description: "Ticket details go here.",
# }
# )
def raise_support_ticket(params)
Expand Down
69 changes: 69 additions & 0 deletions test/pacts/support_api_pact_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
require "test_helper"
require "gds_api/support_api"

describe "GdsApi::SupportApi pact tests" do
include PactTest

describe "#raise_support_ticket" do
let(:api_client) { GdsApi::SupportApi.new(support_api_host) }

it "responds with a 201 Success if the parameters provided are valid" do
support_api
.given("the parameters are valid")
.upon_receiving("a raise ticket request")
.with(
method: :post,
path: "/support-tickets",
headers: GdsApi::JsonClient.default_request_with_json_body_headers,
body: {
subject: "Feedback for app",
tags: %w[app_name],
user_agent: "Safari",
description: "There is something wrong with this page.",
},
)
.will_respond_with(
status: 201,
body: {
status: "success",
},
headers: {
"Content-Type" => "application/json; charset=utf-8",
},
)

api_client.raise_support_ticket(
subject: "Feedback for app",
tags: %w[app_name],
user_agent: "Safari",
description: "There is something wrong with this page.",
)
end

it "responds with 422 Error when required parameters are not provided" do
support_api
.given("the required parameters are not provided")
.upon_receiving("a raise ticket request")
.with(
method: :post,
path: "/support-tickets",
headers: GdsApi::JsonClient.default_request_with_json_body_headers,
body: {
subject: "Ticket without body",
},
)
.will_respond_with(
status: 422,
body: {
status: "error",
},
)

begin
api_client.raise_support_ticket(subject: "Ticket without body")
rescue GdsApi::HTTPUnprocessableEntity
# expected outcome
end
end
end
end
7 changes: 6 additions & 1 deletion test/support_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,12 @@

describe "POST /support-tickets" do
it "makes a valid POST request to the support API" do
params = { subject: "Feedback for app", tags: "app_name", details: "Ticket details go here." }
params = {
subject: "Feedback for app",
tags: "app_name",
user_agent: "Safari",
description: "There is something wrong with this page.",
}
stub_post = stub_support_api_valid_raise_support_ticket(params)

@api.raise_support_ticket(params)
Expand Down

0 comments on commit 5fc5fd4

Please sign in to comment.