-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1275 from alphagov/add-schema-publishing-api-endp…
…oints Add `/schemas` publishing api endpoints
- Loading branch information
Showing
5 changed files
with
280 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
require "test_helper" | ||
require "gds_api/publishing_api" | ||
|
||
describe "GdsApi::PublishingApi##get_schemas_by_name pact tests" do | ||
include PactTest | ||
|
||
let(:api_client) { GdsApi::PublishingApi.new(publishing_api_host) } | ||
|
||
let(:schema) do | ||
{ | ||
"/govuk/publishing-api/content_schemas/dist/formats/email_address/publisher_v2/schema.json": { | ||
type: "object", | ||
required: %w[a], | ||
properties: { | ||
email_address: { "some" => "schema" }, | ||
}, | ||
}, | ||
} | ||
end | ||
|
||
describe "when a schema is found" do | ||
before do | ||
publishing_api | ||
.given("there is a schema for an email_address") | ||
.upon_receiving("a get schema by name request") | ||
.with( | ||
method: :get, | ||
path: "/v2/schemas/email_address", | ||
) | ||
.will_respond_with( | ||
status: 200, | ||
body: schema, | ||
) | ||
end | ||
|
||
it "returns the named schema" do | ||
response = api_client.get_schema("email_address") | ||
assert_equal(schema.to_json, response.to_json) | ||
end | ||
end | ||
|
||
describe "when a schema is not found" do | ||
before do | ||
publishing_api | ||
.given("there is not a schema for an email_address") | ||
.upon_receiving("a get schema by name request") | ||
.with( | ||
method: :get, | ||
path: "/v2/schemas/email_address", | ||
) | ||
.will_respond_with( | ||
status: 404, | ||
) | ||
end | ||
|
||
it "returns a 404 error" do | ||
assert_raises(GdsApi::HTTPNotFound) do | ||
api_client.get_schema("email_address") | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
require "test_helper" | ||
require "gds_api/publishing_api" | ||
|
||
describe "GdsApi::PublishingApi#get_schemas pact tests" do | ||
include PactTest | ||
|
||
let(:api_client) { GdsApi::PublishingApi.new(publishing_api_host) } | ||
|
||
let(:schemas) do | ||
{ | ||
"email_address": { | ||
type: "object", | ||
required: %w[a], | ||
properties: { | ||
email_address: { "some" => "schema" }, | ||
}, | ||
}, | ||
"tax_license": { | ||
type: "object", | ||
required: %w[a], | ||
properties: { | ||
tax_license: { "another" => "schema" }, | ||
}, | ||
}, | ||
} | ||
end | ||
|
||
before do | ||
publishing_api | ||
.given("there are publisher schemas") | ||
.upon_receiving("a get schemas request") | ||
.with( | ||
method: :get, | ||
path: "/v2/schemas", | ||
) | ||
.will_respond_with( | ||
status: 200, | ||
body: schemas, | ||
) | ||
end | ||
|
||
it "returns all the schemas" do | ||
response = api_client.get_schemas | ||
assert_equal(schemas.to_json, response.to_json) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters