# frozen_string_literal: true require 'spec_helper' describe Praxis::EndpointDefinition do subject(:endpoint_definition) { PeopleResource } its(:description) { should eq('People resource') } its(:media_type) { should eq(Person) } its(:version) { should eq('1.0') } its(:prefix) { should eq('/people') } its(:actions) { should have(4).items } # Two real actions, and two post versions of the GET its(:metadata) { should_not have_key(:doc_visibility) } context '.describe' do subject(:describe) { endpoint_definition.describe } its([:description]) { should eq(endpoint_definition.description) } its([:media_type]) { should eq(endpoint_definition.media_type.describe(true)) } its([:actions]) { should have(4).items } # Two real actions, and two post versions of the GET its([:metadata]) { should be_kind_of(Hash) } its([:traits]) { should eq [:test] } it { should_not have_key(:parent) } context 'for a resource with a parent' do let(:endpoint_definition) { ApiResources::VolumeSnapshots } its([:parent]) { should eq ApiResources::Volumes.id } end end context '.routing_prefix' do subject(:endpoint_definition) { ApiResources::VolumeSnapshots } it do expect(endpoint_definition.routing_prefix).to eq('/clouds/:cloud_id/volumes/:volume_id/snapshots') end end context '.parent_prefix' do subject(:endpoint_definition) { ApiResources::VolumeSnapshots } let(:base_path) { Praxis::ApiDefinition.instance.info.base_path } its(:parent_prefix) { should eq('/clouds/:cloud_id/volumes/:volume_id') } it do expect(endpoint_definition.parent_prefix).to_not match(/^#{base_path}/) end end context '.action' do it 'requires a block' do expect do endpoint_definition.action(:something) end.to raise_error(ArgumentError) end it 'creates an ActionDefinition for actions' do index = endpoint_definition.actions[:index] expect(index).to be_kind_of(Praxis::ActionDefinition) expect(index.description).to eq('index description') end it 'complains if action names are not symbols' do expect do Class.new do include Praxis::EndpointDefinition action 'foo' do end end end.to raise_error(ArgumentError, /Action names must be defined using symbols/) end context 'enable_large_params_proxy_action' do it 'duplicates the show action with a sister _with_post one' do action_names = endpoint_definition.actions.keys expect(action_names).to match_array(%i[index show show_with_post index_with_post]) end context 'defaults the exposed path for the POST action "' do it 'to add a prefix of "actions/