-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
188 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,76 @@ | ||
# frozen_string_literal: true | ||
|
||
RSpec.describe ClientsValidator do | ||
subject(:validate) { described_class.new(params).validate! } | ||
|
||
context 'when all parameters are valid' do | ||
let(:params) do | ||
{ | ||
'address' => 's', | ||
'private_key' => 'a', | ||
'public_key' => 'b', | ||
'preshared_key' => 'c', | ||
'enable' => false, | ||
'data' => {} | ||
} | ||
end | ||
|
||
it 'return true' do | ||
expect(validate).to be(true) | ||
end | ||
end | ||
|
||
context 'when parameters are empty' do | ||
let(:params) do | ||
{} | ||
end | ||
|
||
it 'return true' do | ||
expect(validate).to be(true) | ||
end | ||
end | ||
|
||
context 'when all parameters are valid but there are extra ones' do | ||
let(:params) do | ||
{ | ||
'address' => 's', | ||
'private_key' => 'a', | ||
'public_key' => 'b', | ||
'preshared_key' => 'c', | ||
'enable' => false, | ||
'data' => {}, | ||
'extra' => 123 | ||
} | ||
end | ||
|
||
it 'raises a validation error' do | ||
expect { validate }.to raise_error(JSON::Schema::ValidationError) | ||
end | ||
end | ||
|
||
context 'when one parameter is not valid' do | ||
let(:params) do | ||
{ | ||
'enable' => 'false' | ||
} | ||
end | ||
|
||
it 'raises a validation error' do | ||
expect { validate }.to raise_error(JSON::Schema::ValidationError) | ||
end | ||
end | ||
|
||
context 'when there were several parameters and they were valid' do | ||
let(:params) do | ||
{ | ||
'preshared_key' => 'c', | ||
'enable' => false, | ||
'data' => {} | ||
} | ||
end | ||
|
||
it 'return true' do | ||
expect(validate).to be(true) | ||
end | ||
end | ||
end |