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

Add error message for uuid_v1? uuid_v2? uuid_v3? and uuid_v5? #474

Merged
merged 2 commits into from
Nov 20, 2024
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: 9 additions & 1 deletion config/errors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,17 @@ en:
default: "must be %{size} bytes long"
range: "must be within %{size_left} - %{size_right} bytes long"

uri?: "is not a valid URI"

uuid_v1?: "is not a valid UUID"

uuid_v2?: "is not a valid UUID"

uuid_v3?: "is not a valid UUID"

uuid_v4?: "is not a valid UUID"

uri?: "is not a valid URI"
uuid_v5?: "is not a valid UUID"

not:
empty?: "cannot be empty"
17 changes: 17 additions & 0 deletions spec/integration/params/predicates/uuid_v1_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe "Predicates: uuid_v1?" do
subject(:schema) do
Dry::Schema.Params do
required(:uuid).value(:string, :uuid_v1?)
end
end

it "passes with valid input" do
expect(schema.(uuid: "2e14d58e-afff-11ee-a506-0242ac120002")).to be_success
end

it "fails with invalid input" do
expect(schema.(uuid: "not-uuid").errors.to_h).to eql(uuid: ["is not a valid UUID"])
end
end
17 changes: 17 additions & 0 deletions spec/integration/params/predicates/uuid_v2_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe "Predicates: uuid_v2?" do
subject(:schema) do
Dry::Schema.Params do
required(:uuid).value(:string, :uuid_v2?)
end
end

it "passes with valid input" do
expect(schema.(uuid: "000003e8-afff-21ee-a300-325096b39f47")).to be_success
end

it "fails with invalid input" do
expect(schema.(uuid: "not-uuid").errors.to_h).to eql(uuid: ["is not a valid UUID"])
end
end
17 changes: 17 additions & 0 deletions spec/integration/params/predicates/uuid_v3_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe "Predicates: uuid_v3?" do
subject(:schema) do
Dry::Schema.Params do
required(:uuid).value(:string, :uuid_v3?)
end
end

it "passes with valid input" do
expect(schema.(uuid: "1d955abe-9522-33d5-a788-a1b186b163dc")).to be_success
end

it "fails with invalid input" do
expect(schema.(uuid: "not-uuid").errors.to_h).to eql(uuid: ["is not a valid UUID"])
end
end
17 changes: 17 additions & 0 deletions spec/integration/params/predicates/uuid_v5_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe "Predicates: uuid_v5?" do
subject(:schema) do
Dry::Schema.Params do
required(:uuid).value(:string, :uuid_v5?)
end
end

it "passes with valid input" do
expect(schema.(uuid: "601d90d0-8611-502d-b49b-86c0779b6159")).to be_success
end

it "fails with invalid input" do
expect(schema.(uuid: "not-uuid").errors.to_h).to eql(uuid: ["is not a valid UUID"])
end
end
Loading