Skip to content

Commit

Permalink
Update support-api test helpers
Browse files Browse the repository at this point in the history
We should also stub when an invalid post request is sent to the
`/support-tickets` endpoint.
  • Loading branch information
deborahchua committed Jun 5, 2024
1 parent 61e46ec commit 9aabf9d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 9 deletions.
6 changes: 2 additions & 4 deletions lib/gds_api/support_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +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)
post_json("#{endpoint}/support-tickets", params)
Expand Down
10 changes: 8 additions & 2 deletions lib/gds_api/test_helpers/support_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,16 @@ def stub_support_api_feedback_export_request(id, response_body = nil)
.to_return(status: 200, body: response_body.to_json)
end

def stub_support_api_raise_support_ticket(params)
def stub_support_api_valid_raise_support_ticket(params)
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/support-tickets")
post_stub.with(body: params)
post_stub.to_return(status: 201)
post_stub.to_return(status: 201, body: { status: "success" }.to_json)
end

def stub_support_api_invalid_raise_support_ticket(params)
post_stub = stub_http_request(:post, "#{SUPPORT_API_ENDPOINT}/support-tickets")
post_stub.with(body: params)
post_stub.to_return(status: 422, body: { status: "error" }.to_json)
end

def stub_any_support_api_call
Expand Down
21 changes: 18 additions & 3 deletions test/support_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,28 @@
end

describe "POST /support-tickets" do
it "makes a POST request to the support API" do
params = { subject: "Feedback for app", tags: "app_name", details: "Ticket details go here." }
stub_post = stub_support_api_raise_support_ticket(params)
it "makes a valid POST request to the support API" do
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)

assert_requested(stub_post)
end

it "makes an invalid POST request to the support API" do
params = { subject: "Ticket without body" }

stub_support_api_invalid_raise_support_ticket(params)

assert_raises GdsApi::HTTPUnprocessableEntity do
@api.raise_support_ticket(params)
end
end
end
end

0 comments on commit 9aabf9d

Please sign in to comment.