Skip to content

Commit

Permalink
update tests for invalid commands
Browse files Browse the repository at this point in the history
  • Loading branch information
emiltin committed Jul 7, 2023
1 parent fbe206f commit 0ccfaa5
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 43 deletions.
104 changes: 104 additions & 0 deletions spec/site/tlc/invalid_command_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
RSpec.describe 'Site::Traffic Light Controller' do
include Validator::CommandHelpers

context 'receiving an command with an unknown component id' do

# Verify that site reponds with NotAck when receive a command
# with an unknown component id
#
# 1. Given the site is connected
# 2. When we send a command with an unknown component id
# 3. Then the site return a command response with age=undefined

it 'return a command response with age=undefined' do |example|
Validator::Site.connected do |task,supervisor,site|
log "Sending M0001"
command_list = build_command_list :M0001, :setValue, {
securityCode: Validator.config['secrets']['security_codes'][2],
status: 'NormalControl',
timeout: 0,
intersection: 0
}
result = site.send_command Validator.config['main_component'], command_list,
collect: { timeout: Validator.config['timeouts']['command_response'] },
validate: false # disable validation of outgoing message
collector = result[:collector]
expect(collector).to be_an(RSMP::Collector)
expect(collector.status).to eq(:ok)
response = collector.messages.first
expect(response).to be_an(RSMP::CommandResponse)
rvs = response.attributes['rvs']
expect(rvs).to be_an(Array)
rvs.each do |rv|
age = rv['age']
expect(age).to eq('undefined'), "expected rvs age attribute to be 'undefined', got #{rv.inspect}"
end
end
end
end

context 'receiving an unknown command code id' do

# Verify that site returns NotAck when receiving an unknown command
#
# 1. Given the site is connected
# 2. When we send a non-existing M0000 command
# 3. Then the site return NotAck

it 'returns NotAck' do |example|
Validator::Site.connected do |task,supervisor,site|
log "Sending non-existing command M0000"
command_list = build_command_list :M0000, :bad, {}
result = site.send_command Validator.config['main_component'], command_list,
collect: { timeout: Validator.config['timeouts']['command_response'] },
validate: false # disable validation of outgoing message
collector = result[:collector]
expect(collector).to be_an(RSMP::Collector)
expect(collector.status).to eq(:cancelled)
expect(collector.error).to be_an(RSMP::MessageRejected)
end
end
end

context 'receiving a command with a missing attribute' do
it 'returns NotAck' do |example|
Validator::Site.connected do |task,supervisor,site|
log "Sending M0001 with 'status' attribute missing"
command_list = build_command_list :M0001, :setValue, {
securityCode: '1111',
intersection: '0',
timeout: '0'
# intentionally not setting 'status'
}
result = site.send_command Validator.config['main_component'], command_list,
collect: { timeout: Validator.config['timeouts']['command_response'] },
validate: false # disable validation of outgoing message
collector = result[:collector]
expect(collector).to be_an(RSMP::Collector)
expect(collector.status).to eq(:cancelled)
expect(collector.error).to be_an(RSMP::MessageRejected)
end
end
end

context 'receiving a command with a bad command name n' do
it 'returns NotAck' do |example|
Validator::Site.connected do |task,supervisor,site|
log "Sending M0001"
# for M0001, cO should be :setValue, here we use the incorrect :bad
command_list = build_command_list :M0001, :bad, {
securityCode: '1111',
intersection: '0',
timeout: '0'
}
result = site.send_command Validator.config['main_component'], command_list,
collect: { timeout: Validator.config['timeouts']['command_response'] },
validate: false # disable validation of outgoing message
collector = result[:collector]
expect(collector).to be_an(RSMP::Collector)
expect(collector.status).to eq(:cancelled)
expect(collector.error).to be_an(RSMP::MessageRejected)
end
end
end
end
43 changes: 0 additions & 43 deletions spec/site/tlc/unknown_command_spec.rb

This file was deleted.

0 comments on commit 0ccfaa5

Please sign in to comment.