Skip to content

Commit

Permalink
add tests for aliased param transforms/validations
Browse files Browse the repository at this point in the history
  • Loading branch information
ezekg committed Jan 5, 2024
1 parent cd58129 commit 8ae7b34
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions spec/typed_params/processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,30 @@
expect(params[:bar]).to be nil
expect(params[:baz]).to be nil
end

it 'should alias param with type mismatch' do
schema = TypedParams::Schema.new(type: :hash) { param :foo, type: :integer, alias: :bar }
params = TypedParams::Parameterizer.new(schema:).call(value: { bar: 'baz' })
processor = TypedParams::Processor.new(schema:)

expect { processor.call(params) }.to raise_error TypedParams::InvalidParameterError
end

it 'should alias param with validation' do
schema = TypedParams::Schema.new(type: :hash) { param :foo, type: :integer, alias: :bar, validate: -> v { false } }
params = TypedParams::Parameterizer.new(schema:).call(value: { bar: 1 })
processor = TypedParams::Processor.new(schema:)

expect { processor.call(params) }.to raise_error TypedParams::InvalidParameterError
end

it 'should alias param with transform' do
schema = TypedParams::Schema.new(type: :hash) { param :foo, type: :integer, alias: :bar, transform: -> k, v { [k, v + 1] } }
params = TypedParams::Parameterizer.new(schema:).call(value: { bar: 1 })
processor = TypedParams::Processor.new(schema:)

processor.call(params)

expect(params[:foo]).to satisfy { _1 in TypedParams::Parameter(value: 2) }
end
end

0 comments on commit 8ae7b34

Please sign in to comment.