discourse/spec/lib/validators/objects_setting_validator_spec.rb
Gabriel Grubba ebdb3de2e7
FIX: Fix ObjectsSettingValidator error message handling (#38336)
Before, when adding a `type: object` site setting, if it did not match
the schema, the only message returned was `Invalid object.`

With these changes, it is possible to understand which properties did no
match the schema
2026-03-09 14:50:17 -03:00

19 lines
714 B
Ruby

# frozen_string_literal: true
RSpec.describe ObjectsSettingValidator do
let(:schema) { { name: "test", properties: { title: { type: "string", required: true } } } }
describe "#valid_value?" do
it "returns true for valid objects" do
validator = ObjectsSettingValidator.new(schema: schema)
expect(validator.valid_value?('[{"title": "hello"}]')).to eq(true)
expect(validator.error_message).to be_nil
end
it "returns false with specific error message for invalid objects" do
validator = ObjectsSettingValidator.new(schema: schema)
expect(validator.valid_value?("[{}]")).to eq(false)
expect(validator.error_message).to include("must be present")
end
end
end