Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions spec/site/tlc/invalid_command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,98 @@
end
end
end

context 'receiving a command with invalid parameter values' do

# Verify that site returns current values when receiving a command
# with invalid parameter values that cause the command to fail
#
# 1. Given the site is connected
# 2. When we send a valid M0002 command to establish current values
# 3. Then we send an invalid M0002 command with non-existing timeplan
# 4. Then the site should return a command response with current (unchanged) values
# 5. And verify the non-existing timeplan is not in the config

it 'returns current values when command fails with invalid values', sxl: '>=1.0.7' do |example|
Validator::Site.connected do |task,supervisor,site|
# Verify that timeplan 255 is not in the configured plans
configured_plans = Validator.get_config('items','plans')
expect(configured_plans).not_to include(255), "Test assumes timeplan 255 is not configured, but it is: #{configured_plans}"

# First, send a valid M0002 command to establish known current values
log "Sending valid M0002 command to establish current values"

valid_plan = '1' # Use plan 1 from available plans [1,2]
valid_command_list = build_command_list :M0002, :setPlan, {
securityCode: Validator.get_config('secrets','security_codes',2), # Valid: '2222'
status: 'True',
timeplan: valid_plan
}

valid_result = site.send_command(
Validator.get_config('main_component'),
valid_command_list,
collect: { timeout: Validator.get_config('timeouts','command_response') }
)

# Verify the valid command succeeded
valid_collector = valid_result[:collector]
expect(valid_collector).to be_an(RSMP::Collector)
expect(valid_collector.status).to eq(:ok)
valid_response = valid_collector.messages.first
expect(valid_response).to be_an(RSMP::CommandResponse)

# Store the current values from the successful command
valid_rvs = valid_response.attributes['rvs']
expect(valid_rvs).to be_an(Array)
expect(valid_rvs).not_to be_empty, "Expected return values from valid command"

# Now send an invalid M0002 command with non-existing timeplan
log "Sending invalid M0002 command with non-existing timeplan 255"

invalid_command_list = build_command_list :M0002, :setPlan, {
securityCode: Validator.get_config('secrets','security_codes',2), # Valid security code
status: 'True',
timeplan: '255' # Non-existing timeplan
}

invalid_result = site.send_command(
Validator.get_config('main_component'),
invalid_command_list,
collect: { timeout: Validator.get_config('timeouts','command_response') }
)

# The invalid command should either be rejected or return current values
invalid_collector = invalid_result[:collector]
expect(invalid_collector).to be_an(RSMP::Collector)

if invalid_collector.status == :ok
# If command was processed, it should return current values
invalid_response = invalid_collector.messages.first
expect(invalid_response).to be_an(RSMP::CommandResponse)

invalid_rvs = invalid_response.attributes['rvs']
expect(invalid_rvs).to be_an(Array)
expect(invalid_rvs).not_to be_empty, "Expected return values from invalid command"

# Verify that return values have proper structure and contain current values
invalid_rvs.each do |rv|
expect(rv).to have_key('age'), "Expected age in return value"
expect(rv).to have_key('cCI'), "Expected command code id in return value"
expect(rv).to have_key('n'), "Expected parameter name in return value"
expect(rv).to have_key('v'), "Expected parameter value in return value"
expect(rv['cCI']).to eq('M0002'), "Expected command code id M0002"

# The age should indicate current values (not 'undefined')
age = rv['age']
expect(age).not_to eq('undefined'), "Expected current values, not undefined age"
end
else
# If command was rejected, that's also acceptable behavior
expect(invalid_collector.status).to eq(:cancelled)
expect(invalid_collector.error).to be_an(RSMP::MessageRejected)
end
end
end
end
end
Loading