Spec: do not use the deprecated api_token

This commit is contained in:
simon lehericey 2018-09-26 15:07:33 +02:00
parent 9a6e985bac
commit 7b27f00a23
2 changed files with 13 additions and 11 deletions

View file

@ -1,14 +1,15 @@
require 'spec_helper'
describe API::V1::DossiersController do
let(:admin) { create(:administrateur, :with_api_token) }
let(:admin) { create(:administrateur) }
let(:token) { admin.renew_api_token }
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, :with_type_de_champ_private, administrateur: admin) }
let(:wrong_procedure) { create(:procedure) }
it { expect(described_class).to be < APIController }
describe 'GET index (with bearer token)' do
let(:authorization_header) { ActionController::HttpAuthentication::Token.encode_credentials(admin.api_token) }
let(:authorization_header) { ActionController::HttpAuthentication::Token.encode_credentials(token) }
let(:retour) do
request.env['HTTP_AUTHORIZATION'] = authorization_header
get :index, params: { procedure_id: procedure_id }
@ -23,7 +24,7 @@ describe API::V1::DossiersController do
end
describe 'GET index' do
let(:retour) { get :index, params: { token: admin.api_token, procedure_id: procedure_id } }
let(:retour) { get :index, params: { token: token, procedure_id: procedure_id } }
subject { retour }
@ -62,7 +63,7 @@ describe API::V1::DossiersController do
end
describe 'with custom resultats_par_page' do
let(:retour) { get :index, params: { token: admin.api_token, procedure_id: procedure_id, resultats_par_page: 18 } }
let(:retour) { get :index, params: { token: token, procedure_id: procedure_id, resultats_par_page: 18 } }
subject { body[:pagination] }
it { is_expected.to have_key(:resultats_par_page) }
it { expect(subject[:resultats_par_page]).to eq(18) }
@ -81,7 +82,7 @@ describe API::V1::DossiersController do
end
context 'when there are multiple pages' do
let(:retour) { get :index, params: { token: admin.api_token, procedure_id: procedure_id, page: 2 } }
let(:retour) { get :index, params: { token: token, procedure_id: procedure_id, page: 2 } }
let!(:dossier1) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction)) }
let!(:dossier2) { create(:dossier, :with_entreprise, procedure: procedure, state: Dossier.states.fetch(:en_construction)) }
@ -102,7 +103,7 @@ describe API::V1::DossiersController do
end
describe 'GET show' do
let(:retour) { get :show, params: { token: admin.api_token, procedure_id: procedure_id, id: dossier_id } }
let(:retour) { get :show, params: { token: token, procedure_id: procedure_id, id: dossier_id } }
subject { retour }
context 'when procedure is not found' do

View file

@ -1,11 +1,12 @@
describe API::V1::ProceduresController, type: :controller do
let(:admin) { create(:administrateur, :with_api_token) }
let!(:admin) { create(:administrateur, :with_api_token) }
let!(:token) { admin.renew_api_token }
it { expect(described_class).to be < APIController }
describe 'GET show' do
context 'when procedure does not exist' do
subject { get :show, params: { id: 999_999_999, token: admin.api_token } }
subject { get :show, params: { id: 999_999_999, token: token } }
it { expect(subject.status).to eq(404) }
end
@ -13,7 +14,7 @@ describe API::V1::ProceduresController, type: :controller do
context 'when procedure does not belong to administrateur' do
let(:procedure) { create(:procedure, administrateur: create(:administrateur)) }
subject { get :show, params: { id: procedure, token: admin.api_token } }
subject { get :show, params: { id: procedure, token: token } }
it { expect(subject.status).to eq(404) }
end
@ -21,7 +22,7 @@ describe API::V1::ProceduresController, type: :controller do
context 'when procedure exist' do
let(:procedure) { create(:procedure, :with_two_type_de_piece_justificative, :with_type_de_champ, administrateur: admin) }
subject { get :show, params: { id: procedure, token: admin.api_token } }
subject { get :show, params: { id: procedure, token: token } }
it 'return REST code 200', :show_in_doc do
expect(subject.status).to eq(200)
@ -30,7 +31,7 @@ describe API::V1::ProceduresController, type: :controller do
describe 'body' do
let(:module_api_carto) { create(:module_api_carto, use_api_carto: true, quartiers_prioritaires: true, cadastre: true) }
let(:procedure) { create(:procedure, :with_type_de_champ, :with_two_type_de_piece_justificative, module_api_carto: module_api_carto, administrateur: admin) }
let(:response) { get :show, params: { id: procedure.id, token: admin.api_token } }
let(:response) { get :show, params: { id: procedure.id, token: token } }
subject { JSON.parse(response.body, symbolize_names: true)[:procedure] }