Skip to content

Commit

Permalink
Fix wrong service specs
Browse files Browse the repository at this point in the history
  • Loading branch information
jlledom committed May 14, 2024
1 parent ab72cdc commit b4c0c87
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions spec/unit/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,44 +368,44 @@ module Backend
describe '.active?' do
it 'returns true when service is active' do
[
{ state: :active, id: '8001' },
{ state: 'active', id: '8001' },
{ state: :active, id: '8001', provider_key: 'foo' },
{ state: 'active', id: '8001', provider_key: 'foo' },
# even when state is not set
{ id: '8001' },
{ id: '8001', provider_key: 'foo' },
# even when state is intentionally set as nil
{ state: nil, id: '9001'}
{ state: nil, id: '9001', provider_key: 'foo'}
].each do |svc_attrs|
expect(Service.save!(svc_attrs).active?).to be_truthy
end
end

it 'returns false when the service is disabled' do
[
{ state: :suspended, id: '9001' },
{ state: 'suspended', id: '9001' },
{ state: :something, id: '9001' },
{ state: :disable, id: '9001' },
{ state: :disabled, id: '9001' },
{ state: '1', id: '9001' },
{ state: '0', id: '9001' },
{ state: 'true', id: '9001' },
{ state: 'false', id: '9001' }
{ state: :suspended, id: '9001', provider_key: 'foo' },
{ state: 'suspended', id: '9001', provider_key: 'foo' },
{ state: :something, id: '9001', provider_key: 'foo' },
{ state: :disable, id: '9001', provider_key: 'foo' },
{ state: :disabled, id: '9001', provider_key: 'foo' },
{ state: '1', id: '9001', provider_key: 'foo' },
{ state: '0', id: '9001', provider_key: 'foo' },
{ state: 'true', id: '9001', provider_key: 'foo' },
{ state: 'false', id: '9001', provider_key: 'foo' }
].each do |svc_attrs|
expect(Service.save!(svc_attrs).active?).to be_falsy
end
end

it 'returns true when the service does not have state in the DB' do
service_id = '9001'
Service.save!({state: :suspended, id: service_id, default_service: false})
Service.save!({state: :suspended, id: service_id, provider_key: 'foo', default_service: false})
Service.storage.del ThreeScale::Backend::Service.storage_key(service_id, 'state')
expect(Service.load_by_id(service_id).active?).to be true
Service.delete_by_id(service_id)
end

it 'returns false when the service has an invalid state in the DB' do
service_id = '9001'
Service.save!({state: :not_defined_state, id: service_id, default_service: false})
Service.save!({state: :not_defined_state, id: service_id, provider_key: 'foo', default_service: false})
Service.storage.set ThreeScale::Backend::Service.storage_key(service_id, 'state'), 'not_defined_state'
expect(Service.load_by_id(service_id).active?).to be false
Service.delete_by_id(service_id)
Expand All @@ -415,12 +415,12 @@ module Backend
describe '#active=' do
it 'when set to true, active? returns true' do
[
{ state: :suspended, id: '9001', default_service: false },
{ state: :active, id: '9001', default_service: false },
{ state: :something, id: '9001', default_service: false },
{ state: nil, id: '9001', default_service: false },
{ state: "", id: '9001', default_service: false },
{ id: '9001', default_service: false}
{ state: :suspended, id: '9001', provider_key: 'foo', default_service: false },
{ state: :active, id: '9001', provider_key: 'foo', default_service: false },
{ state: :something, id: '9001', provider_key: 'foo', default_service: false },
{ state: nil, id: '9001', provider_key: 'foo', default_service: false },
{ state: "", id: '9001', provider_key: 'foo', default_service: false },
{ id: '9001', provider_key: 'foo', default_service: false}
].each do |svc_attrs|
service = Service.save!(svc_attrs)
service.active = true
Expand All @@ -431,12 +431,12 @@ module Backend

it 'when set to false, active? returns false' do
[
{ state: :suspended, id: '9001', default_service: false },
{ state: :active, id: '9001', default_service: false },
{ state: :something, id: '9001', default_service: false },
{ state: nil, id: '9001', default_service: false },
{ state: "", id: '9001', default_service: false },
{ id: '9001', default_service: false}
{ state: :suspended, id: '9001', provider_key: 'foo', default_service: false },
{ state: :active, id: '9001', provider_key: 'foo', default_service: false },
{ state: :something, id: '9001', provider_key: 'foo', default_service: false },
{ state: nil, id: '9001', provider_key: 'foo', default_service: false },
{ state: "", id: '9001', provider_key: 'foo', default_service: false },
{ id: '9001', provider_key: 'foo', default_service: false}
].each do |svc_attrs|
service = Service.save!(svc_attrs)
service.active = false
Expand Down

0 comments on commit b4c0c87

Please sign in to comment.