|
| 1 | +require 'spec_helper' |
| 2 | +require 'messages/service_offerings_show_message' |
| 3 | +require 'field_message_spec_shared_examples' |
| 4 | + |
| 5 | +module VCAP::CloudController |
| 6 | + RSpec.describe ServiceOfferingsShowMessage do |
| 7 | + describe '.from_params' do |
| 8 | + let(:params) do |
| 9 | + { |
| 10 | + 'fields' => { 'service_broker' => 'guid,name' }, |
| 11 | + }.with_indifferent_access |
| 12 | + end |
| 13 | + |
| 14 | + it 'returns the correct message' do |
| 15 | + message = described_class.from_params(params) |
| 16 | + |
| 17 | + expect(message).to be_valid |
| 18 | + expect(message).to be_a(described_class) |
| 19 | + expect(message.fields).to match({ 'service_broker': ['guid', 'name'] }) |
| 20 | + end |
| 21 | + |
| 22 | + it 'converts requested keys to symbols' do |
| 23 | + message = described_class.from_params(params) |
| 24 | + expect(message.requested?(:fields)).to be_truthy |
| 25 | + end |
| 26 | + |
| 27 | + it 'accepts an empty set' do |
| 28 | + message = described_class.from_params({}) |
| 29 | + expect(message).to be_valid |
| 30 | + end |
| 31 | + |
| 32 | + it 'does not accept arbitrary parameters' do |
| 33 | + message = described_class.from_params({ foobar: 'pants' }.with_indifferent_access) |
| 34 | + |
| 35 | + expect(message).not_to be_valid |
| 36 | + expect(message.errors[:base][0]).to include("Unknown query parameter(s): 'foobar'") |
| 37 | + end |
| 38 | + |
| 39 | + context 'fields' do |
| 40 | + it_behaves_like 'fields query hash' |
| 41 | + |
| 42 | + it_behaves_like 'field query parameter', 'service_broker', 'guid,name' |
| 43 | + end |
| 44 | + end |
| 45 | + end |
| 46 | +end |
0 commit comments