Skip to content

Commit

Permalink
Add more helpful error if the format is not found
Browse files Browse the repository at this point in the history
  • Loading branch information
pezholio committed Jun 24, 2024
1 parent 983d95e commit 0b74127
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/govuk_schemas/random_content_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,17 @@ def string_for_type(type)
when "email"
Faker::Internet.email
else
raise "Unknown attribute type `#{type}`"
raise <<~DOC
Unsupported JSON schema type `#{type}`
Supported formats are:
- date-time
- uri
- email
This can be fixed by adding a type to the `string_for_type` method in
`lib/govuk_schemas/random_content_generator.rb` in https://github.com/alphagov/govuk_schemas
DOC
end
end

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

expect(response).to eq(email)
end

it "raises an error if the type is not present" do
expect {
GovukSchemas::RandomContentGenerator.new.string_for_type("duration")
}.to raise_error(/Unsupported JSON schema type `duration`/)
end
end

describe ".uri" do
Expand Down

0 comments on commit 0b74127

Please sign in to comment.