diff options
| -rw-r--r-- | spec/controllers/api/v1/workbenches_controller_spec.rb | 18 | ||||
| -rw-r--r-- | spec/support/api_key.rb | 4 | ||||
| -rw-r--r-- | spec/support/shared_context.rb | 8 |
3 files changed, 30 insertions, 0 deletions
diff --git a/spec/controllers/api/v1/workbenches_controller_spec.rb b/spec/controllers/api/v1/workbenches_controller_spec.rb index 187d8ffeb..dc05c3926 100644 --- a/spec/controllers/api/v1/workbenches_controller_spec.rb +++ b/spec/controllers/api/v1/workbenches_controller_spec.rb @@ -1,5 +1,23 @@ require 'rails_helper' RSpec.describe Api::V1::WorkbenchesController, type: :controller do + context 'unauthenticated' do + describe 'GET #index' do + it 'should not be successful' do + get :index + expect(response).not_to be_success + end + end + end + context 'authenticated' do + include_context 'iboo authenticated api user' + + describe 'GET #index' do + it 'should be successful' do + get :index + expect(response).to be_success + end + end + end end diff --git a/spec/support/api_key.rb b/spec/support/api_key.rb index 5aaa31217..cc08cd7f1 100644 --- a/spec/support/api_key.rb +++ b/spec/support/api_key.rb @@ -7,18 +7,22 @@ module ApiKeyHelper def get_api_key Api::V1::ApiKey.first_or_create(referential: referential, organisation: organisation) end + def config_formatted_request_with_authorization( format) request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials( get_api_key.token) request.accept = format end + def config_formatted_request_with_dummy_authorization( format) request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Token.encode_credentials( "dummy") request.accept = format end + def config_formatted_request_without_authorization( format) request.env['HTTP_AUTHORIZATION'] = nil request.accept = format end + def json_xml_format? request.accept == "application/json" || request.accept == "application/xml" end diff --git a/spec/support/shared_context.rb b/spec/support/shared_context.rb new file mode 100644 index 000000000..c08ee6163 --- /dev/null +++ b/spec/support/shared_context.rb @@ -0,0 +1,8 @@ +shared_context 'iboo authenticated api user' do + let(:api_key) { create(:api_key) } + let(:user) { create(:user, organisation: api_key.organisation ) } + + before do + request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(user.username, api_key.token) + end +end |
