Skip to content

Commit

Permalink
Add error message for uuid_v1? uuid_v2? uuid_v3? and uuid_v5? (#474)
Browse files Browse the repository at this point in the history
  • Loading branch information
spyroska authored Nov 20, 2024
1 parent c25862f commit 8cb064f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 1 deletion.
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

0 comments on commit 8cb064f

Please sign in to comment.