Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use "generic" schema in place of old "placeholder" #93

Merged
merged 1 commit into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions spec/lib/assert_matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ def assert(boolean, error_message); end
%w[publisher links frontend notification].each do |schema_type|
describe "#assert_valid_against_#{schema_type}_schema" do
it "detects an valid schema" do
example = GovukSchemas::RandomExample.for_schema("#{schema_type}_schema": "placeholder")
validator = GovukSchemas::Validator.new("placeholder", schema_type, example)
example = GovukSchemas::RandomExample.for_schema("#{schema_type}_schema": "generic")
validator = GovukSchemas::Validator.new("generic", schema_type, example)
expect(self).to receive(:assert).with(true, validator.error_message)

public_send("assert_valid_against_#{schema_type}_schema", example, "placeholder")
public_send("assert_valid_against_#{schema_type}_schema", example, "generic")
end

it "detects an invalid schema" do
example = { obviously_invalid: true, second_invalid_attribute: true }
validator = GovukSchemas::Validator.new("placeholder", schema_type, example)
validator = GovukSchemas::Validator.new("generic", schema_type, example)
expect(self).to receive(:assert).with(false, validator.error_message)

public_send("assert_valid_against_#{schema_type}_schema", example, "placeholder")
public_send("assert_valid_against_#{schema_type}_schema", example, "generic")
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/random_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
RSpec.describe GovukSchemas::RandomExample do
describe ".for_schema" do
it "returns a random example for a schema" do
example = GovukSchemas::RandomExample.for_schema(frontend_schema: "placeholder")
example = GovukSchemas::RandomExample.for_schema(frontend_schema: "generic")

expect(example).to be_a(Hash)
end

it "can be customised" do
example = GovukSchemas::RandomExample.for_schema(frontend_schema: "placeholder") do |hash|
example = GovukSchemas::RandomExample.for_schema(frontend_schema: "generic") do |hash|
hash.merge("base_path" => "/some-base-path")
end

Expand Down
12 changes: 6 additions & 6 deletions spec/lib/rspec_matchers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,29 @@

describe "#be_valid_against_publisher_schema" do
it "detects an valid schema" do
example = GovukSchemas::RandomExample.for_schema(publisher_schema: "placeholder")
example = GovukSchemas::RandomExample.for_schema(publisher_schema: "generic")

expect(example).to be_valid_against_publisher_schema("placeholder")
expect(example).to be_valid_against_publisher_schema("generic")
end

it "detects an invalid schema" do
example = { obviously_invalid: true }

expect(example).to_not be_valid_against_publisher_schema("placeholder")
expect(example).to_not be_valid_against_publisher_schema("generic")
end
end

describe "#be_valid_against_links_schema" do
it "detects an valid schema for links" do
example = GovukSchemas::RandomExample.for_schema(links_schema: "placeholder")
example = GovukSchemas::RandomExample.for_schema(links_schema: "generic")

expect(example).to be_valid_against_links_schema("placeholder")
expect(example).to be_valid_against_links_schema("generic")
end

it "detects an invalid schema for links" do
example = { obviously_invalid: true }

expect(example).to_not be_valid_against_links_schema("placeholder")
expect(example).to_not be_valid_against_links_schema("generic")
end
end
end
14 changes: 7 additions & 7 deletions spec/lib/validator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
RSpec.describe GovukSchemas::Validator do
describe "#valid?" do
it "detects an valid schema" do
example = GovukSchemas::RandomExample.for_schema(publisher_schema: "placeholder")
validator = described_class.new("placeholder", "publisher", example)
example = GovukSchemas::RandomExample.for_schema(publisher_schema: "generic")
validator = described_class.new("generic", "publisher", example)

expect(validator.valid?).to eq true
end

it "detects an invalid schema" do
example = { obviously_invalid: true }
validator = described_class.new("placeholder", "publisher", example)
validator = described_class.new("generic", "publisher", example)

expect(validator.valid?).to eq false
end

it "handles the payload being passed as json" do
example = GovukSchemas::RandomExample.for_schema(publisher_schema: "placeholder").to_json
validator = described_class.new("placeholder", "publisher", example)
example = GovukSchemas::RandomExample.for_schema(publisher_schema: "generic").to_json
validator = described_class.new("generic", "publisher", example)

expect(validator.valid?).to eq true
end
Expand All @@ -28,7 +28,7 @@
describe "#error_message" do
let(:start_of_error_message) do
<<~DOC
expected the payload to be valid against the 'placeholder' schema:
expected the payload to be valid against the 'generic' schema:

{
"obviously_invalid": true
Expand All @@ -40,7 +40,7 @@

it "constructs an error message based on the schema_name, payload and errors" do
example = { obviously_invalid: true }
validator = described_class.new("placeholder", "publisher", example)
validator = described_class.new("generic", "publisher", example)

expect(validator.error_message).to include start_of_error_message
expect(validator.error_message).to match(/- The item did not contain a required property of '([a-z_]+)'/i)
Expand Down