2015-12-21 17:51:49 +01:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe APIController, type: :controller do
|
2019-02-26 16:57:04 +01:00
|
|
|
describe 'valid_token_for_procedure?' do
|
|
|
|
let(:procedure) { create(:procedure) }
|
|
|
|
let(:admin) { procedure.administrateurs.first }
|
2018-08-24 15:53:57 +02:00
|
|
|
|
2019-02-26 16:57:04 +01:00
|
|
|
subject { controller.send(:'valid_token_for_procedure?', procedure) }
|
2018-08-24 15:53:57 +02:00
|
|
|
|
2018-09-26 15:39:45 +02:00
|
|
|
context 'when the admin has not any token' do
|
|
|
|
context 'and the token is not given' do
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
2015-12-21 17:51:49 +01:00
|
|
|
end
|
2018-08-24 15:53:57 +02:00
|
|
|
|
2018-09-26 15:39:45 +02:00
|
|
|
context 'when the admin has a token' do
|
|
|
|
let!(:token) { admin.renew_api_token }
|
2018-08-24 15:53:57 +02:00
|
|
|
|
2018-09-26 15:39:45 +02:00
|
|
|
context 'and the token is given by params' do
|
|
|
|
before { controller.params[:token] = token }
|
2018-08-24 15:53:57 +02:00
|
|
|
|
2018-09-26 15:39:45 +02:00
|
|
|
it { is_expected.to be true }
|
|
|
|
end
|
2018-08-24 15:53:57 +02:00
|
|
|
|
2018-09-26 15:39:45 +02:00
|
|
|
context 'and the token is given by header' do
|
|
|
|
before do
|
|
|
|
valid_headers = { 'Authorization' => "Bearer token=#{token}" }
|
|
|
|
request.headers.merge!(valid_headers)
|
|
|
|
end
|
2018-08-24 15:53:57 +02:00
|
|
|
|
2018-09-26 15:39:45 +02:00
|
|
|
it { is_expected.to be true }
|
2018-08-24 15:53:57 +02:00
|
|
|
end
|
|
|
|
|
2018-09-26 15:39:45 +02:00
|
|
|
context 'and the token is not given' do
|
|
|
|
it { is_expected.to be false }
|
|
|
|
end
|
2015-12-21 17:51:49 +01:00
|
|
|
end
|
|
|
|
end
|
2017-04-04 15:27:04 +02:00
|
|
|
end
|