Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ledermann committed Dec 11, 2023
1 parent b973830 commit e19cfad
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions spec/lib/senec/local/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@
end
end

context 'when body is customized', vcr: 'local/request-custom' do
subject(:request) do
context 'when body is customized' do
let(:request) do
described_class.new(
connection:,
body: {
Expand All @@ -176,19 +176,36 @@
end

describe '#get' do
context 'when key exists' do
context 'when key exists', vcr: 'local/request-custom' do
subject(:get) { request.get('WIZARD', 'PWRCFG_PEAK_PV_POWER') }

it { is_expected.to be_a(Float) }
end

context 'when key does not exist' do
context 'when key does not exist', vcr: 'local/request-custom' do
subject(:get) { request.get('foo', 'bar') }

it 'raises an error' do
expect { get }.to raise_error(Senec::Local::Error, 'Value missing for foo.bar')
end
end

context 'when value cannot be decoded' do
subject(:get) { request.get('WIZARD', 'PWRCFG_PEAK_PV_POWER') }

before do
stub_request(:any, "#{connection.url}#{request.path}").to_return(body: {
'WIZARD' => {
'PWRCFG_PEAK_PV_POWER' => 'invalid'
}
}.to_json)
end

it 'raises an error' do
expect { get }.to raise_error(Senec::Local::Error,
"Decoding failed for WIZARD.PWRCFG_PEAK_PV_POWER: Unknown value 'invalid'",)
end
end
end
end
end

0 comments on commit e19cfad

Please sign in to comment.